+ ', + '' + ); + ?> +
+' . esc_html( $package ) . '
'
+ ) . ' - ' . esc_html__( 'Your installation of WooCommerce is incomplete. If you installed WooCommerce from GitHub, please refer to this document to set up your development environment: https://github.com/woocommerce/woocommerce/wiki/How-to-set-up-WooCommerce-development-environment', 'woocommerce' )
+ );
+ }
+ add_action(
+ 'admin_notices',
+ function() use ( $package ) {
+ ?>
+
+
+ ' . esc_html( $package ) . ''
+ );
+ ?>
+
+
+ ',
+ ''
+ );
+ ?>
+
Review content here
\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $product_reviews[0]['reviewer_avatar_urls'], - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews/' . $review_id ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews' ), - ), - ), - 'up' => array( - array( - 'href' => rest_url( '/wc/v3/products/' . $product->get_id() ), - ), - ), - ), - ), - $product_reviews - ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.5.0 - */ - public function test_get_product_reviews_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests to make sure an error is returned when an invalid product is loaded. - * - * @since 3.5.0 - */ - public function test_get_product_reviews_invalid_product() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/0/reviews' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests getting a single product review. - * - * @since 3.5.0 - */ - public function test_get_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $product_review_id, - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => "Review content here
\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests getting a single product review without the correct permissions. - * - * @since 3.5.0 - */ - public function test_get_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a product review with an invalid ID. - * - * @since 3.5.0 - */ - public function test_get_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests creating a product review. - * - * @since 3.5.0 - */ - public function test_create_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'rating' => '5', - 'product_id' => $product->get_id(), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => 'Hello world.', - 'rating' => 5, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests creating a product review without required fields. - * - * @since 3.5.0 - */ - public function test_create_product_review_invalid_fields() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - - // missing review - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // Missing reviewer. - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // missing reviewer_email - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests updating a product review. - * - * @since 3.5.0 - */ - public function test_update_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - $this->assertEquals( "Review content here
\n", $data['review'] ); - $this->assertEquals( 'admin', $data['reviewer'] ); - $this->assertEquals( 'woo@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 0, $data['rating'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world - updated.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo2@woo.local', - 'rating' => 3, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'Hello world - updated.', $data['review'] ); - $this->assertEquals( 'Justin', $data['reviewer'] ); - $this->assertEquals( 'woo2@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 3, $data['rating'] ); - } - - /** - * Tests updating a product review without the correct permissions. - * - * @since 3.5.0 - */ - public function test_update_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests that updating a product review with an invalid id fails. - * - * @since 3.5.0 - */ - public function test_update_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/0' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test deleting a product review. - * - * @since 3.5.0 - */ - public function test_delete_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a product review without permission/creds. - * - * @since 3.5.0 - */ - public function test_delete_product_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a product review with an invalid id. - * - * @since 3.5.0 - */ - public function test_delete_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test batch managing product reviews. - * - * @since 3.5.0 - */ - public function test_product_reviews_batch() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - - $review_1_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $review_2_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $review_3_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $review_4_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $review_1_id, - 'review' => 'Updated review.', - ), - ), - 'delete' => array( - $review_2_id, - $review_3_id, - ), - 'create' => array( - array( - 'review' => 'New review.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo3@woo.local', - 'product_id' => $product->get_id(), - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'Updated review.', $data['update'][0]['review'] ); - $this->assertEquals( 'New review.', $data['create'][0]['review'] ); - $this->assertEquals( $review_2_id, $data['delete'][0]['previous']['id'] ); - $this->assertEquals( $review_3_id, $data['delete'][1]['previous']['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ); - $request->set_param( 'product', $product->get_id() ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test the product review schema. - * - * @since 3.5.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/reviews' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 11, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'product_id', $properties ); - $this->assertArrayHasKey( 'status', $properties ); - $this->assertArrayHasKey( 'reviewer', $properties ); - $this->assertArrayHasKey( 'reviewer_email', $properties ); - $this->assertArrayHasKey( 'review', $properties ); - $this->assertArrayHasKey( 'rating', $properties ); - $this->assertArrayHasKey( 'verified', $properties ); - - if ( get_option( 'show_avatars' ) ) { - $this->assertArrayHasKey( 'reviewer_avatar_urls', $properties ); - } - } -} diff --git a/tests/unit-tests/api/product-variations.php b/tests/unit-tests/api/product-variations.php deleted file mode 100644 index ab1b810be43..00000000000 --- a/tests/unit-tests/api/product-variations.php +++ /dev/null @@ -1,474 +0,0 @@ -endpoint = new WC_REST_Product_Variations_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.5.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v3/products/(?Padmin@example.org
.',
- 'type' => 'text',
- 'default' => '',
- 'tip' => 'Enter recipients (comma separated) for this email. Defaults to admin@example.org
.',
- 'value' => '',
- '_links' => array(
- 'self' => array(
- array(
- 'href' => rest_url( '/wc/v3/settings/email_new_order/recipient' ),
- ),
- ),
- 'collection' => array(
- array(
- 'href' => rest_url( '/wc/v3/settings/email_new_order' ),
- ),
- ),
- ),
- ),
- $settings
- );
-
- // test get single
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) );
- $setting = $response->get_data();
-
- $this->assertEquals(
- array(
- 'id' => 'subject',
- 'label' => 'Subject',
- 'description' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'type' => 'text',
- 'default' => '',
- 'tip' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'value' => '',
- 'group_id' => 'email_new_order',
- ),
- $setting
- );
-
- // test update
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_new_order', 'subject' ) );
- $request->set_body_params(
- array(
- 'value' => 'This is my subject',
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
-
- $this->assertEquals(
- array(
- 'id' => 'subject',
- 'label' => 'Subject',
- 'description' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'type' => 'text',
- 'default' => '',
- 'tip' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'value' => 'This is my subject',
- 'group_id' => 'email_new_order',
- ),
- $setting
- );
-
- // test updating another subject and making sure it works with a "similar" id
- $request = new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
-
- $this->assertEmpty( $setting['value'] );
-
- // test update
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
- $request->set_body_params(
- array(
- 'value' => 'This is my new subject',
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
-
- $this->assertEquals( 'This is my new subject', $setting['value'] );
-
- // make sure the other is what we left it
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) );
- $setting = $response->get_data();
-
- $this->assertEquals( 'This is my subject', $setting['value'] );
- }
-
- /**
- * Test validation of checkbox settings.
- *
- * @since 3.5.0
- */
- public function test_validation_checkbox() {
- wp_set_current_user( $this->user );
-
- // test bogus value
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
- $request->set_body_params(
- array(
- 'value' => 'not_yes_or_no',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 400, $response->get_status() );
-
- // test yes
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
- $request->set_body_params(
- array(
- 'value' => 'yes',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 200, $response->get_status() );
-
- // test no
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
- $request->set_body_params(
- array(
- 'value' => 'no',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 200, $response->get_status() );
- }
-
- /**
- * Test validation of radio settings.
- *
- * @since 3.5.0
- */
- public function test_validation_radio() {
- wp_set_current_user( $this->user );
-
- // not a valid option
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
- $request->set_body_params(
- array(
- 'value' => 'billing2',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 400, $response->get_status() );
-
- // valid
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
- $request->set_body_params(
- array(
- 'value' => 'billing',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 200, $response->get_status() );
- }
-
- /**
- * Test validation of multiselect.
- *
- * @since 3.5.0
- */
- public function test_validation_multiselect() {
- wp_set_current_user( $this->user );
-
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ) );
- $setting = $response->get_data();
- $this->assertEmpty( $setting['value'] );
-
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) );
- $request->set_body_params(
- array(
- 'value' => array( 'AX', 'DZ', 'MMM' ),
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
- }
-
- /**
- * Test validation of select.
- *
- * @since 3.5.0
- */
- public function test_validation_select() {
- wp_set_current_user( $this->user );
-
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ) );
- $setting = $response->get_data();
- $this->assertEquals( 'kg', $setting['value'] );
-
- // invalid
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
- $request->set_body_params(
- array(
- 'value' => 'pounds', // invalid, should be lbs
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 400, $response->get_status() );
-
- // valid
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
- $request->set_body_params(
- array(
- 'value' => 'lbs', // invalid, should be lbs
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( 'lbs', $setting['value'] );
- }
-
- /**
- * Test to make sure the 'base location' setting is present in the response.
- * That it is returned as 'select' and not 'single_select_country',
- * and that both state and country options are returned.
- *
- * @since 3.5.0
- */
- public function test_woocommerce_default_country() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_default_country' ) );
- $setting = $response->get_data();
-
- $this->assertEquals( 'select', $setting['type'] );
- $this->assertArrayHasKey( 'GB', $setting['options'] );
- $this->assertArrayHasKey( 'US:OR', $setting['options'] );
- }
-
- /**
- * Test to make sure the store address setting can be fetched and updated.
- *
- * @since 3.5.0
- */
- public function test_woocommerce_store_address() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_address' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-
- /**
- * Test to make sure the store address 2 (line 2) setting can be fetched and updated.
- *
- * @since 3.5.0
- */
- public function test_woocommerce_store_address_2() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_address_2' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-
- /**
- * Test to make sure the store city setting can be fetched and updated.
- *
- * @since 3.5.0
- */
- public function test_woocommerce_store_city() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_city' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-
- /**
- * Test to make sure the store postcode setting can be fetched and updated.
- *
- * @since 3.5.0
- */
- public function test_woocommerce_store_postcode() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_postcode' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-}
diff --git a/tests/unit-tests/api/shipping-methods.php b/tests/unit-tests/api/shipping-methods.php
deleted file mode 100644
index ad139c427af..00000000000
--- a/tests/unit-tests/api/shipping-methods.php
+++ /dev/null
@@ -1,143 +0,0 @@
-endpoint = new WC_REST_Shipping_Methods_Controller();
- $this->user = $this->factory->user->create(
- array(
- 'role' => 'administrator',
- )
- );
- }
-
- /**
- * Test route registration.
- *
- * @since 3.5.0
- */
- public function test_register_routes() {
- $routes = $this->server->get_routes();
- $this->assertArrayHasKey( '/wc/v3/shipping_methods', $routes );
- $this->assertArrayHasKey( '/wc/v3/shipping_methods/(?PReview content here
\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $product_reviews[0]['reviewer_avatar_urls'], - '_links' => array( - 'self' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews/' . $review_id ), - ), - ), - 'collection' => array( - array( - 'href' => rest_url( '/wc/v3/products/reviews' ), - ), - ), - 'up' => array( - array( - 'href' => rest_url( '/wc/v3/products/' . $product->get_id() ), - ), - ), - ), - ), - $product_reviews - ); - } - - /** - * Tests to make sure product reviews cannot be viewed without valid permissions. - * - * @since 3.0.0 - */ - public function test_get_product_reviews_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests to make sure an error is returned when an invalid product is loaded. - * - * @since 3.0.0 - */ - public function test_get_product_reviews_invalid_product() { - wp_set_current_user( $this->user ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/0/reviews' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests getting a single product review. - * - * @since 3.0.0 - */ - public function test_get_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $product_review_id, - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => "Review content here
\n", - 'rating' => 0, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests getting a single product review without the correct permissions. - * - * @since 3.0.0 - */ - public function test_get_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests getting a product review with an invalid ID. - * - * @since 3.0.0 - */ - public function test_get_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/0' ) ); - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Tests creating a product review. - * - * @since 3.0.0 - */ - public function test_create_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'rating' => '5', - 'product_id' => $product->get_id(), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 201, $response->get_status() ); - $this->assertEquals( - array( - 'id' => $data['id'], - 'date_created' => $data['date_created'], - 'date_created_gmt' => $data['date_created_gmt'], - 'product_id' => $product->get_id(), - 'status' => 'approved', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - 'review' => 'Hello world.', - 'rating' => 5, - 'verified' => false, - 'reviewer_avatar_urls' => $data['reviewer_avatar_urls'], - ), - $data - ); - } - - /** - * Tests creating a product review without required fields. - * - * @since 3.0.0 - */ - public function test_create_product_review_invalid_fields() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - - // missing review - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // Missing reviewer. - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer_email' => 'woo@woo.local', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - - // missing reviewer_email - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 400, $response->get_status() ); - } - - /** - * Tests updating a product review. - * - * @since 3.0.0 - */ - public function test_update_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); - $data = $response->get_data(); - $this->assertEquals( "Review content here
\n", $data['review'] ); - $this->assertEquals( 'admin', $data['reviewer'] ); - $this->assertEquals( 'woo@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 0, $data['rating'] ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world - updated.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo2@woo.local', - 'rating' => 3, - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $this->assertEquals( 'Hello world - updated.', $data['review'] ); - $this->assertEquals( 'Justin', $data['reviewer'] ); - $this->assertEquals( 'woo2@woo.local', $data['reviewer_email'] ); - $this->assertEquals( 3, $data['rating'] ); - } - - /** - * Tests updating a product review without the correct permissions. - * - * @since 3.0.0 - */ - public function test_update_product_review_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Tests that updating a product review with an invalid id fails. - * - * @since 3.0.0 - */ - public function test_update_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/0' ); - $request->set_body_params( - array( - 'review' => 'Hello world.', - 'reviewer' => 'Admin', - 'reviewer_email' => 'woo@woo.dev', - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test deleting a product review. - * - * @since 3.0.0 - */ - public function test_delete_product_review() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); - } - - /** - * Test deleting a product review without permission/creds. - * - * @since 3.0.0 - */ - public function test_delete_product_without_permission() { - wp_set_current_user( 0 ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 401, $response->get_status() ); - } - - /** - * Test deleting a product review with an invalid id. - * - * @since 3.0.0 - */ - public function test_delete_product_review_invalid_id() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $product_review_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/0' ); - $request->set_param( 'force', true ); - $response = $this->server->dispatch( $request ); - - $this->assertEquals( 404, $response->get_status() ); - } - - /** - * Test batch managing product reviews. - */ - public function test_product_reviews_batch() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - - $review_1_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $review_2_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $review_3_id = WC_Helper_Product::create_product_review( $product->get_id() ); - $review_4_id = WC_Helper_Product::create_product_review( $product->get_id() ); - - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews/batch' ); - $request->set_body_params( - array( - 'update' => array( - array( - 'id' => $review_1_id, - 'review' => 'Updated review.', - ), - ), - 'delete' => array( - $review_2_id, - $review_3_id, - ), - 'create' => array( - array( - 'review' => 'New review.', - 'reviewer' => 'Justin', - 'reviewer_email' => 'woo3@woo.local', - 'product_id' => $product->get_id(), - ), - ), - ) - ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 'Updated review.', $data['update'][0]['review'] ); - $this->assertEquals( 'New review.', $data['create'][0]['review'] ); - $this->assertEquals( $review_2_id, $data['delete'][0]['previous']['id'] ); - $this->assertEquals( $review_3_id, $data['delete'][1]['previous']['id'] ); - - $request = new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ); - $request->set_param( 'product', $product->get_id() ); - - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 3, count( $data ) ); - } - - /** - * Test the product review schema. - * - * @since 3.0.0 - */ - public function test_product_review_schema() { - wp_set_current_user( $this->user ); - $product = WC_Helper_Product::create_simple_product(); - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/reviews' ); - $response = $this->server->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - - $this->assertEquals( 11, count( $properties ) ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'date_created', $properties ); - $this->assertArrayHasKey( 'date_created_gmt', $properties ); - $this->assertArrayHasKey( 'product_id', $properties ); - $this->assertArrayHasKey( 'status', $properties ); - $this->assertArrayHasKey( 'reviewer', $properties ); - $this->assertArrayHasKey( 'reviewer_email', $properties ); - $this->assertArrayHasKey( 'review', $properties ); - $this->assertArrayHasKey( 'rating', $properties ); - $this->assertArrayHasKey( 'verified', $properties ); - - if ( get_option( 'show_avatars' ) ) { - $this->assertArrayHasKey( 'reviewer_avatar_urls', $properties ); - } - } -} diff --git a/tests/unit-tests/api/v2/product-variations.php b/tests/unit-tests/api/v2/product-variations.php deleted file mode 100644 index 7e268a7c657..00000000000 --- a/tests/unit-tests/api/v2/product-variations.php +++ /dev/null @@ -1,473 +0,0 @@ -endpoint = new WC_REST_Product_Variations_Controller(); - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - - /** - * Test route registration. - * - * @since 3.0.0 - */ - public function test_register_routes() { - $routes = $this->server->get_routes(); - $this->assertArrayHasKey( '/wc/v2/products/(?Padmin@example.org
.',
- 'type' => 'text',
- 'default' => '',
- 'tip' => 'Enter recipients (comma separated) for this email. Defaults to admin@example.org
.',
- 'value' => '',
- '_links' => array(
- 'self' => array(
- array(
- 'href' => rest_url( '/wc/v2/settings/email_new_order/recipient' ),
- ),
- ),
- 'collection' => array(
- array(
- 'href' => rest_url( '/wc/v2/settings/email_new_order' ),
- ),
- ),
- ),
- ),
- $settings
- );
-
- // test get single
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) );
- $setting = $response->get_data();
-
- $this->assertEquals(
- array(
- 'id' => 'subject',
- 'label' => 'Subject',
- 'description' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'type' => 'text',
- 'default' => '',
- 'tip' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'value' => '',
- ),
- $setting
- );
-
- // test update
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_new_order', 'subject' ) );
- $request->set_body_params(
- array(
- 'value' => 'This is my subject',
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
-
- $this->assertEquals(
- array(
- 'id' => 'subject',
- 'label' => 'Subject',
- 'description' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'type' => 'text',
- 'default' => '',
- 'tip' => 'Available placeholders: {site_title}, {order_date}, {order_number}
',
- 'value' => 'This is my subject',
- ),
- $setting
- );
-
- // test updating another subject and making sure it works with a "similar" id
- $request = new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
-
- $this->assertEmpty( $setting['value'] );
-
- // test update
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
- $request->set_body_params(
- array(
- 'value' => 'This is my new subject',
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
-
- $this->assertEquals( 'This is my new subject', $setting['value'] );
-
- // make sure the other is what we left it
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) );
- $setting = $response->get_data();
-
- $this->assertEquals( 'This is my subject', $setting['value'] );
- }
-
- /**
- * Test validation of checkbox settings.
- *
- * @since 3.0.0
- */
- public function test_validation_checkbox() {
- wp_set_current_user( $this->user );
-
- // test bogus value
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
- $request->set_body_params(
- array(
- 'value' => 'not_yes_or_no',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 400, $response->get_status() );
-
- // test yes
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
- $request->set_body_params(
- array(
- 'value' => 'yes',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 200, $response->get_status() );
-
- // test no
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
- $request->set_body_params(
- array(
- 'value' => 'no',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 200, $response->get_status() );
- }
-
- /**
- * Test validation of radio settings.
- *
- * @since 3.0.0
- */
- public function test_validation_radio() {
- wp_set_current_user( $this->user );
-
- // not a valid option
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
- $request->set_body_params(
- array(
- 'value' => 'billing2',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 400, $response->get_status() );
-
- // valid
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
- $request->set_body_params(
- array(
- 'value' => 'billing',
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 200, $response->get_status() );
- }
-
- /**
- * Test validation of multiselect.
- *
- * @since 3.0.0
- */
- public function test_validation_multiselect() {
- wp_set_current_user( $this->user );
-
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ) );
- $setting = $response->get_data();
- $this->assertEmpty( $setting['value'] );
-
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) );
- $request->set_body_params(
- array(
- 'value' => array( 'AX', 'DZ', 'MMM' ),
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
- }
-
- /**
- * Test validation of select.
- *
- * @since 3.0.0
- */
- public function test_validation_select() {
- wp_set_current_user( $this->user );
-
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ) );
- $setting = $response->get_data();
- $this->assertEquals( 'kg', $setting['value'] );
-
- // invalid
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
- $request->set_body_params(
- array(
- 'value' => 'pounds', // invalid, should be lbs
- )
- );
- $response = $this->server->dispatch( $request );
- $this->assertEquals( 400, $response->get_status() );
-
- // valid
- $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
- $request->set_body_params(
- array(
- 'value' => 'lbs', // invalid, should be lbs
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( 'lbs', $setting['value'] );
- }
-
- /**
- * Test to make sure the 'base location' setting is present in the response.
- * That it is returned as 'select' and not 'single_select_country',
- * and that both state and country options are returned.
- *
- * @since 3.0.7
- */
- public function test_woocommerce_default_country() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_default_country' ) );
- $setting = $response->get_data();
-
- $this->assertEquals( 'select', $setting['type'] );
- $this->assertArrayHasKey( 'GB', $setting['options'] );
- $this->assertArrayHasKey( 'US:OR', $setting['options'] );
- }
-
- /**
- * Test to make sure the store address setting can be fetched and updated.
- *
- * @since 3.1.1
- */
- public function test_woocommerce_store_address() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_address' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-
- /**
- * Test to make sure the store address 2 (line 2) setting can be fetched and updated.
- *
- * @since 3.1.1
- */
- public function test_woocommerce_store_address_2() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_address_2' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-
- /**
- * Test to make sure the store city setting can be fetched and updated.
- *
- * @since 3.1.1
- */
- public function test_woocommerce_store_city() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_city' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-
- /**
- * Test to make sure the store postcode setting can be fetched and updated.
- *
- * @since 3.1.1
- */
- public function test_woocommerce_store_postcode() {
- wp_set_current_user( $this->user );
- $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_postcode' ) );
- $setting = $response->get_data();
- $this->assertEquals( 'text', $setting['type'] );
-
- // Repalce the old value with something uniquely new
- $old_value = $setting['value'];
- $new_value = $old_value . ' ' . rand( 1000, 9999 );
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
- $request->set_body_params(
- array(
- 'value' => $new_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $new_value, $setting['value'] );
-
- // Put the original value back
- $request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
- $request->set_body_params(
- array(
- 'value' => $old_value,
- )
- );
- $response = $this->server->dispatch( $request );
- $setting = $response->get_data();
- $this->assertEquals( $old_value, $setting['value'] );
- }
-}
diff --git a/tests/unit-tests/api/v2/shipping-methods.php b/tests/unit-tests/api/v2/shipping-methods.php
deleted file mode 100644
index 65c153e8f31..00000000000
--- a/tests/unit-tests/api/v2/shipping-methods.php
+++ /dev/null
@@ -1,143 +0,0 @@
-endpoint = new WC_REST_Shipping_Methods_Controller();
- $this->user = $this->factory->user->create(
- array(
- 'role' => 'administrator',
- )
- );
- }
-
- /**
- * Test route registration.
- *
- * @since 3.0.0
- */
- public function test_register_routes() {
- $routes = $this->server->get_routes();
- $this->assertArrayHasKey( '/wc/v2/shipping_methods', $routes );
- $this->assertArrayHasKey( '/wc/v2/shipping_methods/(?P- ', - '' - ); - ?> -
-