Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ protected function get_images( $product ) {
$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' ),
Expand Down Expand Up @@ -2115,7 +2115,7 @@ public function get_collection_params() {
'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',
);
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions unit-tests/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ protected function load_framework() {
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';
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/Tests/Version2/shipping-zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function create_shipping_zone( $name, $order = 0, $locations = array()
public function test_register_routes() {
$routes = $this->server->get_routes();
$this->assertArrayHasKey( '/wc/v2/shipping/zones', $routes );
$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<id>[\d-]+)', $routes );
$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<id>[\d]+)', $routes );
$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<id>[\d]+)/locations', $routes );
$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<zone_id>[\d]+)/methods', $routes );
$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', $routes );
Expand Down
4 changes: 2 additions & 2 deletions unit-tests/Tests/Version3/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public function test_wc_rest_upload_image_from_url_should_return_error_when_unab
*/
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.';
Expand Down
53 changes: 53 additions & 0 deletions unit-tests/Tests/Version3/products.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,59 @@ public function test_get_products() {
$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.
*
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/Tests/Version3/shipping-zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function create_shipping_zone( $name, $order = 0, $locations = array()
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]+)', $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 );
Expand Down
6 changes: 3 additions & 3 deletions woocommerce-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@

defined( 'ABSPATH' ) || exit;

if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) {
if ( version_compare( PHP_VERSION, '7.0.0', '<' ) ) {
return;
}

Expand Down