Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case { protected $serve..

Decoded Output download

<?php
 class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case { protected $server; protected $endpoint; protected $user; protected $zones; public function setUp() : void { parent::setUp(); $this->endpoint = new WC_REST_Shipping_Zones_Controller(); $this->user = $this->factory->user->create(array("role" => "administrator")); $this->zones = array(); } protected function create_shipping_zone($name, $order = 0, $locations = array()) { $zone = new WC_Shipping_Zone(null); $zone->set_zone_name($name); $zone->set_zone_order($order); $zone->set_locations($locations); $zone->save(); $this->zones[] = $zone; return $zone; } public function test_register_routes() { $routes = $this->server->get_routes(); $this->assertArrayHasKey("/wc/v3/shipping/zones", $routes); $this->assertArrayHasKey("/wc/v3/shipping/zones/(?P<id>[\d]+)", $routes); $this->assertArrayHasKey("/wc/v3/shipping/zones/(?P<id>[\d]+)/locations", $routes); $this->assertArrayHasKey("/wc/v3/shipping/zones/(?P<zone_id>[\d]+)/methods", $routes); $this->assertArrayHasKey("/wc/v3/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)", $routes); } public function test_get_zones() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones")); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 1); $this->assertContains(array("id" => $data[0]["id"], "name" => "Locations not covered by your other zones", "order" => 0, "_links" => array("self" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $data[0]["id"]))), "collection" => array(array("href" => rest_url("/wc/v3/shipping/zones"))), "describedby" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $data[0]["id"] . "/locations"))))), $data); $this->create_shipping_zone("Zone 1"); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones")); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 2); $this->assertContains(array("id" => $data[1]["id"], "name" => "Zone 1", "order" => 0, "_links" => array("self" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $data[1]["id"]))), "collection" => array(array("href" => rest_url("/wc/v3/shipping/zones"))), "describedby" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $data[1]["id"] . "/locations"))))), $data); } public function test_get_shipping_zones_without_permission() { wp_set_current_user(0); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones")); $this->assertEquals(401, $response->get_status()); } public function test_get_shipping_zones_disabled_shipping() { wp_set_current_user($this->user); add_filter("wc_shipping_enabled", "__return_false"); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones")); $this->assertEquals(404, $response->get_status()); remove_filter("wc_shipping_enabled", "__return_false"); } public function test_get_shipping_zone_schema() { $request = new WP_REST_Request("OPTIONS", "/wc/v3/shipping/zones"); $response = $this->server->dispatch($request); $data = $response->get_data(); $properties = $data["schema"]["properties"]; $this->assertEquals(3, count($properties)); $this->assertArrayHasKey("id", $properties); $this->assertTrue($properties["id"]["readonly"]); $this->assertArrayHasKey("name", $properties); $this->assertArrayHasKey("order", $properties); } public function test_create_shipping_zone() { wp_set_current_user($this->user); $request = new WP_REST_Request("POST", "/wc/v3/shipping/zones"); $request->set_body_params(array("name" => "Test Zone", "order" => 1)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(201, $response->get_status()); $this->assertEquals(array("id" => $data["id"], "name" => "Test Zone", "order" => 1, "_links" => array("self" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $data["id"]))), "collection" => array(array("href" => rest_url("/wc/v3/shipping/zones"))), "describedby" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $data["id"] . "/locations"))))), $data); } public function test_create_shipping_zone_without_permission() { wp_set_current_user(0); $request = new WP_REST_Request("POST", "/wc/v3/shipping/zones"); $request->set_body_params(array("name" => "Test Zone", "order" => 1)); $response = $this->server->dispatch($request); $this->assertEquals(401, $response->get_status()); } public function test_update_shipping_zone() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Test Zone"); $request = new WP_REST_Request("PUT", "/wc/v3/shipping/zones/" . $zone->get_id()); $request->set_body_params(array("name" => "Zone Test", "order" => 2)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(array("id" => $zone->get_id(), "name" => "Zone Test", "order" => 2, "_links" => array("self" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id()))), "collection" => array(array("href" => rest_url("/wc/v3/shipping/zones"))), "describedby" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/locations"))))), $data); } public function test_update_shipping_zone_invalid_id() { wp_set_current_user($this->user); $request = new WP_REST_Request("PUT", "/wc/v3/shipping/zones/555555"); $request->set_body_params(array("name" => "Zone Test", "order" => 2)); $response = $this->server->dispatch($request); $this->assertEquals(404, $response->get_status()); } public function test_delete_shipping_zone() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Zone 1"); $request = new WP_REST_Request("DELETE", "/wc/v3/shipping/zones/" . $zone->get_id()); $request->set_param("force", true); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); } public function test_delete_shipping_zone_without_permission() { wp_set_current_user(0); $zone = $this->create_shipping_zone("Zone 1"); $request = new WP_REST_Request("DELETE", "/wc/v3/shipping/zones/" . $zone->get_id()); $request->set_param("force", true); $response = $this->server->dispatch($request); $this->assertEquals(401, $response->get_status()); } public function test_delete_shipping_zone_invalid_id() { wp_set_current_user($this->user); $request = new WP_REST_Request("DELETE", "/wc/v3/shipping/zones/555555"); $response = $this->server->dispatch($request); $this->assertEquals(404, $response->get_status()); } public function test_get_single_shipping_zone() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Test Zone"); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/" . $zone->get_id())); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(array("id" => $zone->get_id(), "name" => "Test Zone", "order" => 0, "_links" => array("self" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id()))), "collection" => array(array("href" => rest_url("/wc/v3/shipping/zones"))), "describedby" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/locations"))))), $data); } public function test_get_single_shipping_zone_invalid_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/1")); $this->assertEquals(404, $response->get_status()); } public function test_get_locations() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Zone 1", 0, array(array("code" => "US", "type" => "country"))); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/" . $zone->get_id() . "/locations")); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 1); $this->assertEquals(array(array("code" => "US", "type" => "country", "_links" => array("collection" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/locations"))), "describes" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id())))))), $data); } public function test_get_locations_invalid_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/1/locations")); $this->assertEquals(404, $response->get_status()); } public function test_update_locations() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Test Zone"); $request = new WP_REST_Request("PUT", "/wc/v3/shipping/zones/" . $zone->get_id() . "/locations"); $request->add_header("Content-Type", "application/json"); $request->set_body(json_encode(array(array("code" => "UK", "type" => "country"), array("code" => "US"), array("code" => "SW1A0AA", "type" => "postcode"), array("type" => "continent")))); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(3, count($data)); $this->assertEquals(array(array("code" => "UK", "type" => "country", "_links" => array("collection" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/locations"))), "describes" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id()))))), array("code" => "US", "type" => "country", "_links" => array("collection" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/locations"))), "describes" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id()))))), array("code" => "SW1A0AA", "type" => "postcode", "_links" => array("collection" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/locations"))), "describes" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id())))))), $data); } public function test_update_locations_invalid_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("PUT", "/wc/v3/shipping/zones/1/locations")); $this->assertEquals(404, $response->get_status()); } public function test_get_methods() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Zone 1"); $instance_id = $zone->add_shipping_method("flat_rate"); $methods = $zone->get_shipping_methods(); $method = $methods[$instance_id]; $settings = array(); $method->init_instance_settings(); foreach ($method->get_instance_form_fields() as $id => $field) { $data = array("id" => $id, "label" => $field["title"], "description" => empty($field["description"]) ? '' : $field["description"], "type" => $field["type"], "value" => $method->instance_settings[$id], "default" => empty($field["default"]) ? '' : $field["default"], "tip" => empty($field["description"]) ? '' : $field["description"], "placeholder" => empty($field["placeholder"]) ? '' : $field["placeholder"]); if (!empty($field["options"])) { $data["options"] = $field["options"]; } $settings[$id] = $data; } $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods")); $data = $response->get_data(); $expected = array("id" => $instance_id, "instance_id" => $instance_id, "title" => $method->instance_settings["title"], "order" => $method->method_order, "enabled" => "yes" === $method->enabled, "method_id" => $method->id, "method_title" => $method->method_title, "method_description" => $method->method_description, "settings" => $settings, "_links" => array("self" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id))), "collection" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id() . "/methods"))), "describes" => array(array("href" => rest_url("/wc/v3/shipping/zones/" . $zone->get_id()))))); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 1); $this->assertContains($expected, $data); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id)); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals($expected, $data); } public function test_get_methods_invalid_zone_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/1/methods")); $this->assertEquals(404, $response->get_status()); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/1/methods/1")); $this->assertEquals(404, $response->get_status()); } public function test_get_methods_invalid_method_id() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Zone 1"); $response = $this->server->dispatch(new WP_REST_Request("GET", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/1")); $this->assertEquals(404, $response->get_status()); } public function test_update_methods() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Zone 1"); $instance_id = $zone->add_shipping_method("flat_rate"); $methods = $zone->get_shipping_methods(); $method = $methods[$instance_id]; $request = new WP_REST_Request("GET", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertArrayHasKey("title", $data["settings"]); $this->assertEquals("Flat rate", $data["settings"]["title"]["value"]); $this->assertArrayHasKey("tax_status", $data["settings"]); $this->assertEquals("taxable", $data["settings"]["tax_status"]["value"]); $this->assertArrayHasKey("cost", $data["settings"]); $this->assertEquals("0", $data["settings"]["cost"]["value"]); $request = new WP_REST_Request("POST", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id); $request->set_body_params(array("settings" => array("cost" => 5))); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertArrayHasKey("title", $data["settings"]); $this->assertEquals("Flat rate", $data["settings"]["title"]["value"]); $this->assertArrayHasKey("tax_status", $data["settings"]); $this->assertEquals("taxable", $data["settings"]["tax_status"]["value"]); $this->assertArrayHasKey("cost", $data["settings"]); $this->assertEquals("5", $data["settings"]["cost"]["value"]); $request = new WP_REST_Request("POST", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id); $request->set_body_params(array("settings" => array("cost" => 10, "tax_status" => "none"))); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertArrayHasKey("title", $data["settings"]); $this->assertEquals("Flat rate", $data["settings"]["title"]["value"]); $this->assertArrayHasKey("tax_status", $data["settings"]); $this->assertEquals("none", $data["settings"]["tax_status"]["value"]); $this->assertArrayHasKey("cost", $data["settings"]); $this->assertEquals("10", $data["settings"]["cost"]["value"]); $request = new WP_REST_Request("POST", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id); $request->set_body_params(array("settings" => array("cost" => 10, "tax_status" => "this_is_not_a_valid_option"))); $response = $this->server->dispatch($request); $this->assertEquals(400, $response->get_status()); $this->assertTrue($data["enabled"]); $this->assertEquals(1, $data["order"]); $request = new WP_REST_Request("POST", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id); $request->set_body_params(array("enabled" => false, "order" => 2)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertFalse($data["enabled"]); $this->assertEquals(2, $data["order"]); $this->assertArrayHasKey("cost", $data["settings"]); $this->assertEquals("10", $data["settings"]["cost"]["value"]); } public function test_create_method() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Zone 1"); $request = new WP_REST_Request("POST", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods"); $request->set_body_params(array("method_id" => "flat_rate", "enabled" => false, "order" => 2)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertFalse($data["enabled"]); $this->assertEquals(2, $data["order"]); $this->assertArrayHasKey("cost", $data["settings"]); $this->assertEquals("0", $data["settings"]["cost"]["value"]); } public function test_delete_method() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("Zone 1"); $instance_id = $zone->add_shipping_method("flat_rate"); $methods = $zone->get_shipping_methods(); $method = $methods[$instance_id]; $request = new WP_REST_Request("DELETE", "/wc/v3/shipping/zones/" . $zone->get_id() . "/methods/" . $instance_id); $request->set_param("force", true); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); } } ?>

