diff --git a/package.json b/package.json index c3842219a49..54554e3a408 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "woocommerce-rest-api", "title": "WooCommerce REST API", - "version": "1.0.5", + "version": "1.0.8", "homepage": "https://woocommerce.com/", "repository": { "type": "git", diff --git a/src/Controllers/Version2/class-wc-rest-products-v2-controller.php b/src/Controllers/Version2/class-wc-rest-products-v2-controller.php index d6942fc2826..f38ecb7dfb9 100644 --- a/src/Controllers/Version2/class-wc-rest-products-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-products-v2-controller.php @@ -419,9 +419,9 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller { $images[] = array( 'id' => 0, 'date_created' => wc_rest_prepare_date_response( current_time( 'mysql' ), false ), // Default to now. - 'date_created_gmt' => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ), // Default to now. + 'date_created_gmt' => wc_rest_prepare_date_response( time() ), // Default to now. 'date_modified' => wc_rest_prepare_date_response( current_time( 'mysql' ), false ), - 'date_modified_gmt' => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ), + 'date_modified_gmt' => wc_rest_prepare_date_response( time() ), 'src' => wc_placeholder_img_src(), 'name' => __( 'Placeholder', 'woocommerce-rest-api' ), 'alt' => __( 'Placeholder', 'woocommerce-rest-api' ), @@ -2115,7 +2115,7 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller { 'default' => 'any', 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce-rest-api' ), 'type' => 'string', - 'enum' => array_merge( array( 'any', 'future' ), array_keys( get_post_statuses() ) ), + 'enum' => array_merge( array( 'any', 'future', 'trash' ), array_keys( get_post_statuses() ) ), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ); diff --git a/src/Package.php b/src/Package.php index e524c51bcef..13c5ff30588 100644 --- a/src/Package.php +++ b/src/Package.php @@ -19,7 +19,7 @@ class Package { * * @var string */ - const VERSION = '1.0.7'; + const VERSION = '1.0.8'; /** * Init the package - load the REST API Server class. diff --git a/unit-tests/Bootstrap.php b/unit-tests/Bootstrap.php index d4658968ce8..b10c7f8eae5 100755 --- a/unit-tests/Bootstrap.php +++ b/unit-tests/Bootstrap.php @@ -113,11 +113,11 @@ class Bootstrap { require_once $this->wp_tests_dir . '/includes/bootstrap.php'; // WooCommerce Core Testing Framework. - require_once $this->wc_tests_dir . '/framework/class-wc-unit-test-factory.php'; - require_once $this->wc_tests_dir . '/framework/vendor/class-wp-test-spy-rest-server.php'; - require_once $this->wc_tests_dir . '/includes/wp-http-testcase.php'; - require_once $this->wc_tests_dir . '/framework/class-wc-unit-test-case.php'; - require_once $this->wc_tests_dir . '/framework/class-wc-rest-unit-test-case.php'; + require_once $this->wc_tests_dir . '/legacy/framework/class-wc-unit-test-factory.php'; + require_once $this->wc_tests_dir . '/legacy/framework/vendor/class-wp-test-spy-rest-server.php'; + require_once $this->wc_tests_dir . '/legacy/includes/wp-http-testcase.php'; + require_once $this->wc_tests_dir . '/legacy/framework/class-wc-unit-test-case.php'; + require_once $this->wc_tests_dir . '/legacy/framework/class-wc-rest-unit-test-case.php'; require_once $this->tests_dir . '/Helpers/AdminNotesHelper.php'; require_once $this->tests_dir . '/Helpers/CouponHelper.php'; diff --git a/unit-tests/Tests/Version2/shipping-zones.php b/unit-tests/Tests/Version2/shipping-zones.php index c6e2c4a102e..1d9ea5368d3 100644 --- a/unit-tests/Tests/Version2/shipping-zones.php +++ b/unit-tests/Tests/Version2/shipping-zones.php @@ -55,7 +55,7 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case { public function test_register_routes() { $routes = $this->server->get_routes(); $this->assertArrayHasKey( '/wc/v2/shipping/zones', $routes ); - $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d-]+)', $routes ); + $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)', $routes ); $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/locations', $routes ); $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/methods', $routes ); $this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P[\d]+)/methods/(?P[\d]+)', $routes ); diff --git a/unit-tests/Tests/Version3/functions.php b/unit-tests/Tests/Version3/functions.php index 3f6f96404de..3b3b27eb5c9 100644 --- a/unit-tests/Tests/Version3/functions.php +++ b/unit-tests/Tests/Version3/functions.php @@ -82,11 +82,11 @@ class WC_Tests_API_Functions extends WC_Unit_Test_Case { */ public function test_wc_rest_upload_image_from_url_should_return_error_when_invalid_image_is_passed() { // empty file. - $expected_error_message = 'Invalid image: File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.'; + $expected_error_message = 'Invalid image: File is empty.'; $result = wc_rest_upload_image_from_url( 'http://somedomain.com/invalid-image-1.png' ); $this->assertWPError( $result ); - $this->assertEquals( $expected_error_message, $result->get_error_message() ); + $this->assertStringStartsWith( $expected_error_message, $result->get_error_message() ); // unsupported mime type. $expected_error_message = 'Invalid image: Sorry, this file type is not permitted for security reasons.'; diff --git a/unit-tests/Tests/Version3/products.php b/unit-tests/Tests/Version3/products.php index 10f876d07ee..22351897134 100644 --- a/unit-tests/Tests/Version3/products.php +++ b/unit-tests/Tests/Version3/products.php @@ -58,6 +58,59 @@ class WC_Tests_API_Product extends WC_REST_Unit_Test_Case { $this->assertEquals( 'DUMMY EXTERNAL SKU', $products[1]['sku'] ); } + /** + * Test getting trashed products. + */ + public function test_get_trashed_products() { + wp_set_current_user( $this->user ); + $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); + $data_store = WC_Data_Store::load( 'product' ); + $data_store->delete( $product ); + $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); + $request->set_query_params( array( 'status' => 'trash' ) ); + $response = $this->server->dispatch( $request ); + $products = $response->get_data(); + + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 1, count( $products ) ); + $this->assertEquals( $product->get_name(), $products[0]['name'] ); + $this->assertEquals( $product->get_id(), $products[0]['id'] ); + } + + /** + * Trashed products should not be returned by default. + */ + public function test_get_trashed_products_not_returned_by_default() { + wp_set_current_user( $this->user ); + $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); + $data_store = WC_Data_Store::load( 'product' ); + $data_store->delete( $product ); + + $response = $this->server->dispatch( + new WP_REST_Request( 'GET', '/wc/v3/products' ) + ); + $products = $response->get_data(); + + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 0, count( $products ) ); + } + + /** + * Trashed product can be fetched directly. + */ + public function test_get_trashed_products_returned_by_id() { + wp_set_current_user( $this->user ); + $product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); + $data_store = WC_Data_Store::load( 'product' ); + $data_store->delete( $product ); + + $response = $this->server->dispatch( + new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) + ); + + $this->assertEquals( 200, $response->get_status() ); + } + /** * Test getting products without permission. * diff --git a/unit-tests/Tests/Version3/shipping-zones.php b/unit-tests/Tests/Version3/shipping-zones.php index 580391d1b33..a735357b41f 100644 --- a/unit-tests/Tests/Version3/shipping-zones.php +++ b/unit-tests/Tests/Version3/shipping-zones.php @@ -57,7 +57,7 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case { public function test_register_routes() { $routes = $this->server->get_routes(); $this->assertArrayHasKey( '/wc/v3/shipping/zones', $routes ); - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d-]+)', $routes ); + $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)', $routes ); $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)/locations', $routes ); $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)/methods', $routes ); $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P[\d]+)/methods/(?P[\d]+)', $routes ); diff --git a/woocommerce-rest-api.php b/woocommerce-rest-api.php index 296dac73707..10b7ea38a29 100644 --- a/woocommerce-rest-api.php +++ b/woocommerce-rest-api.php @@ -5,8 +5,8 @@ * Description: The WooCommerce core REST API, installed as a feature plugin for development and testing purposes. Requires WooCommerce 3.7+ and PHP 5.3+. * Author: Automattic * Author URI: https://woocommerce.com - * Version: 1.0.7 - * Requires PHP: 5.6 + * Version: 1.0.8 + * Requires PHP: 7.0 * License: GPLv3 * * @package Automattic/WooCommerce/RestApi @@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || exit; -if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) { +if ( version_compare( PHP_VERSION, '7.0.0', '<' ) ) { return; }