Did this file decode correctly?

Original Code

<?php
 class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case { protected $server; protected $endpoint; protected $user; protected $zones; public function setUp() : void { parent::setUp(); $this->endpoint = new WC_REST_Shipping_Zones_Controller(); $this->user = $this->factory->user->create(array("\162\157\x6c\145" => "\141\x64\x6d\x69\156\151\x73\164\x72\x61\164\157\x72")); $this->zones = array(); } protected function create_shipping_zone($name, $order = 0, $locations = array()) { $zone = new WC_Shipping_Zone(null); $zone->set_zone_name($name); $zone->set_zone_order($order); $zone->set_locations($locations); $zone->save(); $this->zones[] = $zone; return $zone; } public function test_register_routes() { $routes = $this->server->get_routes(); $this->assertArrayHasKey("\x2f\x77\143\x2f\x76\63\57\163\x68\151\160\x70\151\156\147\57\x7a\157\x6e\145\x73", $routes); $this->assertArrayHasKey("\57\167\143\57\x76\63\x2f\163\150\151\160\160\151\x6e\147\x2f\x7a\157\x6e\x65\163\x2f\x28\77\x50\74\x69\144\x3e\133\134\x64\x5d\x2b\x29", $routes); $this->assertArrayHasKey("\57\x77\143\x2f\166\x33\57\163\x68\x69\x70\160\151\x6e\147\x2f\172\x6f\156\x65\x73\57\50\77\120\x3c\151\144\x3e\133\x5c\144\135\53\x29\57\154\157\143\141\x74\x69\157\x6e\163", $routes); $this->assertArrayHasKey("\57\x77\x63\x2f\x76\63\57\x73\150\151\160\160\x69\x6e\147\57\x7a\157\156\145\163\57\50\x3f\120\74\172\157\156\145\x5f\151\x64\x3e\133\134\x64\135\x2b\x29\x2f\155\x65\x74\150\x6f\144\163", $routes); $this->assertArrayHasKey("\x2f\x77\143\x2f\x76\63\x2f\163\x68\151\x70\160\151\156\x67\57\x7a\x6f\x6e\x65\163\57\x28\x3f\x50\x3c\x7a\157\156\x65\137\x69\144\x3e\133\134\x64\135\53\51\57\x6d\x65\164\150\x6f\144\x73\x2f\x28\77\120\x3c\x69\156\x73\x74\x61\156\x63\x65\137\x69\144\76\133\134\x64\135\x2b\51", $routes); } public function test_get_zones() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("\107\105\124", "\x2f\167\x63\57\166\63\x2f\163\x68\x69\x70\x70\151\x6e\147\x2f\x7a\x6f\x6e\x65\163")); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 1); $this->assertContains(array("\151\144" => $data[0]["\x69\x64"], "\156\x61\155\x65" => "\x4c\157\x63\141\164\151\x6f\156\163\x20\156\x6f\164\40\143\x6f\166\145\x72\x65\144\x20\142\171\40\x79\x6f\165\x72\40\157\164\150\145\162\x20\x7a\x6f\x6e\x65\163", "\x6f\x72\x64\145\162" => 0, "\137\x6c\151\156\153\x73" => array("\163\145\154\x66" => array(array("\150\x72\145\x66" => rest_url("\x2f\x77\143\x2f\166\63\x2f\163\150\151\x70\x70\151\x6e\147\x2f\172\x6f\x6e\145\x73\57" . $data[0]["\151\x64"]))), "\143\157\x6c\154\145\x63\x74\151\x6f\156" => array(array("\x68\162\x65\x66" => rest_url("\57\167\143\57\166\63\x2f\x73\150\151\x70\x70\151\156\x67\x2f\x7a\x6f\156\x65\163"))), "\144\x65\x73\x63\x72\151\x62\145\x64\142\171" => array(array("\x68\162\145\146" => rest_url("\x2f\x77\x63\57\x76\x33\57\x73\150\x69\x70\x70\151\x6e\x67\57\x7a\x6f\156\145\x73\x2f" . $data[0]["\x69\144"] . "\57\154\x6f\143\x61\x74\151\157\156\x73"))))), $data); $this->create_shipping_zone("\132\157\x6e\x65\x20\61"); $response = $this->server->dispatch(new WP_REST_Request("\x47\105\124", "\x2f\167\143\57\x76\x33\x2f\163\x68\x69\160\x70\151\156\147\57\x7a\157\x6e\145\x73")); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 2); $this->assertContains(array("\151\144" => $data[1]["\151\144"], "\156\141\x6d\145" => "\132\157\156\x65\40\x31", "\x6f\x72\144\x65\162" => 0, "\x5f\154\x69\156\x6b\163" => array("\x73\x65\154\146" => array(array("\150\162\x65\146" => rest_url("\x2f\x77\143\57\166\63\x2f\163\x68\x69\160\x70\x69\156\x67\57\x7a\157\156\145\x73\57" . $data[1]["\x69\x64"]))), "\x63\x6f\154\154\145\143\x74\x69\157\x6e" => array(array("\x68\162\145\146" => rest_url("\x2f\167\x63\x2f\166\63\57\163\150\151\x70\160\151\156\147\x2f\x7a\x6f\x6e\145\x73"))), "\144\x65\163\x63\162\x69\142\145\144\142\x79" => array(array("\150\x72\x65\x66" => rest_url("\x2f\x77\x63\57\166\63\57\163\150\x69\160\160\x69\156\x67\57\172\x6f\156\145\163\57" . $data[1]["\x69\144"] . "\57\x6c\157\143\141\164\x69\157\x6e\x73"))))), $data); } public function test_get_shipping_zones_without_permission() { wp_set_current_user(0); $response = $this->server->dispatch(new WP_REST_Request("\x47\105\124", "\x2f\167\143\57\x76\63\57\163\x68\x69\160\x70\x69\156\x67\57\172\x6f\x6e\x65\x73")); $this->assertEquals(401, $response->get_status()); } public function test_get_shipping_zones_disabled_shipping() { wp_set_current_user($this->user); add_filter("\167\143\137\163\150\151\x70\160\151\156\147\x5f\x65\156\x61\142\154\145\x64", "\137\137\x72\145\x74\x75\162\x6e\137\146\141\x6c\x73\145"); $response = $this->server->dispatch(new WP_REST_Request("\x47\105\124", "\57\167\143\x2f\166\x33\57\163\150\x69\160\160\151\x6e\147\x2f\x7a\157\x6e\x65\x73")); $this->assertEquals(404, $response->get_status()); remove_filter("\167\143\x5f\163\150\151\160\160\x69\x6e\147\x5f\x65\x6e\141\x62\154\145\x64", "\137\x5f\162\145\164\x75\162\156\x5f\x66\141\x6c\163\145"); } public function test_get_shipping_zone_schema() { $request = new WP_REST_Request("\117\120\124\x49\x4f\x4e\123", "\57\x77\x63\57\x76\63\57\x73\x68\x69\160\160\x69\156\147\57\172\x6f\x6e\145\x73"); $response = $this->server->dispatch($request); $data = $response->get_data(); $properties = $data["\x73\143\x68\x65\155\x61"]["\160\162\157\x70\145\x72\164\x69\145\163"]; $this->assertEquals(3, count($properties)); $this->assertArrayHasKey("\151\144", $properties); $this->assertTrue($properties["\x69\x64"]["\162\x65\x61\144\x6f\x6e\154\171"]); $this->assertArrayHasKey("\x6e\141\x6d\145", $properties); $this->assertArrayHasKey("\x6f\162\x64\x65\x72", $properties); } public function test_create_shipping_zone() { wp_set_current_user($this->user); $request = new WP_REST_Request("\x50\x4f\x53\124", "\57\167\143\57\x76\x33\57\163\150\151\x70\160\151\x6e\147\57\172\157\x6e\145\x73"); $request->set_body_params(array("\156\x61\x6d\145" => "\124\x65\x73\x74\40\132\157\156\145", "\157\x72\144\145\162" => 1)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(201, $response->get_status()); $this->assertEquals(array("\151\x64" => $data["\151\x64"], "\156\x61\155\145" => "\x54\145\163\x74\40\x5a\x6f\x6e\x65", "\x6f\162\x64\145\162" => 1, "\x5f\x6c\x69\x6e\x6b\x73" => array("\x73\145\154\x66" => array(array("\x68\x72\x65\x66" => rest_url("\x2f\167\x63\57\x76\x33\x2f\x73\150\x69\160\x70\151\x6e\x67\57\x7a\x6f\156\x65\163\x2f" . $data["\x69\144"]))), "\143\157\154\154\145\143\x74\x69\157\156" => array(array("\150\x72\145\x66" => rest_url("\57\x77\x63\57\166\x33\57\163\150\x69\160\160\x69\156\x67\x2f\172\157\x6e\x65\163"))), "\x64\x65\x73\x63\x72\151\x62\x65\144\142\171" => array(array("\x68\162\x65\146" => rest_url("\57\167\x63\57\x76\x33\57\x73\x68\x69\x70\160\151\156\147\57\x7a\157\156\x65\163\57" . $data["\x69\144"] . "\57\154\157\143\x61\164\x69\157\x6e\x73"))))), $data); } public function test_create_shipping_zone_without_permission() { wp_set_current_user(0); $request = new WP_REST_Request("\x50\117\123\x54", "\57\x77\143\57\x76\x33\57\x73\x68\151\160\160\151\x6e\147\57\x7a\x6f\156\x65\163"); $request->set_body_params(array("\x6e\141\x6d\x65" => "\124\x65\163\x74\x20\x5a\157\156\x65", "\x6f\162\x64\145\x72" => 1)); $response = $this->server->dispatch($request); $this->assertEquals(401, $response->get_status()); } public function test_update_shipping_zone() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\x54\145\163\x74\40\x5a\x6f\x6e\x65"); $request = new WP_REST_Request("\x50\125\124", "\57\x77\143\x2f\166\63\57\x73\150\151\x70\160\x69\156\147\57\172\x6f\x6e\x65\x73\57" . $zone->get_id()); $request->set_body_params(array("\156\x61\155\x65" => "\x5a\157\156\x65\40\x54\x65\x73\x74", "\157\x72\144\x65\162" => 2)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(array("\x69\x64" => $zone->get_id(), "\156\x61\x6d\145" => "\132\x6f\156\x65\40\124\x65\163\164", "\157\162\x64\145\x72" => 2, "\x5f\154\151\x6e\153\163" => array("\x73\x65\154\146" => array(array("\x68\162\x65\146" => rest_url("\57\x77\143\57\x76\x33\x2f\x73\150\x69\160\x70\151\156\147\57\x7a\x6f\x6e\x65\x73\57" . $zone->get_id()))), "\143\157\x6c\154\145\x63\164\x69\157\156" => array(array("\150\x72\145\146" => rest_url("\x2f\167\x63\x2f\x76\x33\57\163\x68\x69\x70\x70\151\x6e\147\57\x7a\157\x6e\x65\163"))), "\x64\x65\163\x63\162\151\x62\x65\144\142\x79" => array(array("\150\162\x65\146" => rest_url("\x2f\167\143\x2f\x76\x33\57\163\150\151\x70\160\x69\156\x67\57\172\x6f\x6e\145\x73\57" . $zone->get_id() . "\57\x6c\x6f\143\141\164\x69\157\x6e\x73"))))), $data); } public function test_update_shipping_zone_invalid_id() { wp_set_current_user($this->user); $request = new WP_REST_Request("\x50\x55\x54", "\x2f\x77\x63\57\166\63\x2f\x73\150\151\160\x70\x69\x6e\x67\x2f\x7a\x6f\x6e\145\x73\x2f\65\65\65\65\65\65"); $request->set_body_params(array("\156\141\155\145" => "\x5a\x6f\x6e\x65\40\124\x65\x73\164", "\x6f\x72\144\145\162" => 2)); $response = $this->server->dispatch($request); $this->assertEquals(404, $response->get_status()); } public function test_delete_shipping_zone() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\x5a\x6f\156\145\x20\x31"); $request = new WP_REST_Request("\x44\x45\114\105\x54\105", "\x2f\x77\x63\57\166\63\57\163\150\x69\160\x70\151\156\x67\57\x7a\x6f\x6e\x65\x73\57" . $zone->get_id()); $request->set_param("\x66\x6f\x72\x63\145", true); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); } public function test_delete_shipping_zone_without_permission() { wp_set_current_user(0); $zone = $this->create_shipping_zone("\x5a\x6f\x6e\x65\x20\61"); $request = new WP_REST_Request("\x44\x45\114\x45\124\x45", "\x2f\167\x63\x2f\166\63\57\x73\x68\151\x70\160\x69\156\x67\57\172\x6f\156\x65\163\x2f" . $zone->get_id()); $request->set_param("\x66\x6f\x72\143\x65", true); $response = $this->server->dispatch($request); $this->assertEquals(401, $response->get_status()); } public function test_delete_shipping_zone_invalid_id() { wp_set_current_user($this->user); $request = new WP_REST_Request("\x44\x45\114\105\x54\x45", "\x2f\167\x63\57\x76\63\57\x73\x68\151\x70\160\x69\x6e\x67\57\x7a\157\x6e\x65\163\x2f\x35\65\65\65\x35\x35"); $response = $this->server->dispatch($request); $this->assertEquals(404, $response->get_status()); } public function test_get_single_shipping_zone() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\x54\145\x73\164\x20\132\157\156\x65"); $response = $this->server->dispatch(new WP_REST_Request("\107\105\x54", "\57\167\x63\57\166\63\57\163\x68\151\160\160\151\156\147\57\172\157\156\x65\163\57" . $zone->get_id())); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(array("\151\144" => $zone->get_id(), "\x6e\141\155\x65" => "\124\145\x73\x74\x20\x5a\x6f\x6e\x65", "\x6f\162\144\x65\x72" => 0, "\x5f\x6c\151\156\x6b\x73" => array("\163\145\x6c\146" => array(array("\150\x72\145\x66" => rest_url("\57\167\x63\x2f\x76\63\57\163\150\x69\160\160\151\x6e\x67\x2f\172\x6f\x6e\145\x73\x2f" . $zone->get_id()))), "\x63\x6f\x6c\x6c\145\x63\x74\151\157\x6e" => array(array("\150\162\145\x66" => rest_url("\57\x77\x63\57\166\x33\x2f\x73\x68\151\x70\160\x69\156\x67\x2f\x7a\157\x6e\145\163"))), "\144\145\163\143\162\x69\142\x65\144\142\171" => array(array("\x68\x72\145\x66" => rest_url("\x2f\167\x63\57\x76\63\x2f\x73\150\151\x70\160\x69\x6e\x67\57\x7a\x6f\x6e\145\x73\x2f" . $zone->get_id() . "\57\154\157\x63\141\x74\x69\x6f\x6e\x73"))))), $data); } public function test_get_single_shipping_zone_invalid_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("\107\x45\x54", "\x2f\x77\x63\x2f\166\x33\x2f\x73\x68\151\x70\x70\x69\x6e\x67\57\172\x6f\x6e\x65\163\57\x31")); $this->assertEquals(404, $response->get_status()); } public function test_get_locations() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\132\x6f\x6e\x65\40\x31", 0, array(array("\143\x6f\x64\x65" => "\125\123", "\x74\171\x70\145" => "\143\157\165\x6e\x74\162\x79"))); $response = $this->server->dispatch(new WP_REST_Request("\x47\105\124", "\57\167\x63\57\166\63\57\x73\150\151\x70\x70\151\x6e\x67\57\172\157\x6e\x65\163\57" . $zone->get_id() . "\x2f\154\157\x63\x61\x74\151\x6f\x6e\163")); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 1); $this->assertEquals(array(array("\x63\x6f\x64\x65" => "\x55\123", "\x74\x79\x70\x65" => "\x63\157\165\x6e\164\x72\171", "\x5f\154\x69\x6e\x6b\x73" => array("\x63\x6f\x6c\x6c\x65\143\x74\x69\x6f\156" => array(array("\x68\x72\x65\x66" => rest_url("\x2f\167\143\x2f\x76\63\x2f\x73\150\x69\160\160\151\156\x67\57\172\x6f\156\145\163\x2f" . $zone->get_id() . "\57\x6c\x6f\x63\141\164\151\x6f\x6e\163"))), "\x64\x65\x73\143\162\151\142\145\x73" => array(array("\150\162\145\x66" => rest_url("\57\x77\x63\57\166\x33\x2f\163\150\151\160\x70\x69\x6e\x67\x2f\172\x6f\156\145\x73\57" . $zone->get_id())))))), $data); } public function test_get_locations_invalid_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("\x47\x45\124", "\57\x77\143\57\x76\63\57\163\x68\x69\160\160\151\x6e\x67\x2f\172\x6f\156\145\163\57\x31\x2f\154\x6f\143\141\164\x69\157\156\x73")); $this->assertEquals(404, $response->get_status()); } public function test_update_locations() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\x54\x65\163\164\40\x5a\157\x6e\x65"); $request = new WP_REST_Request("\x50\x55\124", "\57\167\x63\x2f\166\63\57\163\x68\151\160\160\151\x6e\x67\57\172\157\156\145\x73\x2f" . $zone->get_id() . "\57\x6c\x6f\x63\141\164\151\x6f\x6e\163"); $request->add_header("\x43\x6f\156\164\x65\156\164\x2d\x54\171\160\x65", "\141\x70\x70\x6c\x69\143\x61\x74\x69\157\x6e\57\152\x73\157\x6e"); $request->set_body(json_encode(array(array("\143\157\144\x65" => "\125\113", "\x74\171\x70\x65" => "\143\x6f\165\156\x74\x72\171"), array("\143\157\144\145" => "\125\123"), array("\143\x6f\x64\145" => "\123\127\61\101\60\x41\x41", "\x74\171\160\x65" => "\160\x6f\x73\x74\143\157\144\145"), array("\x74\171\x70\x65" => "\x63\x6f\156\x74\151\x6e\x65\x6e\164")))); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertEquals(3, count($data)); $this->assertEquals(array(array("\143\157\x64\145" => "\125\113", "\164\171\160\145" => "\x63\157\x75\x6e\164\x72\171", "\137\154\151\156\153\x73" => array("\143\157\154\x6c\x65\x63\164\151\157\x6e" => array(array("\150\162\145\146" => rest_url("\57\x77\143\57\x76\x33\x2f\163\x68\151\x70\160\151\x6e\147\x2f\172\x6f\x6e\x65\163\57" . $zone->get_id() . "\57\x6c\x6f\x63\x61\x74\x69\157\156\x73"))), "\144\x65\163\143\162\151\x62\x65\163" => array(array("\x68\x72\145\146" => rest_url("\x2f\167\x63\57\166\x33\x2f\x73\x68\x69\x70\160\x69\156\147\x2f\172\157\x6e\145\163\57" . $zone->get_id()))))), array("\143\x6f\x64\145" => "\125\x53", "\164\171\160\x65" => "\x63\157\165\x6e\164\x72\x79", "\137\x6c\151\156\153\x73" => array("\x63\x6f\x6c\154\145\x63\164\x69\x6f\156" => array(array("\150\162\145\146" => rest_url("\x2f\x77\x63\57\x76\x33\57\163\150\151\160\x70\x69\156\147\x2f\172\157\156\x65\x73\x2f" . $zone->get_id() . "\x2f\x6c\x6f\x63\141\164\151\x6f\156\x73"))), "\x64\x65\x73\143\x72\151\x62\145\163" => array(array("\x68\x72\x65\x66" => rest_url("\x2f\x77\x63\x2f\166\x33\57\163\x68\x69\160\160\151\156\147\x2f\x7a\x6f\x6e\x65\163\57" . $zone->get_id()))))), array("\x63\157\x64\145" => "\123\127\61\101\60\101\101", "\x74\x79\160\145" => "\160\157\163\x74\143\157\x64\145", "\137\x6c\x69\x6e\x6b\x73" => array("\x63\x6f\154\154\x65\x63\164\151\x6f\x6e" => array(array("\x68\x72\145\x66" => rest_url("\57\x77\143\x2f\x76\x33\x2f\x73\x68\151\x70\160\151\156\147\x2f\172\x6f\x6e\145\x73\57" . $zone->get_id() . "\x2f\154\x6f\x63\141\x74\x69\x6f\x6e\x73"))), "\x64\x65\x73\143\x72\x69\x62\x65\x73" => array(array("\x68\x72\145\146" => rest_url("\x2f\167\x63\x2f\166\63\57\x73\150\x69\x70\x70\x69\x6e\x67\57\172\x6f\x6e\145\163\57" . $zone->get_id())))))), $data); } public function test_update_locations_invalid_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("\x50\x55\124", "\x2f\x77\x63\x2f\x76\63\57\x73\x68\x69\160\x70\151\156\147\57\172\x6f\156\x65\163\57\61\57\154\157\143\141\x74\151\157\x6e\163")); $this->assertEquals(404, $response->get_status()); } public function test_get_methods() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\132\157\156\145\40\61"); $instance_id = $zone->add_shipping_method("\x66\x6c\141\x74\137\162\x61\164\x65"); $methods = $zone->get_shipping_methods(); $method = $methods[$instance_id]; $settings = array(); $method->init_instance_settings(); foreach ($method->get_instance_form_fields() as $id => $field) { $data = array("\151\x64" => $id, "\154\141\x62\145\x6c" => $field["\x74\x69\x74\154\x65"], "\x64\x65\x73\x63\162\151\160\x74\x69\x6f\x6e" => empty($field["\x64\145\x73\x63\162\151\160\164\x69\x6f\x6e"]) ? '' : $field["\144\x65\163\x63\162\x69\x70\x74\x69\157\156"], "\x74\x79\160\145" => $field["\x74\171\160\145"], "\166\x61\154\165\x65" => $method->instance_settings[$id], "\144\145\146\141\165\x6c\x74" => empty($field["\x64\145\146\141\x75\154\x74"]) ? '' : $field["\x64\x65\146\141\165\154\x74"], "\164\151\160" => empty($field["\144\x65\163\143\162\x69\160\164\x69\x6f\156"]) ? '' : $field["\x64\x65\163\x63\x72\x69\x70\x74\151\157\156"], "\160\154\141\143\x65\x68\157\154\144\x65\x72" => empty($field["\x70\x6c\141\x63\x65\150\x6f\x6c\x64\145\162"]) ? '' : $field["\160\x6c\x61\143\x65\x68\x6f\154\x64\x65\162"]); if (!empty($field["\x6f\160\x74\x69\157\x6e\x73"])) { $data["\157\x70\x74\151\x6f\x6e\163"] = $field["\x6f\160\x74\151\157\156\x73"]; } $settings[$id] = $data; } $response = $this->server->dispatch(new WP_REST_Request("\x47\x45\124", "\x2f\x77\143\x2f\x76\63\57\x73\150\x69\x70\160\x69\156\x67\57\x7a\157\156\145\x73\57" . $zone->get_id() . "\57\x6d\145\164\150\157\144\x73")); $data = $response->get_data(); $expected = array("\151\x64" => $instance_id, "\151\x6e\x73\x74\141\x6e\x63\x65\x5f\x69\x64" => $instance_id, "\164\x69\164\154\x65" => $method->instance_settings["\164\x69\x74\x6c\145"], "\157\162\x64\x65\x72" => $method->method_order, "\x65\156\x61\x62\x6c\145\144" => "\x79\x65\x73" === $method->enabled, "\155\x65\164\x68\x6f\x64\137\151\x64" => $method->id, "\x6d\145\x74\150\157\x64\137\164\151\164\x6c\145" => $method->method_title, "\x6d\x65\x74\x68\x6f\x64\137\144\145\163\143\162\x69\x70\x74\151\x6f\156" => $method->method_description, "\x73\x65\164\164\151\x6e\147\x73" => $settings, "\137\x6c\x69\156\x6b\163" => array("\163\x65\x6c\x66" => array(array("\150\162\x65\146" => rest_url("\x2f\x77\143\x2f\166\63\57\x73\x68\151\160\160\151\x6e\x67\x2f\x7a\157\x6e\x65\x73\x2f" . $zone->get_id() . "\x2f\x6d\145\164\x68\157\144\163\57" . $instance_id))), "\143\157\154\154\x65\x63\164\151\x6f\156" => array(array("\x68\162\145\x66" => rest_url("\x2f\167\x63\x2f\x76\x33\x2f\x73\150\151\160\160\x69\156\x67\x2f\172\x6f\x6e\145\x73\x2f" . $zone->get_id() . "\x2f\x6d\x65\164\x68\x6f\144\x73"))), "\x64\145\163\x63\x72\151\142\x65\163" => array(array("\150\162\x65\146" => rest_url("\x2f\x77\x63\x2f\x76\63\x2f\163\150\151\160\160\x69\x6e\147\x2f\172\157\x6e\145\x73\x2f" . $zone->get_id()))))); $this->assertEquals(200, $response->get_status()); $this->assertEquals(count($data), 1); $this->assertContains($expected, $data); $response = $this->server->dispatch(new WP_REST_Request("\x47\x45\x54", "\x2f\167\143\57\x76\x33\57\163\150\x69\160\x70\151\x6e\x67\57\x7a\157\156\x65\163\x2f" . $zone->get_id() . "\x2f\x6d\x65\164\150\157\x64\x73\x2f" . $instance_id)); $data = $response->get_data(); $this->assertEquals(200, $response->get_status()); $this->assertEquals($expected, $data); } public function test_get_methods_invalid_zone_id() { wp_set_current_user($this->user); $response = $this->server->dispatch(new WP_REST_Request("\107\x45\x54", "\57\167\143\57\166\x33\x2f\x73\x68\x69\160\160\x69\156\147\x2f\172\157\x6e\145\x73\57\x31\57\155\x65\x74\x68\x6f\x64\163")); $this->assertEquals(404, $response->get_status()); $response = $this->server->dispatch(new WP_REST_Request("\x47\105\x54", "\x2f\167\x63\57\166\x33\x2f\x73\150\x69\160\x70\x69\156\147\x2f\172\157\x6e\145\163\x2f\61\57\x6d\x65\x74\150\x6f\x64\163\x2f\x31")); $this->assertEquals(404, $response->get_status()); } public function test_get_methods_invalid_method_id() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\x5a\157\x6e\x65\40\x31"); $response = $this->server->dispatch(new WP_REST_Request("\x47\x45\124", "\x2f\167\143\x2f\166\x33\57\x73\x68\x69\x70\160\151\156\147\57\172\x6f\156\x65\x73\57" . $zone->get_id() . "\x2f\155\x65\164\150\x6f\144\163\57\x31")); $this->assertEquals(404, $response->get_status()); } public function test_update_methods() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\x5a\157\156\145\x20\x31"); $instance_id = $zone->add_shipping_method("\146\x6c\141\x74\137\162\141\x74\145"); $methods = $zone->get_shipping_methods(); $method = $methods[$instance_id]; $request = new WP_REST_Request("\x47\x45\x54", "\57\x77\143\57\x76\63\57\163\x68\151\160\160\151\156\147\57\172\157\x6e\145\x73\57" . $zone->get_id() . "\57\155\145\x74\x68\157\x64\x73\57" . $instance_id); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertArrayHasKey("\x74\151\164\x6c\x65", $data["\163\x65\164\x74\151\156\x67\x73"]); $this->assertEquals("\106\x6c\x61\x74\x20\x72\141\x74\145", $data["\x73\145\164\164\151\x6e\x67\163"]["\x74\x69\164\x6c\145"]["\x76\x61\x6c\165\x65"]); $this->assertArrayHasKey("\x74\141\x78\x5f\x73\164\x61\x74\165\163", $data["\163\x65\x74\164\151\x6e\147\x73"]); $this->assertEquals("\164\x61\170\x61\x62\154\x65", $data["\163\145\x74\164\x69\x6e\x67\x73"]["\x74\x61\x78\137\163\164\141\x74\x75\x73"]["\166\x61\x6c\x75\145"]); $this->assertArrayHasKey("\x63\157\x73\164", $data["\163\x65\x74\164\151\156\147\x73"]); $this->assertEquals("\x30", $data["\163\145\164\x74\x69\156\147\163"]["\x63\157\x73\164"]["\x76\x61\154\x75\x65"]); $request = new WP_REST_Request("\120\x4f\x53\x54", "\57\x77\143\57\x76\x33\57\163\x68\x69\160\x70\151\156\x67\x2f\172\157\x6e\x65\163\x2f" . $zone->get_id() . "\x2f\x6d\145\x74\150\x6f\x64\163\57" . $instance_id); $request->set_body_params(array("\x73\x65\x74\x74\x69\x6e\x67\163" => array("\x63\157\163\164" => 5))); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertArrayHasKey("\164\x69\164\154\145", $data["\163\145\164\164\151\x6e\x67\163"]); $this->assertEquals("\x46\154\x61\164\40\x72\x61\164\145", $data["\x73\145\x74\164\x69\156\147\x73"]["\x74\x69\x74\x6c\145"]["\166\x61\x6c\165\145"]); $this->assertArrayHasKey("\164\141\170\x5f\163\x74\x61\164\x75\163", $data["\163\x65\164\164\151\x6e\147\163"]); $this->assertEquals("\164\x61\170\141\142\x6c\x65", $data["\x73\145\164\x74\151\156\x67\163"]["\x74\141\170\x5f\x73\x74\x61\x74\x75\x73"]["\166\141\x6c\x75\145"]); $this->assertArrayHasKey("\143\157\163\x74", $data["\163\145\164\x74\151\156\147\163"]); $this->assertEquals("\65", $data["\x73\145\164\164\151\x6e\x67\x73"]["\x63\157\x73\164"]["\x76\141\154\165\x65"]); $request = new WP_REST_Request("\120\x4f\123\x54", "\57\x77\x63\57\166\63\57\x73\x68\x69\160\160\x69\156\147\57\172\157\x6e\145\x73\57" . $zone->get_id() . "\57\x6d\x65\164\150\x6f\x64\163\x2f" . $instance_id); $request->set_body_params(array("\163\x65\164\x74\x69\156\x67\163" => array("\x63\x6f\x73\164" => 10, "\164\141\x78\137\x73\164\141\164\x75\x73" => "\156\x6f\156\145"))); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertArrayHasKey("\x74\151\x74\x6c\x65", $data["\163\x65\164\164\x69\156\147\x73"]); $this->assertEquals("\x46\154\x61\x74\x20\162\141\164\145", $data["\163\145\164\164\151\x6e\x67\163"]["\164\151\x74\154\145"]["\x76\141\154\165\x65"]); $this->assertArrayHasKey("\164\141\x78\137\163\164\x61\x74\x75\163", $data["\x73\145\x74\x74\151\x6e\x67\x73"]); $this->assertEquals("\x6e\x6f\156\x65", $data["\163\x65\164\x74\x69\156\x67\x73"]["\x74\141\170\x5f\x73\x74\141\x74\165\x73"]["\166\x61\x6c\165\145"]); $this->assertArrayHasKey("\x63\x6f\x73\x74", $data["\163\145\164\x74\x69\x6e\147\163"]); $this->assertEquals("\61\x30", $data["\163\145\164\164\x69\x6e\147\163"]["\143\157\163\x74"]["\166\141\154\x75\145"]); $request = new WP_REST_Request("\x50\x4f\x53\124", "\57\167\143\57\166\63\x2f\163\150\x69\160\160\x69\x6e\147\57\x7a\157\x6e\145\x73\57" . $zone->get_id() . "\57\155\x65\164\x68\157\144\163\57" . $instance_id); $request->set_body_params(array("\x73\145\x74\x74\151\156\147\x73" => array("\x63\157\x73\164" => 10, "\x74\x61\x78\137\x73\164\141\x74\x75\x73" => "\164\x68\151\163\137\151\163\137\x6e\157\164\x5f\141\137\166\141\154\x69\x64\x5f\157\x70\164\x69\157\156"))); $response = $this->server->dispatch($request); $this->assertEquals(400, $response->get_status()); $this->assertTrue($data["\x65\156\141\142\154\145\144"]); $this->assertEquals(1, $data["\157\x72\144\x65\x72"]); $request = new WP_REST_Request("\x50\x4f\123\x54", "\57\x77\143\x2f\x76\63\x2f\x73\x68\x69\160\160\151\x6e\x67\57\x7a\x6f\156\145\163\57" . $zone->get_id() . "\57\x6d\145\164\150\x6f\144\x73\x2f" . $instance_id); $request->set_body_params(array("\145\x6e\141\142\154\x65\x64" => false, "\x6f\162\x64\145\162" => 2)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertFalse($data["\145\156\141\x62\154\145\x64"]); $this->assertEquals(2, $data["\x6f\162\144\x65\162"]); $this->assertArrayHasKey("\x63\x6f\x73\x74", $data["\163\145\x74\164\x69\156\x67\x73"]); $this->assertEquals("\61\x30", $data["\x73\x65\x74\x74\x69\156\x67\x73"]["\x63\x6f\163\x74"]["\166\141\x6c\x75\145"]); } public function test_create_method() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\132\x6f\156\145\40\x31"); $request = new WP_REST_Request("\x50\117\123\124", "\x2f\167\x63\57\166\x33\57\163\x68\151\160\x70\151\156\147\x2f\x7a\x6f\x6e\x65\x73\57" . $zone->get_id() . "\x2f\x6d\145\x74\150\157\x64\x73"); $request->set_body_params(array("\155\x65\164\x68\157\144\x5f\x69\144" => "\146\154\x61\164\137\162\141\164\x65", "\145\156\141\x62\154\x65\x64" => false, "\157\x72\144\x65\162" => 2)); $response = $this->server->dispatch($request); $data = $response->get_data(); $this->assertFalse($data["\x65\x6e\141\x62\154\145\x64"]); $this->assertEquals(2, $data["\x6f\x72\x64\x65\x72"]); $this->assertArrayHasKey("\143\157\x73\x74", $data["\163\145\164\164\151\156\147\163"]); $this->assertEquals("\x30", $data["\x73\x65\164\x74\x69\x6e\x67\163"]["\x63\157\163\164"]["\166\141\x6c\165\145"]); } public function test_delete_method() { wp_set_current_user($this->user); $zone = $this->create_shipping_zone("\132\157\156\145\x20\x31"); $instance_id = $zone->add_shipping_method("\146\x6c\x61\x74\137\162\x61\164\x65"); $methods = $zone->get_shipping_methods(); $method = $methods[$instance_id]; $request = new WP_REST_Request("\x44\x45\114\x45\x54\105", "\57\167\x63\57\x76\x33\x2f\x73\150\151\160\x70\151\156\147\x2f\x7a\x6f\x6e\145\163\57" . $zone->get_id() . "\x2f\155\145\164\150\x6f\144\163\57" . $instance_id); $request->set_param("\146\x6f\x72\143\145", true); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->get_status()); } }

Function Calls

None

Variables

None

Stats

MD5 bfa987e4f6847c15fc1c75d788ae71df
Eval Count 0
Decode Time 98 ms