From 5d65448e9701869ed8bb0e3308a7872058b0311b Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 10 Jun 2019 13:39:46 +0100 Subject: [PATCH] Fixing tests --- .../Controllers/AbstractController.php | 2 +- .../Controllers/AbstractObjectsController.php | 14 +- .../Controllers/AbstractPostsController.php | 12 +- .../Controllers/AbstractTermsContoller.php | 6 +- src/RestApi/Version4/Controllers/Coupons.php | 6 +- .../Controllers/CustomerDownloads.php | 4 +- .../Version4/Controllers/Customers.php | 16 +- src/RestApi/Version4/Controllers/Data.php | 4 +- .../Version4/Controllers/Data/Continents.php | 8 +- .../Version4/Controllers/Data/Countries.php | 8 +- .../Version4/Controllers/Data/Currencies.php | 10 +- .../Version4/Controllers/Data/DownloadIPs.php | 6 +- .../Version4/Controllers/Leaderboards.php | 6 +- .../Version4/Controllers/NetworkOrders.php | 2 +- .../Version4/Controllers/OrderNotes.php | 14 +- .../Version4/Controllers/OrderRefunds.php | 10 +- src/RestApi/Version4/Controllers/Orders.php | 4 +- .../Version4/Controllers/PaymentGateways.php | 12 +- .../Controllers/ProductAttributeTerms.php | 4 +- .../Controllers/ProductAttributes.php | 10 +- .../Controllers/ProductCategories.php | 4 +- .../Version4/Controllers/ProductReviews.php | 2 +- .../Controllers/ProductShippingClasses.php | 4 +- .../Version4/Controllers/ProductTags.php | 4 +- .../Controllers/ProductVariations.php | 14 +- src/RestApi/Version4/Controllers/Products.php | 12 +- src/RestApi/Version4/Controllers/Reports.php | 4 +- .../Controllers/Reports/Categories.php | 4 +- .../Controllers/Reports/CouponStats.php | 4 +- .../Version4/Controllers/Reports/Coupons.php | 4 +- .../Controllers/Reports/CustomerStats.php | 4 +- .../Controllers/Reports/Customers.php | 4 +- .../Controllers/Reports/DownloadStats.php | 4 +- .../Controllers/Reports/Downloads.php | 4 +- .../Version4/Controllers/Reports/Import.php | 14 +- .../Controllers/Reports/OrderStats.php | 4 +- .../Version4/Controllers/Reports/Orders.php | 4 +- .../Reports/PerformanceIndicators.php | 4 +- .../Controllers/Reports/ProductStats.php | 4 +- .../Version4/Controllers/Reports/Products.php | 4 +- .../Controllers/Reports/RevenueStats.php | 4 +- .../Version4/Controllers/Reports/Stock.php | 4 +- .../Controllers/Reports/StockStats.php | 4 +- .../Version4/Controllers/Reports/TaxStats.php | 4 +- .../Version4/Controllers/Reports/Taxes.php | 4 +- .../Controllers/Reports/Variations.php | 4 +- src/RestApi/Version4/Controllers/Settings.php | 6 +- .../Version4/Controllers/SettingsOptions.php | 10 +- .../Version4/Controllers/ShippingMethods.php | 8 +- .../Controllers/ShippingZoneLocations.php | 6 +- .../Controllers/ShippingZoneMethods.php | 12 +- .../Version4/Controllers/ShippingZones.php | 8 +- .../Version4/Controllers/SystemStatus.php | 6 +- .../Controllers/SystemStatusTools.php | 8 +- .../Version4/Controllers/TaxClasses.php | 12 +- src/RestApi/Version4/Controllers/Taxes.php | 16 +- src/RestApi/Version4/Controllers/Webhooks.php | 18 +- unit-tests/AbstractReportsTest.php | 48 ++++ unit-tests/AbstractRestApiTest.php | 3 + unit-tests/Bootstrap.php | 24 +- unit-tests/Helpers/ReportsHelper.php | 27 -- ...es-terms.php => ProductAttributeTerms.php} | 10 +- ...s-attributes.php => ProductAttributes.php} | 10 +- ...s-categories.php => ProductCategories.php} | 10 +- unit-tests/Tests/Blocks/products.php | 10 +- unit-tests/Tests/Version4/Functions.php | 257 ------------------ unit-tests/Tests/Version4/Orders.php | 3 - .../Tests/Version4/Reports/Categories.php | 33 +-- unit-tests/Tests/Version4/Reports/Coupons.php | 30 +- .../Tests/Version4/Reports/CouponsStats.php | 27 +- .../Tests/Version4/Reports/CustomerStats.php | 29 +- .../Tests/Version4/Reports/Customers.php | 51 +--- .../Tests/Version4/Reports/DownloadStats.php | 29 +- .../Tests/Version4/Reports/Downloads.php | 27 +- unit-tests/Tests/Version4/Reports/Import.php | 7 +- .../Tests/Version4/Reports/OrderStats.php | 24 +- unit-tests/Tests/Version4/Reports/Orders.php | 30 +- .../Reports/PerformanceIndicators.php | 29 +- .../Tests/Version4/Reports/ProductStats.php | 28 +- .../Tests/Version4/Reports/Products.php | 30 +- .../Tests/Version4/Reports/RevenueStats.php | 20 +- unit-tests/Tests/Version4/Reports/Stock.php | 24 +- .../Tests/Version4/Reports/StockStats.php | 24 +- .../Tests/Version4/Reports/TaxStats.php | 29 +- unit-tests/Tests/Version4/Reports/Taxes.php | 33 +-- .../Tests/Version4/Reports/Variations.php | 30 +- unit-tests/Tests/Version4/Settings.php | 8 +- unit-tests/Tests/Version4/ShippingMethods.php | 2 +- unit-tests/Tests/Version4/ShippingZones.php | 6 +- unit-tests/Tests/Version4/SystemStatus.php | 8 +- 90 files changed, 374 insertions(+), 984 deletions(-) create mode 100644 unit-tests/AbstractReportsTest.php delete mode 100644 unit-tests/Helpers/ReportsHelper.php rename unit-tests/Tests/Blocks/{products-attributes-terms.php => ProductAttributeTerms.php} (91%) rename unit-tests/Tests/Blocks/{products-attributes.php => ProductAttributes.php} (91%) rename unit-tests/Tests/Blocks/{products-categories.php => ProductCategories.php} (92%) delete mode 100644 unit-tests/Tests/Version4/Functions.php diff --git a/src/RestApi/Version4/Controllers/AbstractController.php b/src/RestApi/Version4/Controllers/AbstractController.php index e08694599ae..8df2dce939e 100644 --- a/src/RestApi/Version4/Controllers/AbstractController.php +++ b/src/RestApi/Version4/Controllers/AbstractController.php @@ -119,7 +119,7 @@ abstract class AbstractController extends WP_REST_Controller { * Bulk create, update and delete items. * * @param \WP_REST_Request $request Full details about the request. - * @return array Of \WP_Error or WP_REST_Response. + * @return array Of \WP_Error or \WP_REST_Response. */ public function batch_items( $request ) { /** diff --git a/src/RestApi/Version4/Controllers/AbstractObjectsController.php b/src/RestApi/Version4/Controllers/AbstractObjectsController.php index ff1a4d9fd7e..790f26b5e58 100644 --- a/src/RestApi/Version4/Controllers/AbstractObjectsController.php +++ b/src/RestApi/Version4/Controllers/AbstractObjectsController.php @@ -96,7 +96,7 @@ abstract class AbstractObjectsController extends AbstractPostsController { * @since 3.0.0 * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. - * @return \WP_Error|WP_REST_Response Response object on success, or \WP_Error object on failure. + * @return \WP_Error|\WP_REST_Response Response object on success, or \WP_Error object on failure. */ protected function prepare_object_for_response( $object, $request ) { // translators: %s: Class method name. @@ -120,7 +120,7 @@ abstract class AbstractObjectsController extends AbstractPostsController { * Get a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error|\WP_REST_Response */ public function get_item( $request ) { $object = $this->get_object( (int) $request['id'] ); @@ -169,7 +169,7 @@ abstract class AbstractObjectsController extends AbstractPostsController { * Create a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { @@ -215,7 +215,7 @@ abstract class AbstractObjectsController extends AbstractPostsController { * Update a single post. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { $object = $this->get_object( (int) $request['id'] ); @@ -337,7 +337,7 @@ abstract class AbstractObjectsController extends AbstractPostsController { * Get a collection of posts. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $query_args = $this->prepare_objects_query( $request ); @@ -397,7 +397,7 @@ abstract class AbstractObjectsController extends AbstractPostsController { * Delete a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function delete_item( $request ) { $force = (bool) $request['force']; @@ -456,7 +456,7 @@ abstract class AbstractObjectsController extends AbstractPostsController { * Fires after a single object is deleted or trashed via the REST API. * * @param WC_Data $object The deleted or trashed object. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); diff --git a/src/RestApi/Version4/Controllers/AbstractPostsController.php b/src/RestApi/Version4/Controllers/AbstractPostsController.php index d6943abf056..b6609885d54 100644 --- a/src/RestApi/Version4/Controllers/AbstractPostsController.php +++ b/src/RestApi/Version4/Controllers/AbstractPostsController.php @@ -132,7 +132,7 @@ abstract class AbstractPostsController extends AbstractController { * Get a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $id = (int) $request['id']; @@ -158,7 +158,7 @@ abstract class AbstractPostsController extends AbstractController { * Create a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { @@ -239,7 +239,7 @@ abstract class AbstractPostsController extends AbstractController { * Update a single post. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { $id = (int) $request['id']; @@ -293,7 +293,7 @@ abstract class AbstractPostsController extends AbstractController { * Get a collection of posts. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $args = array(); @@ -401,7 +401,7 @@ abstract class AbstractPostsController extends AbstractController { * Delete a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function delete_item( $request ) { $id = (int) $request['id']; @@ -462,7 +462,7 @@ abstract class AbstractPostsController extends AbstractController { * Fires after a single item is deleted or trashed via the REST API. * * @param object $post The deleted or trashed item. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request ); diff --git a/src/RestApi/Version4/Controllers/AbstractTermsContoller.php b/src/RestApi/Version4/Controllers/AbstractTermsContoller.php index 7d431443c3a..513005002f7 100644 --- a/src/RestApi/Version4/Controllers/AbstractTermsContoller.php +++ b/src/RestApi/Version4/Controllers/AbstractTermsContoller.php @@ -266,7 +266,7 @@ abstract class AbstractTermsContoller extends AbstractController { * Get terms associated with a taxonomy. * * @param \WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function get_items( $request ) { $taxonomy = $this->get_taxonomy( $request ); @@ -530,7 +530,7 @@ abstract class AbstractTermsContoller extends AbstractController { * Delete a single term from a taxonomy. * * @param \WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function delete_item( $request ) { $taxonomy = $this->get_taxonomy( $request ); @@ -562,7 +562,7 @@ abstract class AbstractTermsContoller extends AbstractController { * Fires after a single term is deleted via the REST API. * * @param WP_Term $term The deleted term. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( "woocommerce_rest_delete_{$taxonomy}", $term, $response, $request ); diff --git a/src/RestApi/Version4/Controllers/Coupons.php b/src/RestApi/Version4/Controllers/Coupons.php index ceb62d7766a..f4c4c9b13ac 100644 --- a/src/RestApi/Version4/Controllers/Coupons.php +++ b/src/RestApi/Version4/Controllers/Coupons.php @@ -200,7 +200,7 @@ class Coupons extends AbstractObjectsController { * @since 3.0.0 * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_object_for_response( $object, $request ) { $data = $this->get_formatted_item_data( $object ); @@ -216,7 +216,7 @@ class Coupons extends AbstractObjectsController { * The dynamic portion of the hook name, $this->post_type, * refers to object type being prepared for the response. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. */ @@ -553,7 +553,7 @@ class Coupons extends AbstractObjectsController { * Get a collection of posts and add the code search option to \WP_Query. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { add_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10, 2 ); diff --git a/src/RestApi/Version4/Controllers/CustomerDownloads.php b/src/RestApi/Version4/Controllers/CustomerDownloads.php index 24625e464c4..0dcb39cf469 100644 --- a/src/RestApi/Version4/Controllers/CustomerDownloads.php +++ b/src/RestApi/Version4/Controllers/CustomerDownloads.php @@ -93,7 +93,7 @@ class CustomerDownloads extends AbstractController { * * @param stdClass $download Download object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $download, $request ) { $data = array( @@ -122,7 +122,7 @@ class CustomerDownloads extends AbstractController { /** * Filter customer download data returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param stdClass $download Download object used to create response. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/Customers.php b/src/RestApi/Version4/Controllers/Customers.php index e571d175b1f..616bc60caa9 100644 --- a/src/RestApi/Version4/Controllers/Customers.php +++ b/src/RestApi/Version4/Controllers/Customers.php @@ -268,7 +268,7 @@ class Customers extends AbstractController { * Get all customers. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $prepared_args = array(); @@ -366,7 +366,7 @@ class Customers extends AbstractController { * * @throws WC_REST_Exception On invalid params. * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { try { @@ -420,7 +420,7 @@ class Customers extends AbstractController { * Get a single customer. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $id = (int) $request['id']; @@ -441,7 +441,7 @@ class Customers extends AbstractController { * * @throws WC_REST_Exception On invalid params. * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { try { @@ -502,7 +502,7 @@ class Customers extends AbstractController { * Delete a single customer. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function delete_item( $request ) { $id = (int) $request['id']; @@ -547,7 +547,7 @@ class Customers extends AbstractController { * Fires after a customer is deleted via the REST API. * * @param WP_User $user_data User data. - * @param WP_REST_Response $response The response returned from the API. + * @param \WP_REST_Response $response The response returned from the API. * @param \WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_customer', $user_data, $response, $request ); @@ -560,7 +560,7 @@ class Customers extends AbstractController { * * @param WP_User $user_data User object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $user_data, $request ) { $customer = new \WC_Customer( $user_data->ID ); @@ -574,7 +574,7 @@ class Customers extends AbstractController { /** * Filter customer data returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WP_User $user_data User object used to create response. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/Data.php b/src/RestApi/Version4/Controllers/Data.php index 129d7bfe2b7..bb91d3fa18a 100644 --- a/src/RestApi/Version4/Controllers/Data.php +++ b/src/RestApi/Version4/Controllers/Data.php @@ -77,7 +77,7 @@ class Data extends AbstractController { * * @since 3.5.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $data = array(); @@ -113,7 +113,7 @@ class Data extends AbstractController { * * @param stdClass $resource Resource data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $resource, $request ) { $data = array( diff --git a/src/RestApi/Version4/Controllers/Data/Continents.php b/src/RestApi/Version4/Controllers/Data/Continents.php index 6790afdb10a..995196df4e5 100644 --- a/src/RestApi/Version4/Controllers/Data/Continents.php +++ b/src/RestApi/Version4/Controllers/Data/Continents.php @@ -155,7 +155,7 @@ class Continents extends DataController { * * @since 3.5.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $continents = WC()->countries->get_continents(); @@ -175,7 +175,7 @@ class Continents extends DataController { * * @since 3.5.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $data = $this->get_continent( strtoupper( $request['location'] ), $request ); @@ -191,7 +191,7 @@ class Continents extends DataController { * @since 3.5.0 * @param object $item Data object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $data = $this->add_additional_fields_to_object( $item, $request ); @@ -205,7 +205,7 @@ class Continents extends DataController { * * Allows modification of the loction data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param array $item The original list of continent(s), countries, and states. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Data/Countries.php b/src/RestApi/Version4/Controllers/Data/Countries.php index a7d10eff071..8a76ad37789 100644 --- a/src/RestApi/Version4/Controllers/Data/Countries.php +++ b/src/RestApi/Version4/Controllers/Data/Countries.php @@ -102,7 +102,7 @@ class Countries extends DataController { * * @since 3.5.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $countries = WC()->countries->get_countries(); @@ -122,7 +122,7 @@ class Countries extends DataController { * * @since 3.5.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $data = $this->get_country( strtoupper( $request['location'] ), $request ); @@ -138,7 +138,7 @@ class Countries extends DataController { * @since 3.5.0 * @param object $item Data object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $data = $this->add_additional_fields_to_object( $item, $request ); @@ -152,7 +152,7 @@ class Countries extends DataController { * * Allows modification of the loction data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param array $data The original country's states list. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Data/Currencies.php b/src/RestApi/Version4/Controllers/Data/Currencies.php index 0634c400c27..f3e5acaa54d 100644 --- a/src/RestApi/Version4/Controllers/Data/Currencies.php +++ b/src/RestApi/Version4/Controllers/Data/Currencies.php @@ -101,7 +101,7 @@ class Currencies extends DataController { * Return the list of currencies. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $currencies = get_woocommerce_currencies(); @@ -118,7 +118,7 @@ class Currencies extends DataController { * Return information for a specific currency. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $data = $this->get_currency( strtoupper( $request['currency'] ), $request ); @@ -132,7 +132,7 @@ class Currencies extends DataController { * Return information for the current site currency. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_current_item( $request ) { $currency = get_option( 'woocommerce_currency' ); @@ -144,7 +144,7 @@ class Currencies extends DataController { * * @param object $item Data object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $data = $this->add_additional_fields_to_object( $item, $request ); @@ -156,7 +156,7 @@ class Currencies extends DataController { /** * Filter currency returned from the API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param array $item Currency data. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Data/DownloadIPs.php b/src/RestApi/Version4/Controllers/Data/DownloadIPs.php index 3279cc46c04..8e7637d4e67 100644 --- a/src/RestApi/Version4/Controllers/Data/DownloadIPs.php +++ b/src/RestApi/Version4/Controllers/Data/DownloadIPs.php @@ -50,7 +50,7 @@ class DownloadIPs extends DataController { * * @since 3.5.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { global $wpdb; @@ -86,7 +86,7 @@ class DownloadIPs extends DataController { * @since 3.5.0 * @param object $item Data object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $data = $this->add_additional_fields_to_object( $item, $request ); @@ -98,7 +98,7 @@ class DownloadIPs extends DataController { /** * Filter the list returned from the API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param array $item The original item. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Leaderboards.php b/src/RestApi/Version4/Controllers/Leaderboards.php index 4b01bc9ad36..7cc3b2d99b2 100644 --- a/src/RestApi/Version4/Controllers/Leaderboards.php +++ b/src/RestApi/Version4/Controllers/Leaderboards.php @@ -347,7 +347,7 @@ class Leaderboards extends Data { * Return all leaderboards. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $persisted_query = json_decode( $request['persisted_query'], true ); @@ -402,7 +402,7 @@ class Leaderboards extends Data { * * @param object $item Data object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $data = $this->add_additional_fields_to_object( $item, $request ); @@ -412,7 +412,7 @@ class Leaderboards extends Data { /** * Filter the list returned from the API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param array $item The original item. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/NetworkOrders.php b/src/RestApi/Version4/Controllers/NetworkOrders.php index fa23c096d42..5c3e5cde7ef 100644 --- a/src/RestApi/Version4/Controllers/NetworkOrders.php +++ b/src/RestApi/Version4/Controllers/NetworkOrders.php @@ -105,7 +105,7 @@ class NetworkOrders extends Orders { * * @param \WP_REST_Request $request Full details about the request. * - * @return WP_REST_Response + * @return \WP_REST_Response */ public function network_orders( $request ) { $blog_id = $request->get_param( 'blog_id' ); diff --git a/src/RestApi/Version4/Controllers/OrderNotes.php b/src/RestApi/Version4/Controllers/OrderNotes.php index 0b53a46fdd9..27da4c0ec71 100644 --- a/src/RestApi/Version4/Controllers/OrderNotes.php +++ b/src/RestApi/Version4/Controllers/OrderNotes.php @@ -225,7 +225,7 @@ class OrderNotes extends AbstractController { * Create a single order note. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { @@ -271,7 +271,7 @@ class OrderNotes extends AbstractController { * Get a single order note. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $id = (int) $request['id']; @@ -297,7 +297,7 @@ class OrderNotes extends AbstractController { * Delete a single order note. * * @param \WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function delete_item( $request ) { $id = (int) $request['id']; @@ -328,7 +328,7 @@ class OrderNotes extends AbstractController { return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) ); } - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -340,7 +340,7 @@ class OrderNotes extends AbstractController { * Fires after a order note is deleted or trashed via the REST API. * * @param WP_Comment $note The deleted or trashed order note. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); @@ -353,7 +353,7 @@ class OrderNotes extends AbstractController { * * @param WP_Comment $note Order note object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $note, $request ) { $data = array( @@ -377,7 +377,7 @@ class OrderNotes extends AbstractController { /** * Filter order note object returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WP_Comment $note Order note object used to create response. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/OrderRefunds.php b/src/RestApi/Version4/Controllers/OrderRefunds.php index 54030afe7b2..7c7fdcffbaa 100644 --- a/src/RestApi/Version4/Controllers/OrderRefunds.php +++ b/src/RestApi/Version4/Controllers/OrderRefunds.php @@ -177,7 +177,7 @@ class OrderRefunds extends Orders { * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. * - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function prepare_object_for_response( $object, $request ) { $this->request = $request; @@ -208,7 +208,7 @@ class OrderRefunds extends Orders { * The dynamic portion of the hook name, $this->post_type, * refers to object type being prepared for the response. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. */ @@ -221,7 +221,7 @@ class OrderRefunds extends Orders { * @param WP_Post $post Post object. * @param \WP_REST_Request $request Request object. * - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function prepare_item_for_response( $post, $request ) { $order = wc_get_order( (int) $request['order_id'] ); @@ -326,7 +326,7 @@ class OrderRefunds extends Orders { * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being * prepared for the response. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WP_Post $post Post object. * @param \WP_REST_Request $request Request object. */ @@ -377,7 +377,7 @@ class OrderRefunds extends Orders { * Create a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { diff --git a/src/RestApi/Version4/Controllers/Orders.php b/src/RestApi/Version4/Controllers/Orders.php index 24ae9a4b24a..33497fe8d57 100644 --- a/src/RestApi/Version4/Controllers/Orders.php +++ b/src/RestApi/Version4/Controllers/Orders.php @@ -293,7 +293,7 @@ class Orders extends AbstractObjectsController { * @since 3.0.0 * @param \WC_Data $object Object data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_object_for_response( $object, $request ) { $this->request = $request; @@ -311,7 +311,7 @@ class Orders extends AbstractObjectsController { * The dynamic portion of the hook name, $this->post_type, * refers to object type being prepared for the response. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/PaymentGateways.php b/src/RestApi/Version4/Controllers/PaymentGateways.php index 50645ead356..5a1b683820a 100644 --- a/src/RestApi/Version4/Controllers/PaymentGateways.php +++ b/src/RestApi/Version4/Controllers/PaymentGateways.php @@ -114,7 +114,7 @@ class PaymentGateways extends AbstractController { * Get payment gateways. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $payment_gateways = WC()->payment_gateways->payment_gateways(); @@ -132,7 +132,7 @@ class PaymentGateways extends AbstractController { * Get a single payment gateway. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function get_item( $request ) { $gateway = $this->get_gateway( $request ); @@ -149,7 +149,7 @@ class PaymentGateways extends AbstractController { * Update A Single Payment Method. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function update_item( $request ) { $gateway = $this->get_gateway( $request ); @@ -223,7 +223,7 @@ class PaymentGateways extends AbstractController { * Get a gateway based on the current request object. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|null + * @return \WP_REST_Response|null */ public function get_gateway( $request ) { $gateway = null; @@ -243,7 +243,7 @@ class PaymentGateways extends AbstractController { * * @param WC_Payment_Gateway $gateway Payment gateway object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $gateway, $request ) { $order = (array) get_option( 'woocommerce_gateway_order' ); @@ -269,7 +269,7 @@ class PaymentGateways extends AbstractController { /** * Filter payment gateway objects returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Payment_Gateway $gateway Payment gateway object. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/ProductAttributeTerms.php b/src/RestApi/Version4/Controllers/ProductAttributeTerms.php index a5514d72732..bfa6714bef4 100644 --- a/src/RestApi/Version4/Controllers/ProductAttributeTerms.php +++ b/src/RestApi/Version4/Controllers/ProductAttributeTerms.php @@ -135,7 +135,7 @@ class ProductAttributeTerms extends AbstractTermsContoller { * * @param WP_Term $item Term object. * @param \WP_REST_Request $request Request params. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $item, $request ) { // Get term order. @@ -163,7 +163,7 @@ class ProductAttributeTerms extends AbstractTermsContoller { * * Allows modification of the term data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $item The original term object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/ProductAttributes.php b/src/RestApi/Version4/Controllers/ProductAttributes.php index 27c8486ca49..cea3491f897 100644 --- a/src/RestApi/Version4/Controllers/ProductAttributes.php +++ b/src/RestApi/Version4/Controllers/ProductAttributes.php @@ -357,7 +357,7 @@ class ProductAttributes extends AbstractController { * Delete a single attribute. * * @param \WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function delete_item( $request ) { $force = isset( $request['force'] ) ? (bool) $request['force'] : false; @@ -381,7 +381,7 @@ class ProductAttributes extends AbstractController { return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); } - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -393,7 +393,7 @@ class ProductAttributes extends AbstractController { * Fires after a single attribute is deleted via the REST API. * * @param stdObject $attribute The deleted attribute. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request ); @@ -406,7 +406,7 @@ class ProductAttributes extends AbstractController { * * @param obj $item Term object. * @param \WP_REST_Request $request Request params. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $item, $request ) { $data = array( @@ -431,7 +431,7 @@ class ProductAttributes extends AbstractController { * * Allows modification of the product attribute data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $item The original attribute object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/ProductCategories.php b/src/RestApi/Version4/Controllers/ProductCategories.php index cdcaaa5920b..6e7ff08fd3b 100644 --- a/src/RestApi/Version4/Controllers/ProductCategories.php +++ b/src/RestApi/Version4/Controllers/ProductCategories.php @@ -35,7 +35,7 @@ class ProductCategories extends AbstractTermsContoller { * * @param WP_Term $item Term object. * @param \WP_REST_Request $request Request instance. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $item, $request ) { // Get category display type. @@ -86,7 +86,7 @@ class ProductCategories extends AbstractTermsContoller { * * Allows modification of the term data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $item The original term object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/ProductReviews.php b/src/RestApi/Version4/Controllers/ProductReviews.php index 351ded63a1c..7a52f09481a 100644 --- a/src/RestApi/Version4/Controllers/ProductReviews.php +++ b/src/RestApi/Version4/Controllers/ProductReviews.php @@ -726,7 +726,7 @@ class ProductReviews extends AbstractController { * Filter product reviews object returned from the REST API. * * @param \WP_REST_Response $response The response object. - * @param WP_Comment $review Product review object used to create response. + * @param \WP_Comment $review Product review object used to create response. * @param \WP_REST_Request $request Request object. */ return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request ); diff --git a/src/RestApi/Version4/Controllers/ProductShippingClasses.php b/src/RestApi/Version4/Controllers/ProductShippingClasses.php index c39c8536444..d9bc0c8c2de 100644 --- a/src/RestApi/Version4/Controllers/ProductShippingClasses.php +++ b/src/RestApi/Version4/Controllers/ProductShippingClasses.php @@ -35,7 +35,7 @@ class ProductShippingClasses extends AbstractTermsContoller { * * @param obj $item Term object. * @param \WP_REST_Request $request Request params. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $item, $request ) { $data = array( @@ -59,7 +59,7 @@ class ProductShippingClasses extends AbstractTermsContoller { * * Allows modification of the term data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $item The original term object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/ProductTags.php b/src/RestApi/Version4/Controllers/ProductTags.php index 64137497547..a1491bd3c34 100644 --- a/src/RestApi/Version4/Controllers/ProductTags.php +++ b/src/RestApi/Version4/Controllers/ProductTags.php @@ -35,7 +35,7 @@ class ProductTags extends AbstractTermsContoller { * * @param obj $item Term object. * @param \WP_REST_Request $request Request params. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $item, $request ) { $data = array( @@ -59,7 +59,7 @@ class ProductTags extends AbstractTermsContoller { * * Allows modification of the term data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $item The original term object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/ProductVariations.php b/src/RestApi/Version4/Controllers/ProductVariations.php index 6e867f4ecfb..762c0c5e19d 100644 --- a/src/RestApi/Version4/Controllers/ProductVariations.php +++ b/src/RestApi/Version4/Controllers/ProductVariations.php @@ -174,7 +174,7 @@ class ProductVariations extends Products { * * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_object_for_response( $object, $request ) { $data = array( @@ -238,7 +238,7 @@ class ProductVariations extends Products { * The dynamic portion of the hook name, $this->post_type, * refers to object type being prepared for the response. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. */ @@ -639,7 +639,7 @@ class ProductVariations extends Products { * * @param \WP_REST_Request $request Full details about the request. * - * @return bool|\WP_Error|WP_REST_Response + * @return bool|\WP_Error\WP_REST_Response */ public function delete_item( $request ) { $force = (bool) $request['force']; @@ -684,7 +684,7 @@ class ProductVariations extends Products { $object->delete( true ); $result = 0 === $object->get_id(); - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -733,7 +733,7 @@ class ProductVariations extends Products { * Fires after a single object is deleted or trashed via the REST API. * * @param WC_Data $object The deleted or trashed object. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); @@ -746,7 +746,7 @@ class ProductVariations extends Products { * * @since 3.0.0 * @param \WP_REST_Request $request Full details about the request. - * @return array Of \WP_Error or WP_REST_Response. + * @return array Of \WP_Error or \WP_REST_Response. */ public function batch_items( $request ) { $items = array_filter( $request->get_params() ); @@ -1210,7 +1210,7 @@ class ProductVariations extends Products { * Get a collection of posts and add the post title filter option to \WP_Query. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { add_filter( 'posts_where', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_filter' ), 10, 2 ); diff --git a/src/RestApi/Version4/Controllers/Products.php b/src/RestApi/Version4/Controllers/Products.php index 18b581426f5..464a0b9c7b8 100644 --- a/src/RestApi/Version4/Controllers/Products.php +++ b/src/RestApi/Version4/Controllers/Products.php @@ -149,7 +149,7 @@ class Products extends AbstractObjectsController { * @param \WP_REST_Request $request Request object. * * @since 3.0.0 - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_object_for_response( $object, $request ) { $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; @@ -176,7 +176,7 @@ class Products extends AbstractObjectsController { * The dynamic portion of the hook name, $this->post_type, * refers to object type being prepared for the response. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Data $object Object data. * @param \WP_REST_Request $request Request object. */ @@ -597,7 +597,7 @@ class Products extends AbstractObjectsController { * Get a collection of posts and add the post title filter option to \WP_Query. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 ); @@ -1440,7 +1440,7 @@ class Products extends AbstractObjectsController { * * @param \WP_REST_Request $request Full details about the request. * - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function delete_item( $request ) { $id = (int) $request['id']; @@ -1500,7 +1500,7 @@ class Products extends AbstractObjectsController { $object->delete( true ); $result = 0 === $object->get_id(); - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -1555,7 +1555,7 @@ class Products extends AbstractObjectsController { * Fires after a single object is deleted or trashed via the REST API. * * @param WC_Data $object The deleted or trashed object. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); diff --git a/src/RestApi/Version4/Controllers/Reports.php b/src/RestApi/Version4/Controllers/Reports.php index 284ff185d14..b187692b9d8 100644 --- a/src/RestApi/Version4/Controllers/Reports.php +++ b/src/RestApi/Version4/Controllers/Reports.php @@ -191,7 +191,7 @@ class Reports extends AbstractController { * * @param stdClass $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = array( @@ -225,7 +225,7 @@ class Reports extends AbstractController { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Categories.php b/src/RestApi/Version4/Controllers/Reports/Categories.php index 7929eb8e936..5d69e501b42 100644 --- a/src/RestApi/Version4/Controllers/Reports/Categories.php +++ b/src/RestApi/Version4/Controllers/Reports/Categories.php @@ -103,7 +103,7 @@ class Categories extends Reports { * * @param stdClass $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -121,7 +121,7 @@ class Categories extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/CouponStats.php b/src/RestApi/Version4/Controllers/Reports/CouponStats.php index b8c40152a71..279ba053350 100644 --- a/src/RestApi/Version4/Controllers/Reports/CouponStats.php +++ b/src/RestApi/Version4/Controllers/Reports/CouponStats.php @@ -100,7 +100,7 @@ class CouponStats extends Reports { * * @param stdClass $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = get_object_vars( $report ); @@ -117,7 +117,7 @@ class CouponStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Coupons.php b/src/RestApi/Version4/Controllers/Reports/Coupons.php index 59dd8ac40b4..b4567d8168b 100644 --- a/src/RestApi/Version4/Controllers/Reports/Coupons.php +++ b/src/RestApi/Version4/Controllers/Reports/Coupons.php @@ -91,7 +91,7 @@ class Coupons extends Reports { * * @param stdClass $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -109,7 +109,7 @@ class Coupons extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/CustomerStats.php b/src/RestApi/Version4/Controllers/Reports/CustomerStats.php index be1c23cda27..def364100b1 100644 --- a/src/RestApi/Version4/Controllers/Reports/CustomerStats.php +++ b/src/RestApi/Version4/Controllers/Reports/CustomerStats.php @@ -88,7 +88,7 @@ class CustomerStats extends Reports { * * @param Array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -105,7 +105,7 @@ class CustomerStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Customers.php b/src/RestApi/Version4/Controllers/Reports/Customers.php index 7177a7b7b4f..e96c3804a03 100644 --- a/src/RestApi/Version4/Controllers/Reports/Customers.php +++ b/src/RestApi/Version4/Controllers/Reports/Customers.php @@ -120,7 +120,7 @@ class Customers extends Reports { * * @param array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; @@ -139,7 +139,7 @@ class Customers extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/DownloadStats.php b/src/RestApi/Version4/Controllers/Reports/DownloadStats.php index e0811dd72e9..45e23d85e6f 100644 --- a/src/RestApi/Version4/Controllers/Reports/DownloadStats.php +++ b/src/RestApi/Version4/Controllers/Reports/DownloadStats.php @@ -103,7 +103,7 @@ class DownloadStats extends Reports { * * @param Array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -120,7 +120,7 @@ class DownloadStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Downloads.php b/src/RestApi/Version4/Controllers/Reports/Downloads.php index e1b3bf61230..dff4cc63491 100644 --- a/src/RestApi/Version4/Controllers/Reports/Downloads.php +++ b/src/RestApi/Version4/Controllers/Reports/Downloads.php @@ -80,7 +80,7 @@ class Downloads extends Reports { * * @param Array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -112,7 +112,7 @@ class Downloads extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Import.php b/src/RestApi/Version4/Controllers/Reports/Import.php index 57c5dc5a544..10e168e3a53 100644 --- a/src/RestApi/Version4/Controllers/Reports/Import.php +++ b/src/RestApi/Version4/Controllers/Reports/Import.php @@ -110,7 +110,7 @@ class Import extends Reports { * Import data based on user request params. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function import_items( $request ) { $query_args = $this->prepare_objects_query( $request ); @@ -153,7 +153,7 @@ class Import extends Reports { * * @param object $item Data object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $data = $this->add_additional_fields_to_object( $item, $request ); @@ -163,7 +163,7 @@ class Import extends Reports { /** * Filter the list returned from the API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param array $item The original item. * @param \WP_REST_Request $request Request used to generate the response. */ @@ -227,7 +227,7 @@ class Import extends Reports { * Cancel all queued import actions. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function cancel_import( $request ) { \WC_Admin_Reports_Sync::clear_queued_actions(); @@ -247,7 +247,7 @@ class Import extends Reports { * Delete all imported items. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function delete_imported_items( $request ) { $delete = \WC_Admin_Reports_Sync::delete_report_data(); @@ -274,7 +274,7 @@ class Import extends Reports { * Get the status of the current import. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_import_status( $request ) { $result = array( @@ -296,7 +296,7 @@ class Import extends Reports { * Get the total orders and customers based on user supplied params. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_import_totals( $request ) { $query_args = $this->prepare_objects_query( $request ); diff --git a/src/RestApi/Version4/Controllers/Reports/OrderStats.php b/src/RestApi/Version4/Controllers/Reports/OrderStats.php index faf23e7a79d..1b0224d2026 100644 --- a/src/RestApi/Version4/Controllers/Reports/OrderStats.php +++ b/src/RestApi/Version4/Controllers/Reports/OrderStats.php @@ -110,7 +110,7 @@ class OrderStats extends Reports { * * @param Array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -127,7 +127,7 @@ class OrderStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Orders.php b/src/RestApi/Version4/Controllers/Reports/Orders.php index e0bdb1f1f8a..622b4a18763 100644 --- a/src/RestApi/Version4/Controllers/Reports/Orders.php +++ b/src/RestApi/Version4/Controllers/Reports/Orders.php @@ -99,7 +99,7 @@ class Orders extends Reports { * * @param stdClass $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -117,7 +117,7 @@ class Orders extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php b/src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php index 88e485eab09..7c4dae39174 100644 --- a/src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php +++ b/src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php @@ -323,7 +323,7 @@ class PerformanceIndicators extends Reports { * * @param stdClass $stat_data Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $stat_data, $request ) { $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; @@ -340,7 +340,7 @@ class PerformanceIndicators extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/ProductStats.php b/src/RestApi/Version4/Controllers/Reports/ProductStats.php index 19c7e5e40a3..2794e7e56d9 100644 --- a/src/RestApi/Version4/Controllers/Reports/ProductStats.php +++ b/src/RestApi/Version4/Controllers/Reports/ProductStats.php @@ -115,7 +115,7 @@ class ProductStats extends Reports { * * @param Array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -132,7 +132,7 @@ class ProductStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Products.php b/src/RestApi/Version4/Controllers/Reports/Products.php index 299687f04f1..ba420c494ec 100644 --- a/src/RestApi/Version4/Controllers/Reports/Products.php +++ b/src/RestApi/Version4/Controllers/Reports/Products.php @@ -93,7 +93,7 @@ class Products extends Reports { * * @param Array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -111,7 +111,7 @@ class Products extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/RevenueStats.php b/src/RestApi/Version4/Controllers/Reports/RevenueStats.php index 38a586e4dff..8d58294c2e4 100644 --- a/src/RestApi/Version4/Controllers/Reports/RevenueStats.php +++ b/src/RestApi/Version4/Controllers/Reports/RevenueStats.php @@ -99,7 +99,7 @@ class RevenueStats extends Reports { * * @param Array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -116,7 +116,7 @@ class RevenueStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Stock.php b/src/RestApi/Version4/Controllers/Reports/Stock.php index 4967d31aaba..6bcaeb4d4cd 100644 --- a/src/RestApi/Version4/Controllers/Reports/Stock.php +++ b/src/RestApi/Version4/Controllers/Reports/Stock.php @@ -183,7 +183,7 @@ class Stock extends Reports { * * @param WC_Product $product Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $product, $request ) { $data = array( @@ -209,7 +209,7 @@ class Stock extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Product $product The original product object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/StockStats.php b/src/RestApi/Version4/Controllers/Reports/StockStats.php index df3b371c1cb..db704677959 100644 --- a/src/RestApi/Version4/Controllers/Reports/StockStats.php +++ b/src/RestApi/Version4/Controllers/Reports/StockStats.php @@ -45,7 +45,7 @@ class StockStats extends Reports { * * @param WC_Product $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -62,7 +62,7 @@ class StockStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Product $product The original bject. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/TaxStats.php b/src/RestApi/Version4/Controllers/Reports/TaxStats.php index 3b15000dacf..1c816c4d857 100644 --- a/src/RestApi/Version4/Controllers/Reports/TaxStats.php +++ b/src/RestApi/Version4/Controllers/Reports/TaxStats.php @@ -126,7 +126,7 @@ class TaxStats extends Reports { * * @param stdClass $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = get_object_vars( $report ); @@ -143,7 +143,7 @@ class TaxStats extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Taxes.php b/src/RestApi/Version4/Controllers/Reports/Taxes.php index 4c59faf3838..9ebc4e29d89 100644 --- a/src/RestApi/Version4/Controllers/Reports/Taxes.php +++ b/src/RestApi/Version4/Controllers/Reports/Taxes.php @@ -91,7 +91,7 @@ class Taxes extends Reports { * * @param stdClass $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; @@ -107,7 +107,7 @@ class Taxes extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Reports/Variations.php b/src/RestApi/Version4/Controllers/Reports/Variations.php index 3d162c472c5..988e40f761e 100644 --- a/src/RestApi/Version4/Controllers/Reports/Variations.php +++ b/src/RestApi/Version4/Controllers/Reports/Variations.php @@ -93,7 +93,7 @@ class Variations extends Reports { * * @param array $report Report data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $report, $request ) { $data = $report; @@ -111,7 +111,7 @@ class Variations extends Reports { * * Allows modification of the report data right before it is returned. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param object $report The original report object. * @param \WP_REST_Request $request Request used to generate the response. */ diff --git a/src/RestApi/Version4/Controllers/Settings.php b/src/RestApi/Version4/Controllers/Settings.php index 28e43e29d54..68aca43c5be 100644 --- a/src/RestApi/Version4/Controllers/Settings.php +++ b/src/RestApi/Version4/Controllers/Settings.php @@ -75,7 +75,7 @@ class Settings extends AbstractController { * Update a setting. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { $options_controller = new \WC_REST_Setting_Options_Controller(); @@ -89,7 +89,7 @@ class Settings extends AbstractController { * * @since 3.0.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $groups = apply_filters( 'woocommerce_settings_groups', array() ); @@ -145,7 +145,7 @@ class Settings extends AbstractController { * @since 3.0.0 * @param array $item Group object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $context = empty( $request['context'] ) ? 'view' : $request['context']; diff --git a/src/RestApi/Version4/Controllers/SettingsOptions.php b/src/RestApi/Version4/Controllers/SettingsOptions.php index f4bbcacde72..20f71ed9db4 100644 --- a/src/RestApi/Version4/Controllers/SettingsOptions.php +++ b/src/RestApi/Version4/Controllers/SettingsOptions.php @@ -106,7 +106,7 @@ class SettingsOptions extends AbstractController { * * @since 3.0.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $setting = $this->get_setting( $request['group_id'], $request['id'] ); @@ -125,7 +125,7 @@ class SettingsOptions extends AbstractController { * * @since 3.0.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $settings = $this->get_group_settings( $request['group_id'] ); @@ -277,7 +277,7 @@ class SettingsOptions extends AbstractController { * * @since 3.0.0 * @param \WP_REST_Request $request Full details about the request. - * @return array Of \WP_Error or WP_REST_Response. + * @return array Of \WP_Error or \WP_REST_Response. */ public function batch_items( $request ) { // Get the request params. @@ -304,7 +304,7 @@ class SettingsOptions extends AbstractController { * * @since 3.0.0 * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { $setting = $this->get_setting( $request['group_id'], $request['id'] ); @@ -347,7 +347,7 @@ class SettingsOptions extends AbstractController { * @since 3.0.0 * @param object $item Setting object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { unset( $item['option_key'] ); diff --git a/src/RestApi/Version4/Controllers/ShippingMethods.php b/src/RestApi/Version4/Controllers/ShippingMethods.php index 3f8174386f0..529c2f92d53 100644 --- a/src/RestApi/Version4/Controllers/ShippingMethods.php +++ b/src/RestApi/Version4/Controllers/ShippingMethods.php @@ -95,7 +95,7 @@ class ShippingMethods extends AbstractController { * Get shipping methods. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $wc_shipping = \WC_Shipping::instance(); @@ -112,7 +112,7 @@ class ShippingMethods extends AbstractController { * Get a single Shipping Method. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function get_item( $request ) { $wc_shipping = \WC_Shipping::instance(); @@ -132,7 +132,7 @@ class ShippingMethods extends AbstractController { * * @param WC_Shipping_Method $method Shipping method object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $method, $request ) { $data = array( @@ -153,7 +153,7 @@ class ShippingMethods extends AbstractController { /** * Filter shipping methods object returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Shipping_Method $method Shipping method object used to create response. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/ShippingZoneLocations.php b/src/RestApi/Version4/Controllers/ShippingZoneLocations.php index 706b780d2c3..a6c004695ed 100644 --- a/src/RestApi/Version4/Controllers/ShippingZoneLocations.php +++ b/src/RestApi/Version4/Controllers/ShippingZoneLocations.php @@ -51,7 +51,7 @@ class ShippingZoneLocations extends AbstractShippingZonesController { * Get all Shipping Zone Locations. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function get_items( $request ) { $zone = $this->get_zone( (int) $request['id'] ); @@ -76,7 +76,7 @@ class ShippingZoneLocations extends AbstractShippingZonesController { * Update all Shipping Zone Locations. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function update_items( $request ) { $zone = $this->get_zone( (int) $request['id'] ); @@ -120,7 +120,7 @@ class ShippingZoneLocations extends AbstractShippingZonesController { * * @param array $item Shipping Zone Location. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $item, $request ) { $context = empty( $request['context'] ) ? 'view' : $request['context']; diff --git a/src/RestApi/Version4/Controllers/ShippingZoneMethods.php b/src/RestApi/Version4/Controllers/ShippingZoneMethods.php index 2401e4bc37e..d731ad4f45e 100644 --- a/src/RestApi/Version4/Controllers/ShippingZoneMethods.php +++ b/src/RestApi/Version4/Controllers/ShippingZoneMethods.php @@ -102,7 +102,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController { * Get a single Shipping Zone Method. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function get_item( $request ) { $zone = $this->get_zone( $request['zone_id'] ); @@ -135,7 +135,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController { * Get all Shipping Zone Methods. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function get_items( $request ) { $zone = $this->get_zone( $request['zone_id'] ); @@ -235,7 +235,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController { // Actually delete. $zone->delete_shipping_method( $instance_id ); - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -247,7 +247,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController { * Fires after a method is deleted via the REST API. * * @param object $method - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_shipping_zone_method', $method, $response, $request ); @@ -259,7 +259,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController { * Update A Single Shipping Zone Method. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function update_item( $request ) { $zone = $this->get_zone( $request['zone_id'] ); @@ -352,7 +352,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController { * * @param array $item Shipping Zone Method. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $item, $request ) { $method = array( diff --git a/src/RestApi/Version4/Controllers/ShippingZones.php b/src/RestApi/Version4/Controllers/ShippingZones.php index 654c1a6dbde..55732940534 100644 --- a/src/RestApi/Version4/Controllers/ShippingZones.php +++ b/src/RestApi/Version4/Controllers/ShippingZones.php @@ -92,7 +92,7 @@ class ShippingZones extends AbstractShippingZonesController { * Get a single Shipping Zone. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function get_item( $request ) { $zone = $this->get_zone( $request->get_param( 'id' ) ); @@ -112,7 +112,7 @@ class ShippingZones extends AbstractShippingZonesController { * Get all Shipping Zones. * * @param \WP_REST_Request $request Request data. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function get_items( $request ) { $rest_of_the_world = \WC_Shipping_Zones::get_zone_by( 'zone_id', 0 ); @@ -218,7 +218,7 @@ class ShippingZones extends AbstractShippingZonesController { $previous = $this->get_item( $request ); $zone->delete(); - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -234,7 +234,7 @@ class ShippingZones extends AbstractShippingZonesController { * * @param array $item Shipping Zone. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $item, $request ) { $data = array( diff --git a/src/RestApi/Version4/Controllers/SystemStatus.php b/src/RestApi/Version4/Controllers/SystemStatus.php index e9c34ae1018..e7da5376d68 100644 --- a/src/RestApi/Version4/Controllers/SystemStatus.php +++ b/src/RestApi/Version4/Controllers/SystemStatus.php @@ -60,7 +60,7 @@ class SystemStatus extends AbstractController { * Get a system status info, by section. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $schema = $this->get_item_schema(); @@ -1162,7 +1162,7 @@ class SystemStatus extends AbstractController { * * @param array $system_status System status data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response + * @return \WP_REST_Response */ public function prepare_item_for_response( $system_status, $request ) { $data = $this->add_additional_fields_to_object( $system_status, $request ); @@ -1173,7 +1173,7 @@ class SystemStatus extends AbstractController { /** * Filter the system status returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param mixed $system_status System status * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/SystemStatusTools.php b/src/RestApi/Version4/Controllers/SystemStatusTools.php index e1edacd817f..9ec0e03a034 100644 --- a/src/RestApi/Version4/Controllers/SystemStatusTools.php +++ b/src/RestApi/Version4/Controllers/SystemStatusTools.php @@ -206,7 +206,7 @@ class SystemStatusTools extends AbstractController { * Get a list of system status tools. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $tools = array(); @@ -232,7 +232,7 @@ class SystemStatusTools extends AbstractController { * Return a single tool. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $tools = $this->get_tools(); @@ -257,7 +257,7 @@ class SystemStatusTools extends AbstractController { * Update (execute) a tool. * * @param \WP_REST_Request $request Request data. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { $tools = $this->get_tools(); @@ -294,7 +294,7 @@ class SystemStatusTools extends AbstractController { * * @param array $item Object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $item, $request ) { $context = empty( $request['context'] ) ? 'view' : $request['context']; diff --git a/src/RestApi/Version4/Controllers/TaxClasses.php b/src/RestApi/Version4/Controllers/TaxClasses.php index d6d90a667de..724640dd646 100644 --- a/src/RestApi/Version4/Controllers/TaxClasses.php +++ b/src/RestApi/Version4/Controllers/TaxClasses.php @@ -158,7 +158,7 @@ class TaxClasses extends AbstractController { * Create a single tax. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { $exists = false; @@ -210,7 +210,7 @@ class TaxClasses extends AbstractController { * Delete a single tax class. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function delete_item( $request ) { global $wpdb; @@ -265,7 +265,7 @@ class TaxClasses extends AbstractController { // Delete tax rates in the selected class. $wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) ); - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -277,7 +277,7 @@ class TaxClasses extends AbstractController { * Fires after a tax class is deleted via the REST API. * * @param stdClass $tax_class The tax data. - * @param WP_REST_Response $response The response returned from the API. + * @param \WP_REST_Response $response The response returned from the API. * @param \WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request ); @@ -290,7 +290,7 @@ class TaxClasses extends AbstractController { * * @param array $tax_class Tax class data. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $tax_class, $request ) { $data = $tax_class; @@ -307,7 +307,7 @@ class TaxClasses extends AbstractController { /** * Filter tax object returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param stdClass $tax_class Tax object used to create response. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/Taxes.php b/src/RestApi/Version4/Controllers/Taxes.php index f5bc66417ee..ca787b552cc 100644 --- a/src/RestApi/Version4/Controllers/Taxes.php +++ b/src/RestApi/Version4/Controllers/Taxes.php @@ -197,7 +197,7 @@ class Taxes extends AbstractController { * Get all taxes and allow filtering by tax code. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { global $wpdb; @@ -376,7 +376,7 @@ class Taxes extends AbstractController { * Create a single tax. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { @@ -409,7 +409,7 @@ class Taxes extends AbstractController { * Get a single tax. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $id = (int) $request['id']; @@ -429,7 +429,7 @@ class Taxes extends AbstractController { * Update a single tax. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { $id = (int) $request['id']; @@ -463,7 +463,7 @@ class Taxes extends AbstractController { * Delete a single tax. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function delete_item( $request ) { global $wpdb; @@ -495,7 +495,7 @@ class Taxes extends AbstractController { * Fires after a tax is deleted via the REST API. * * @param stdClass $tax The tax data. - * @param WP_REST_Response $response The response returned from the API. + * @param \WP_REST_Response $response The response returned from the API. * @param \WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request ); @@ -508,7 +508,7 @@ class Taxes extends AbstractController { * * @param stdClass $tax Tax object. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response Response data. + * @return \WP_REST_Response $response Response data. */ public function prepare_item_for_response( $tax, $request ) { global $wpdb; @@ -559,7 +559,7 @@ class Taxes extends AbstractController { /** * Filter tax object returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param stdClass $tax Tax object used to create response. * @param \WP_REST_Request $request Request object. */ diff --git a/src/RestApi/Version4/Controllers/Webhooks.php b/src/RestApi/Version4/Controllers/Webhooks.php index 86e4adc650a..e18dab3ff50 100644 --- a/src/RestApi/Version4/Controllers/Webhooks.php +++ b/src/RestApi/Version4/Controllers/Webhooks.php @@ -222,7 +222,7 @@ class Webhooks extends AbstractController { * Get all webhooks. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_items( $request ) { $args = array(); @@ -292,7 +292,7 @@ class Webhooks extends AbstractController { * Get a single item. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function get_item( $request ) { $id = (int) $request['id']; @@ -311,7 +311,7 @@ class Webhooks extends AbstractController { * Create a single webhook. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { @@ -371,7 +371,7 @@ class Webhooks extends AbstractController { * Update a single webhook. * * @param \WP_REST_Request $request Full details about the request. - * @return \WP_Error|WP_REST_Response + * @return \WP_Error\WP_REST_Response */ public function update_item( $request ) { $id = (int) $request['id']; @@ -445,7 +445,7 @@ class Webhooks extends AbstractController { * Delete a single webhook. * * @param \WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|\WP_Error + * @return \WP_REST_Response|\WP_Error */ public function delete_item( $request ) { $id = (int) $request['id']; @@ -469,7 +469,7 @@ class Webhooks extends AbstractController { /* translators: %s: post type */ return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) ); } - $response = new WP_REST_Response(); + $response = new \WP_REST_Response(); $response->set_data( array( 'deleted' => true, @@ -481,7 +481,7 @@ class Webhooks extends AbstractController { * Fires after a single item is deleted or trashed via the REST API. * * @param WC_Webhook $webhook The deleted or trashed item. - * @param WP_REST_Response $response The response data. + * @param \WP_REST_Response $response The response data. * @param \WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_webhook_object', $webhook, $response, $request ); @@ -547,7 +547,7 @@ class Webhooks extends AbstractController { * * @param int $id Webhook ID. * @param \WP_REST_Request $request Request object. - * @return WP_REST_Response $response + * @return \WP_REST_Response $response */ public function prepare_item_for_response( $id, $request ) { $webhook = wc_get_webhook( $id ); @@ -583,7 +583,7 @@ class Webhooks extends AbstractController { /** * Filter webhook object returned from the REST API. * - * @param WP_REST_Response $response The response object. + * @param \WP_REST_Response $response The response object. * @param WC_Webhook $webhook Webhook object used to create response. * @param \WP_REST_Request $request Request object. */ diff --git a/unit-tests/AbstractReportsTest.php b/unit-tests/AbstractReportsTest.php new file mode 100644 index 00000000000..39d7a6a4b41 --- /dev/null +++ b/unit-tests/AbstractReportsTest.php @@ -0,0 +1,48 @@ +markTestSkipped( 'Skipping reports tests - woocommerce-admin not found.' ); + return; + } + + parent::setUp(); + + $this->user = $this->factory->user->create( + array( + 'role' => 'administrator', + ) + ); + + wp_set_current_user( $this->user ); + + global $wpdb; + $wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Orders_Stats_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. + $wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Products_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. + $wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Coupons_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. + $wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Customers_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. + } + +} diff --git a/unit-tests/AbstractRestApiTest.php b/unit-tests/AbstractRestApiTest.php index b40b34d8a88..7b6b897da90 100644 --- a/unit-tests/AbstractRestApiTest.php +++ b/unit-tests/AbstractRestApiTest.php @@ -22,6 +22,9 @@ namespace WooCommerce\RestApi\UnitTests; defined( 'ABSPATH' ) || exit; use \WC_REST_Unit_Test_Case; +use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper; +use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; +use \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper; /** * Abstract Rest API Test Class diff --git a/unit-tests/Bootstrap.php b/unit-tests/Bootstrap.php index 337210bca6d..7c3ae49ad40 100755 --- a/unit-tests/Bootstrap.php +++ b/unit-tests/Bootstrap.php @@ -26,7 +26,7 @@ class Bootstrap { */ public static function init() { self::$wc_tests_dir = dirname( dirname( dirname( __FILE__ ) ) ) . '/woocommerce/tests'; - self::$wp_tests_dir = getenv( 'WP_TESTS_DIR' ); + self::$wp_tests_dir = getenv( 'WP_TESTS_DIR' ); if ( ! self::$wp_tests_dir ) { self::$wp_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; @@ -36,6 +36,15 @@ class Bootstrap { self::load_framework(); } + /** + * Should we skip WC Admin Reports tests? + * + * @return boolean + */ + public static function skip_report_tests() { + return ! file_exists( dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/woocommerce-admin.php' ); + } + /** * Setup hooks. */ @@ -46,6 +55,10 @@ class Bootstrap { \tests_add_filter( 'muplugins_loaded', function() { require_once dirname( dirname( __DIR__ ) ) . '/woocommerce/woocommerce.php'; require_once dirname( __DIR__ ) . '/woocommerce-rest-api.php'; + + if ( file_exists( dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/woocommerce-admin.php' ) ) { + require_once dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/woocommerce-admin.php'; + } } ); \tests_add_filter( 'setup_theme', function() { @@ -57,6 +70,13 @@ class Bootstrap { \WC_Install::install(); + if ( ! self::skip_report_tests() ) { + echo esc_html( 'Installing WooCommerce Admin...' . PHP_EOL ); + require_once dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/includes/class-wc-admin-install.php'; + \WC_Admin_Install::create_tables(); + \WC_Admin_Install::create_events(); + } + $GLOBALS['wp_roles'] = null; // WPCS: override ok. \wp_roles(); } ); @@ -83,9 +103,9 @@ class Bootstrap { require_once __DIR__ . '/Helpers/ProductHelper.php'; require_once __DIR__ . '/Helpers/ShippingHelper.php'; require_once __DIR__ . '/Helpers/SettingsHelper.php'; - require_once __DIR__ . '/Helpers/ReportsHelper.php'; require_once __DIR__ . '/Helpers/QueueHelper.php'; require_once __DIR__ . '/AbstractRestApiTest.php'; + require_once __DIR__ . '/AbstractReportsTest.php'; } } diff --git a/unit-tests/Helpers/ReportsHelper.php b/unit-tests/Helpers/ReportsHelper.php deleted file mode 100644 index 0c2027699a7..00000000000 --- a/unit-tests/Helpers/ReportsHelper.php +++ /dev/null @@ -1,27 +0,0 @@ -query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Orders_Stats_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. - $wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Products_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. - $wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Coupons_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. - $wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Customers_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine. - } -} diff --git a/unit-tests/Tests/Blocks/products-attributes-terms.php b/unit-tests/Tests/Blocks/ProductAttributeTerms.php similarity index 91% rename from unit-tests/Tests/Blocks/products-attributes-terms.php rename to unit-tests/Tests/Blocks/ProductAttributeTerms.php index afe8cd3c4d8..4febcaf1a72 100644 --- a/unit-tests/Tests/Blocks/products-attributes-terms.php +++ b/unit-tests/Tests/Blocks/ProductAttributeTerms.php @@ -3,12 +3,20 @@ * @package WooCommerce\Tests\API */ +namespace WooCommerce\RestApi\UnitTests\Tests\Blocks; + +defined( 'ABSPATH' ) || exit; + +use \WP_REST_Request; +use \WC_REST_Unit_Test_Case; +use \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper; + /** * Product Controller "products attributes terms" REST API Test * * @since 3.6.0 */ -class WC_Tests_API_Products_Attributes_Terms_Controller extends WC_REST_Unit_Test_Case { +class ProductAttributeTerms extends WC_REST_Unit_Test_Case { /** * Endpoints. diff --git a/unit-tests/Tests/Blocks/products-attributes.php b/unit-tests/Tests/Blocks/ProductAttributes.php similarity index 91% rename from unit-tests/Tests/Blocks/products-attributes.php rename to unit-tests/Tests/Blocks/ProductAttributes.php index b21990dc0c2..6389a097f96 100644 --- a/unit-tests/Tests/Blocks/products-attributes.php +++ b/unit-tests/Tests/Blocks/ProductAttributes.php @@ -3,12 +3,20 @@ * @package WooCommerce\Tests\API */ +namespace WooCommerce\RestApi\UnitTests\Tests\Blocks; + +defined( 'ABSPATH' ) || exit; + +use \WP_REST_Request; +use \WC_REST_Unit_Test_Case; +use \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper; + /** * Product Controller "products attributes" REST API Test * * @since 3.6.0 */ -class WC_Tests_API_Products_Attributes_Controller extends WC_REST_Unit_Test_Case { +class ProductAttributes extends WC_REST_Unit_Test_Case { /** * Endpoints. diff --git a/unit-tests/Tests/Blocks/products-categories.php b/unit-tests/Tests/Blocks/ProductCategories.php similarity index 92% rename from unit-tests/Tests/Blocks/products-categories.php rename to unit-tests/Tests/Blocks/ProductCategories.php index 3aca14621c5..c143942e196 100644 --- a/unit-tests/Tests/Blocks/products-categories.php +++ b/unit-tests/Tests/Blocks/ProductCategories.php @@ -3,12 +3,20 @@ * @package WooCommerce\Tests\API */ +namespace WooCommerce\RestApi\UnitTests\Tests\Blocks; + +defined( 'ABSPATH' ) || exit; + +use \WP_REST_Request; +use \WC_REST_Unit_Test_Case; +use \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper; + /** * Product Categories Controller REST API Test * * @since 3.6.0 */ -class WC_Tests_API_Products_Categories_Controller extends WC_REST_Unit_Test_Case { +class ProductCategories extends WC_REST_Unit_Test_Case { /** * Endpoints. diff --git a/unit-tests/Tests/Blocks/products.php b/unit-tests/Tests/Blocks/products.php index e8062c9c6a9..2da60b143cc 100644 --- a/unit-tests/Tests/Blocks/products.php +++ b/unit-tests/Tests/Blocks/products.php @@ -3,12 +3,20 @@ * @package WooCommerce\Tests\API */ +namespace WooCommerce\RestApi\UnitTests\Tests\Blocks; + +defined( 'ABSPATH' ) || exit; + +use \WP_REST_Request; +use \WC_REST_Unit_Test_Case; +use \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper; + /** * Blocks Product Controller REST API Test * * @since 3.6.0 */ -class WC_Tests_API_Products_Controller extends WC_REST_Unit_Test_Case { +class Products extends WC_REST_Unit_Test_Case { /** * Endpoints. diff --git a/unit-tests/Tests/Version4/Functions.php b/unit-tests/Tests/Version4/Functions.php deleted file mode 100644 index 5d5a01ebadf..00000000000 --- a/unit-tests/Tests/Version4/Functions.php +++ /dev/null @@ -1,257 +0,0 @@ -http_responder = array( $this, 'mock_http_responses' ); - - $upload_dir_info = wp_upload_dir(); - $this->upload_dir_path = $upload_dir_info['path']; - $this->upload_dir_url = $upload_dir_info['url']; - $this->file_name = 'Dr1Bczxq4q.png'; - } - - /** - * Run tear down code for unit tests. - */ - public function tearDown() { - parent::tearDown(); - - // remove files created in the wc_rest_upload_image_from_url() tests. - $file_path = $this->upload_dir_path . '/' . $this->file_name; - - if ( file_exists( $file_path ) ) { - unlink( $file_path ); - } - } - - /** - * Test wc_rest_prepare_date_response(). - * - * @since 2.6.0 - */ - public function test_wc_rest_prepare_date_response() { - $this->assertEquals( '2016-06-06T06:06:06', wc_rest_prepare_date_response( '2016-06-06 06:06:06' ) ); - } - - /** - * Test wc_rest_upload_image_from_url() should return error when unable to download image. - */ - public function test_wc_rest_upload_image_from_url_should_return_error_when_unable_to_download_image() { - $expected_error_message = 'Error getting remote image http://somedomain.com/nonexistent-image.png. Error: Not found.'; - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/nonexistent-image.png' ); - - $this->assertIsWPError( $result ); - $this->assertEquals( $expected_error_message, $result->get_error_message() ); - } - - /** - * Test wc_rest_upload_image_from_url() should return error when invalid image is passed. - * - * @requires PHP 5.4 - */ - 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.'; - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/invalid-image-1.png' ); - - $this->assertIsWPError( $result ); - $this->assertEquals( $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.'; - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/invalid-image-2.png' ); - - $this->assertIsWPError( $result ); - $this->assertEquals( $expected_error_message, $result->get_error_message() ); - } - - /** - * Test wc_rest_upload_image_from_url() should download image and return an array containing - * information about it. - * - * @requires PHP 5.4 - */ - public function test_wc_rest_upload_image_from_url_should_download_image_and_return_array() { - $expected_result = array( - 'file' => $this->upload_dir_path . '/' . $this->file_name, - 'url' => $this->upload_dir_url . '/' . $this->file_name, - 'type' => 'image/png', - ); - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/' . $this->file_name ); - - $this->assertEquals( $expected_result, $result ); - } - - /** - * Test wc_rest_set_uploaded_image_as_attachment(). - * - * @since 2.6.0 - */ - public function test_wc_rest_set_uploaded_image_as_attachment() { - $this->assertInternalType( - 'int', - wc_rest_set_uploaded_image_as_attachment( - array( - 'file' => '', - 'url' => '', - ) - ) - ); - } - - /** - * Test wc_rest_validate_reports_request_arg(). - * - * @since 2.6.0 - */ - public function test_wc_rest_validate_reports_request_arg() { - $request = new WP_REST_Request( - 'GET', - '/wc/v4/foo', - array( - 'args' => array( - 'date' => array( - 'type' => 'string', - 'format' => 'date', - ), - ), - ) - ); - - // Success. - $this->assertTrue( wc_rest_validate_reports_request_arg( '2016-06-06', $request, 'date' ) ); - - // Error. - $error = wc_rest_validate_reports_request_arg( 'foo', $request, 'date' ); - $this->assertEquals( 'The date you provided is invalid.', $error->get_error_message() ); - } - - /** - * Test wc_rest_urlencode_rfc3986(). - * - * @since 2.6.0 - */ - public function test_wc_rest_urlencode_rfc3986() { - $this->assertEquals( 'https%3A%2F%2Fwoocommerce.com%2F', wc_rest_urlencode_rfc3986( 'https://woocommerce.com/' ) ); - } - - /** - * Test wc_rest_check_post_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_post_permissions() { - $this->assertFalse( wc_rest_check_post_permissions( 'shop_order' ) ); - } - - /** - * Test wc_rest_check_user_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_user_permissions() { - $this->assertFalse( wc_rest_check_user_permissions() ); - } - - /** - * Test wc_rest_check_product_term_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_product_term_permissions() { - $this->assertFalse( wc_rest_check_product_term_permissions( 'product_cat' ) ); - } - - /** - * Test wc_rest_check_manager_permissions(). - * - * @since 2.6.0 - */ - public function test_wc_rest_check_manager_permissions() { - $this->assertFalse( wc_rest_check_manager_permissions( 'reports' ) ); - } - - /** - * Helper method to define mocked HTTP responses using WP_HTTP_TestCase. - * Thanks to WP_HTTP_TestCase, it is not necessary to perform a regular request - * to an external server which would significantly slow down the tests. - * - * This function is called by WP_HTTP_TestCase::http_request_listner(). - * - * @param array $request Request arguments. - * @param string $url URL of the request. - * - * @return array|false mocked response or false to let WP perform a regular request. - */ - protected function mock_http_responses( $request, $url ) { - $mocked_response = false; - - if ( 'http://somedomain.com/nonexistent-image.png' === $url ) { - $mocked_response = array( - 'response' => array( - 'code' => 404, - 'message' => 'Not found.', - ), - ); - } elseif ( 'http://somedomain.com/invalid-image-1.png' === $url ) { - // empty image. - $mocked_response = array( - 'response' => array( 'code' => 200 ), - ); - } elseif ( 'http://somedomain.com/invalid-image-2.png' === $url ) { - // image with an unsupported mime type. - // we need to manually copy the file as we are mocking the request. without this an empty file is created. - copy( WC_Unit_Tests_Bootstrap::instance()->tests_dir . '/data/file.txt', $request['filename'] ); - - $mocked_response = array( - 'response' => array( 'code' => 200 ), - ); - } elseif ( 'http://somedomain.com/' . $this->file_name === $url ) { - // we need to manually copy the file as we are mocking the request. without this an empty file is created. - copy( WC_Unit_Tests_Bootstrap::instance()->tests_dir . '/data/Dr1Bczxq4q.png', $request['filename'] ); - - $mocked_response = array( - 'response' => array( 'code' => 200 ), - ); - } - - return $mocked_response; - } -} diff --git a/unit-tests/Tests/Version4/Orders.php b/unit-tests/Tests/Version4/Orders.php index 849fb8a7e12..7bb2feb98d3 100644 --- a/unit-tests/Tests/Version4/Orders.php +++ b/unit-tests/Tests/Version4/Orders.php @@ -10,9 +10,6 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4; defined( 'ABSPATH' ) || exit; use \WooCommerce\RestApi\UnitTests\AbstractRestApiTest; -use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper; /** * Abstract Rest API Test Class diff --git a/unit-tests/Tests/Version4/Reports/Categories.php b/unit-tests/Tests/Version4/Reports/Categories.php index 99f48c69212..ce84c1e9deb 100644 --- a/unit-tests/Tests/Version4/Reports/Categories.php +++ b/unit-tests/Tests/Version4/Reports/Categories.php @@ -10,16 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Class Categories */ -class Categories extends WC_REST_Unit_Test_Case { +class Categories extends AbstractReportsTest { /** * Endpoints. @@ -28,21 +24,6 @@ class Categories extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/categories'; - /** - * Setup test reports categories data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -60,9 +41,6 @@ class Categories extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports() { - ReportsHelper::reset_stats_dbs(); - wp_set_current_user( $this->user ); - // Populate all of the data. $product = new WC_Product_Simple(); $product->set_name( 'Test Product' ); @@ -100,11 +78,8 @@ class Categories extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports_categories_param() { - ReportsHelper::reset_stats_dbs(); - wp_set_current_user( $this->user ); - // Populate all of the data. - $product = new WC_Product_Simple(); + $product = new \WC_Product_Simple(); $product->set_name( 'Test Product' ); $product->set_regular_price( 25 ); $product->save(); @@ -174,8 +149,6 @@ class Categories extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/Coupons.php b/unit-tests/Tests/Version4/Reports/Coupons.php index 16cd2cb728e..5aecfd0903f 100644 --- a/unit-tests/Tests/Version4/Reports/Coupons.php +++ b/unit-tests/Tests/Version4/Reports/Coupons.php @@ -9,17 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Class Coupons */ -class Coupons extends WC_REST_Unit_Test_Case { +class Coupons extends AbstractReportsTest { /** * Endpoints. @@ -28,19 +23,6 @@ class Coupons extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/coupons'; - /** - * Setup test reports products data. - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. */ @@ -54,9 +36,6 @@ class Coupons extends WC_REST_Unit_Test_Case { * Test getting basic reports. */ public function test_get_reports() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Simple product. $product = new WC_Product_Simple(); $product->set_name( 'Test Product' ); @@ -118,9 +97,6 @@ class Coupons extends WC_REST_Unit_Test_Case { * Test getting basic reports with the `coupons` param. */ public function test_get_reports_coupons_param() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Simple product. $product = new WC_Product_Simple(); $product->set_name( 'Test Product' ); @@ -183,8 +159,6 @@ class Coupons extends WC_REST_Unit_Test_Case { * Test reports schema. */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/CouponsStats.php b/unit-tests/Tests/Version4/Reports/CouponsStats.php index 981c481d7b0..f59a9d0ba2c 100644 --- a/unit-tests/Tests/Version4/Reports/CouponsStats.php +++ b/unit-tests/Tests/Version4/Reports/CouponsStats.php @@ -9,17 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Class CouponsStats */ -class CouponsStats extends WC_REST_Unit_Test_Case { +class CouponsStats extends AbstractReportsTest { /** * Endpoints. @@ -28,19 +23,6 @@ class CouponsStats extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/coupons/stats'; - /** - * Setup test reports products stats data. - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. */ @@ -54,9 +36,6 @@ class CouponsStats extends WC_REST_Unit_Test_Case { * Test getting reports. */ public function test_get_reports() { - ReportsHelper::reset_stats_dbs(); - wp_set_current_user( $this->user ); - // Populate all of the data. // Simple product. $product = new WC_Product_Simple(); @@ -153,8 +132,6 @@ class CouponsStats extends WC_REST_Unit_Test_Case { * Test reports schema. */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/CustomerStats.php b/unit-tests/Tests/Version4/Reports/CustomerStats.php index 27dfc5d4030..db4e35a14f8 100644 --- a/unit-tests/Tests/Version4/Reports/CustomerStats.php +++ b/unit-tests/Tests/Version4/Reports/CustomerStats.php @@ -10,12 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers Stats REST API Test Class @@ -23,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class CustomerStats extends WC_REST_Unit_Test_Case { +class CustomerStats extends AbstractReportsTest { /** * Endpoint. * @@ -31,21 +26,6 @@ class CustomerStats extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/customers/stats'; - /** - * Setup test reports products data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -63,8 +43,6 @@ class CustomerStats extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); @@ -96,9 +74,6 @@ class CustomerStats extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - $test_customers = array(); // Create 10 test customers. diff --git a/unit-tests/Tests/Version4/Reports/Customers.php b/unit-tests/Tests/Version4/Reports/Customers.php index e270855af72..af136a77e51 100644 --- a/unit-tests/Tests/Version4/Reports/Customers.php +++ b/unit-tests/Tests/Version4/Reports/Customers.php @@ -10,12 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers REST API Test Class @@ -23,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Customers extends WC_REST_Unit_Test_Case { +class Customers extends AbstractReportsTest { /** * Endpoint. * @@ -31,21 +26,6 @@ class Customers extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/customers'; - /** - * Setup test reports products data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -148,12 +128,12 @@ class Customers extends WC_REST_Unit_Test_Case { $product->set_regular_price( 25 ); $product->save(); - $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $admin_id, $product ); + $order = OrderHelper::create_order( $admin_id, $product ); $order->set_status( 'processing' ); $order->set_total( 100 ); $order->save(); - \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); + QueueHelper::run_all_pending(); $request = new WP_REST_Request( 'GET', $this->endpoint ); $request->set_query_params( array( 'per_page' => 10 ) ); @@ -166,7 +146,7 @@ class Customers extends WC_REST_Unit_Test_Case { $this->assertEquals( $admin_id, $reports[0]['user_id'] ); // Creating a customer should show up regardless of orders. - $customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'customer', 'password', 'customer@example.com' ); + $customer = CustomerHelper::create_customer( 'customer', 'password', 'customer@example.com' ); $request = new WP_REST_Request( 'GET', $this->endpoint ); $request->set_query_params( @@ -194,9 +174,6 @@ class Customers extends WC_REST_Unit_Test_Case { public function test_get_reports() { global $wpdb; - wp_set_current_user( $this->user ); - \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper::reset_stats_dbs(); - $test_customers = array(); $customer_names = array( 'Alice', 'Betty', 'Catherine', 'Dan', 'Eric', 'Fred', 'Greg', 'Henry', 'Ivan', 'Justin' ); @@ -205,25 +182,25 @@ class Customers extends WC_REST_Unit_Test_Case { for ( $i = 1; $i <= 10; $i++ ) { $name = $customer_names[ $i - 1 ]; $email = 'customer+' . strtolower( $name ) . '@example.com'; - $customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( "customer{$i}", 'password', $email ); + $customer = CustomerHelper::create_customer( "customer{$i}", 'password', $email ); $customer->set_first_name( $name ); $customer->save(); $test_customers[] = $customer; } // Create a test product for use in an order. - $product = new WC_Product_Simple(); + $product = new \WC_Product_Simple(); $product->set_name( 'Test Product' ); $product->set_regular_price( 25 ); $product->save(); // Place an order for the first test customer. - $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $test_customers[0]->get_id(), $product ); + $order = OrderHelper::create_order( $test_customers[0]->get_id(), $product ); $order->set_status( 'processing' ); $order->set_total( 100 ); $order->save(); - \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); + QueueHelper::run_all_pending(); $request = new WP_REST_Request( 'GET', $this->endpoint ); $request->set_query_params( @@ -342,8 +319,6 @@ class Customers extends WC_REST_Unit_Test_Case { * Test customer first and last name. */ public function test_customer_name() { - wp_set_current_user( $this->user ); - $customer = wp_insert_user( array( 'user_login' => 'daenerys', @@ -353,7 +328,7 @@ class Customers extends WC_REST_Unit_Test_Case { ); // Test shipping name and empty billing name. - $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $customer ); + $order = OrderHelper::create_order( $customer ); $order->set_billing_first_name( '' ); $order->set_billing_last_name( '' ); $order->set_shipping_first_name( 'Daenerys' ); @@ -362,7 +337,7 @@ class Customers extends WC_REST_Unit_Test_Case { $order->set_total( 100 ); $order->save(); - \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); + QueueHelper::run_all_pending(); $request = new WP_REST_Request( 'GET', $this->endpoint ); $response = $this->server->dispatch( $request ); @@ -379,7 +354,7 @@ class Customers extends WC_REST_Unit_Test_Case { $order->save(); do_action( 'woocommerce_update_customer', $customer ); - \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); + QueueHelper::run_all_pending(); $request = new WP_REST_Request( 'GET', $this->endpoint ); $request->set_query_params( array( 'orderby' => 'username' ) ); // Cache busting. @@ -401,7 +376,7 @@ class Customers extends WC_REST_Unit_Test_Case { ); do_action( 'woocommerce_update_customer', $customer ); - \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); + QueueHelper::run_all_pending(); $request = new WP_REST_Request( 'GET', $this->endpoint ); $request->set_query_params( array( 'orderby' => 'name' ) ); // Cache busting. diff --git a/unit-tests/Tests/Version4/Reports/DownloadStats.php b/unit-tests/Tests/Version4/Reports/DownloadStats.php index cbded71f99d..2940f3a20a8 100644 --- a/unit-tests/Tests/Version4/Reports/DownloadStats.php +++ b/unit-tests/Tests/Version4/Reports/DownloadStats.php @@ -9,10 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers Stats REST API Test Class @@ -20,7 +17,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class DownloadStats extends WC_REST_Unit_Test_Case { +class DownloadStats extends AbstractReportsTest { /** * Endpoints. @@ -29,19 +26,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/downloads/stats'; - /** - * Setup test reports downloads data. - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. */ @@ -56,8 +40,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case { */ public function test_get_report() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); // Populate all of the data. $prod_download = new \WC_Product_Download(); @@ -142,8 +124,7 @@ class DownloadStats extends WC_REST_Unit_Test_Case { */ public function test_get_report_with_user_filter() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); + $time = time(); // First set of data. @@ -236,8 +217,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case { */ public function test_get_report_orderby() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); // Populate all of the data. $prod_download = new \WC_Product_Download(); @@ -346,8 +325,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case { * Test reports schema. */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/Downloads.php b/unit-tests/Tests/Version4/Reports/Downloads.php index e169a6531bd..cf8e3d905e5 100644 --- a/unit-tests/Tests/Version4/Reports/Downloads.php +++ b/unit-tests/Tests/Version4/Reports/Downloads.php @@ -9,10 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers Stats REST API Test Class @@ -20,7 +17,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Downloads extends WC_REST_Unit_Test_Case { +class Downloads extends AbstractReportsTest { /** * Endpoints. @@ -29,19 +26,6 @@ class Downloads extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/downloads'; - /** - * Setup test reports downloads data. - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. */ @@ -56,8 +40,6 @@ class Downloads extends WC_REST_Unit_Test_Case { */ public function test_get_report() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); // Populate all of the data. $prod_download = new \WC_Product_Download(); @@ -112,8 +94,7 @@ class Downloads extends WC_REST_Unit_Test_Case { */ public function filter_setup() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); + $time = time(); // First set of data. @@ -402,8 +383,6 @@ class Downloads extends WC_REST_Unit_Test_Case { * Test reports schema. */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/Import.php b/unit-tests/Tests/Version4/Reports/Import.php index 249f40ef3e2..875c9bfcdf1 100644 --- a/unit-tests/Tests/Version4/Reports/Import.php +++ b/unit-tests/Tests/Version4/Reports/Import.php @@ -9,10 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers Stats REST API Test Class @@ -20,7 +17,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Import extends WC_REST_Unit_Test_Case { +class Import extends AbstractReportsTest { /** * Endpoint. diff --git a/unit-tests/Tests/Version4/Reports/OrderStats.php b/unit-tests/Tests/Version4/Reports/OrderStats.php index e929e89307e..8152df41541 100644 --- a/unit-tests/Tests/Version4/Reports/OrderStats.php +++ b/unit-tests/Tests/Version4/Reports/OrderStats.php @@ -9,13 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Class OrderStats */ -class OrderStats extends WC_REST_Unit_Test_Case { +class OrderStats extends AbstractReportsTest { /** * Endpoints. @@ -24,21 +23,6 @@ class OrderStats extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/orders/stats'; - /** - * Setup test reports orders data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -56,8 +40,6 @@ class OrderStats extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports() { - wp_set_current_user( $this->user ); - // @todo Update after report interface is done. $response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) ); $reports = $response->get_data(); @@ -85,8 +67,6 @@ class OrderStats extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/Orders.php b/unit-tests/Tests/Version4/Reports/Orders.php index 29f32ab1d67..2f283602d5e 100644 --- a/unit-tests/Tests/Version4/Reports/Orders.php +++ b/unit-tests/Tests/Version4/Reports/Orders.php @@ -10,11 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Orders REST API Test Class @@ -22,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Orders extends WC_REST_Unit_Test_Case { +class Orders extends AbstractReportsTest { /** * Endpoints. @@ -31,21 +27,6 @@ class Orders extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/orders'; - /** - * Setup test reports orders data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -63,11 +44,8 @@ class Orders extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Populate all of the data. - $product = new WC_Product_Simple(); + $product = new \WC_Product_Simple(); $product->set_name( 'Test Product' ); $product->set_regular_price( 25 ); $product->save(); @@ -117,8 +95,6 @@ class Orders extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/PerformanceIndicators.php b/unit-tests/Tests/Version4/Reports/PerformanceIndicators.php index cf2ee62639d..024daa95f8a 100644 --- a/unit-tests/Tests/Version4/Reports/PerformanceIndicators.php +++ b/unit-tests/Tests/Version4/Reports/PerformanceIndicators.php @@ -9,16 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * PerformanceIndicators */ -class PerformanceIndicators extends WC_REST_Unit_Test_Case { +class PerformanceIndicators extends AbstractReportsTest { /** * Endpoints. @@ -27,19 +23,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/performance-indicators'; - /** - * Setup tests. - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. */ @@ -55,8 +38,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case { */ public function test_get_indicators() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); // Populate all of the data. We'll create an order and a download. $prod_download = new \WC_Product_Download(); @@ -129,8 +110,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case { */ public function test_get_indicators_empty_request() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); $time = time(); $request = new WP_REST_Request( 'GET', $this->endpoint ); @@ -159,8 +138,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case { * Test schema. */ public function test_indicators_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); @@ -178,8 +155,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case { * Test schema for /allowed indicators endpoint. */ public function test_indicators_schema_allowed() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint . '/allowed' ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/ProductStats.php b/unit-tests/Tests/Version4/Reports/ProductStats.php index 551179464e2..f30b6e0a0de 100644 --- a/unit-tests/Tests/Version4/Reports/ProductStats.php +++ b/unit-tests/Tests/Version4/Reports/ProductStats.php @@ -10,16 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Class ProductStats */ -class ProductStats extends WC_REST_Unit_Test_Case { +class ProductStats extends AbstractReportsTest { /** * Endpoints. @@ -28,21 +24,6 @@ class ProductStats extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/products/stats'; - /** - * Setup test reports products stats data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -60,9 +41,6 @@ class ProductStats extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports() { - ReportsHelper::reset_stats_dbs(); - wp_set_current_user( $this->user ); - // Populate all of the data. $product = new \WC_Product_Simple(); $product->set_name( 'Test Product' ); @@ -144,8 +122,6 @@ class ProductStats extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/Products.php b/unit-tests/Tests/Version4/Reports/Products.php index 989bd9f4ef2..abcdf5436bb 100644 --- a/unit-tests/Tests/Version4/Reports/Products.php +++ b/unit-tests/Tests/Version4/Reports/Products.php @@ -10,10 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Products REST API Test Class @@ -21,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Products extends WC_REST_Unit_Test_Case { +class Products extends AbstractReportsTest { /** * Endpoints. @@ -30,21 +27,6 @@ class Products extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/products'; - /** - * Setup test reports products data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -62,9 +44,6 @@ class Products extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Populate all of the data. $product = new \WC_Product_Simple(); $product->set_name( 'Test Product' ); @@ -99,9 +78,6 @@ class Products extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports_products_param() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Populate all of the data. $product = new \WC_Product_Simple(); $product->set_name( 'Test Product' ); @@ -166,8 +142,6 @@ class Products extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/RevenueStats.php b/unit-tests/Tests/Version4/Reports/RevenueStats.php index e2d1b76c67e..10e8c44eac2 100644 --- a/unit-tests/Tests/Version4/Reports/RevenueStats.php +++ b/unit-tests/Tests/Version4/Reports/RevenueStats.php @@ -10,13 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Class RevenueStats */ -class RevenueStats extends WC_REST_Unit_Test_Case { +class RevenueStats extends AbstractReportsTest { /** * Endpoints. @@ -32,21 +31,6 @@ class RevenueStats extends WC_REST_Unit_Test_Case { */ protected $orders = array(); - /** - * Setup test reports revenue data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * diff --git a/unit-tests/Tests/Version4/Reports/Stock.php b/unit-tests/Tests/Version4/Reports/Stock.php index bc15ecab33c..a435aea84a0 100644 --- a/unit-tests/Tests/Version4/Reports/Stock.php +++ b/unit-tests/Tests/Version4/Reports/Stock.php @@ -10,9 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers Stats REST API Test Class @@ -20,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Stock extends WC_REST_Unit_Test_Case { +class Stock extends AbstractReportsTest { /** * Endpoints. @@ -29,19 +27,6 @@ class Stock extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/stock'; - /** - * Setup test reports stock data. - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. */ @@ -55,9 +40,6 @@ class Stock extends WC_REST_Unit_Test_Case { * Test getting reports. */ public function test_get_reports() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Populate all of the data. $low_stock = new \WC_Product_Simple(); $low_stock->set_name( 'Test low stock' ); @@ -111,8 +93,6 @@ class Stock extends WC_REST_Unit_Test_Case { * Test reports schema. */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/StockStats.php b/unit-tests/Tests/Version4/Reports/StockStats.php index 937e7859c6d..55ed6736e2d 100644 --- a/unit-tests/Tests/Version4/Reports/StockStats.php +++ b/unit-tests/Tests/Version4/Reports/StockStats.php @@ -9,14 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Class StockStats */ -class StockStats extends WC_REST_Unit_Test_Case { +class StockStats extends AbstractReportsTest { /** * Endpoints. @@ -25,19 +23,6 @@ class StockStats extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/stock/stats'; - /** - * Setup test reports stock data. - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. */ @@ -51,9 +36,6 @@ class StockStats extends WC_REST_Unit_Test_Case { * Test getting reports. */ public function test_get_reports() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - $number_of_low_stock = 3; for ( $i = 1; $i <= $number_of_low_stock; $i++ ) { $low_stock = new \WC_Product_Simple(); @@ -128,8 +110,6 @@ class StockStats extends WC_REST_Unit_Test_Case { * Test reports schema. */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/TaxStats.php b/unit-tests/Tests/Version4/Reports/TaxStats.php index 93a7ccd0327..607b3d17909 100644 --- a/unit-tests/Tests/Version4/Reports/TaxStats.php +++ b/unit-tests/Tests/Version4/Reports/TaxStats.php @@ -10,16 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * TaxStats */ -class TaxStats extends WC_REST_Unit_Test_Case { +class TaxStats extends AbstractReportsTest { /** * Endpoints. @@ -28,21 +24,6 @@ class TaxStats extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/taxes/stats'; - /** - * Setup test reports taxes data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -61,11 +42,9 @@ class TaxStats extends WC_REST_Unit_Test_Case { */ public function test_get_reports() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); // Populate all of the data. - $tax = WC_Tax::_insert_tax_rate( + $tax = \WC_Tax::_insert_tax_rate( array( 'tax_rate_country' => 'US', 'tax_rate_state' => '', @@ -143,8 +122,6 @@ class TaxStats extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/Taxes.php b/unit-tests/Tests/Version4/Reports/Taxes.php index c22140dab35..4f93d8b8ada 100644 --- a/unit-tests/Tests/Version4/Reports/Taxes.php +++ b/unit-tests/Tests/Version4/Reports/Taxes.php @@ -10,11 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers Stats REST API Test Class @@ -22,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Taxes extends WC_REST_Unit_Test_Case { +class Taxes extends AbstractReportsTest { /** * Endpoints. @@ -31,21 +27,6 @@ class Taxes extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/taxes'; - /** - * Setup test reports taxes data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -64,8 +45,6 @@ class Taxes extends WC_REST_Unit_Test_Case { */ public function test_get_reports() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); // Populate all of the data. $product = new \WC_Product_Simple(); @@ -132,8 +111,6 @@ class Taxes extends WC_REST_Unit_Test_Case { */ public function test_get_reports_taxes_param() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); // Populate all of the data. $product = new \WC_Product_Simple(); @@ -232,8 +209,6 @@ class Taxes extends WC_REST_Unit_Test_Case { */ public function test_get_reports_orderby_tax_rate() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); $wpdb->insert( $wpdb->prefix . 'woocommerce_tax_rates', @@ -289,8 +264,6 @@ class Taxes extends WC_REST_Unit_Test_Case { */ public function test_get_reports_orderby_tax_code() { global $wpdb; - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); $wpdb->insert( $wpdb->prefix . 'woocommerce_tax_rates', @@ -354,8 +327,6 @@ class Taxes extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Reports/Variations.php b/unit-tests/Tests/Version4/Reports/Variations.php index 0ba93066e45..8997ffcf314 100644 --- a/unit-tests/Tests/Version4/Reports/Variations.php +++ b/unit-tests/Tests/Version4/Reports/Variations.php @@ -10,10 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports; defined( 'ABSPATH' ) || exit; -use \WC_REST_Unit_Test_Case; -use \WP_REST_Request; -use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper; -use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; +use \WooCommerce\RestApi\UnitTests\AbstractReportsTest; /** * Reports Customers Stats REST API Test Class @@ -21,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; * @package WooCommerce\Tests\API * @since 3.5.0 */ -class Variations extends WC_REST_Unit_Test_Case { +class Variations extends AbstractReportsTest { /** * Endpoints. @@ -30,21 +27,6 @@ class Variations extends WC_REST_Unit_Test_Case { */ protected $endpoint = '/wc/v4/reports/variations'; - /** - * Setup test reports products data. - * - * @since 3.5.0 - */ - public function setUp() { - parent::setUp(); - - $this->user = $this->factory->user->create( - array( - 'role' => 'administrator', - ) - ); - } - /** * Test route registration. * @@ -62,9 +44,6 @@ class Variations extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Populate all of the data. $variation = new \WC_Product_Variation(); $variation->set_name( 'Test Variation' ); @@ -102,9 +81,6 @@ class Variations extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_get_reports_variations_param() { - wp_set_current_user( $this->user ); - ReportsHelper::reset_stats_dbs(); - // Populate all of the data. $variation = new \WC_Product_Variation(); $variation->set_name( 'Test Variation' ); @@ -177,8 +153,6 @@ class Variations extends WC_REST_Unit_Test_Case { * @since 3.5.0 */ public function test_reports_schema() { - wp_set_current_user( $this->user ); - $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); diff --git a/unit-tests/Tests/Version4/Settings.php b/unit-tests/Tests/Version4/Settings.php index 4e1650eaa79..6afa0aaa21c 100644 --- a/unit-tests/Tests/Version4/Settings.php +++ b/unit-tests/Tests/Version4/Settings.php @@ -11,6 +11,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4; defined( 'ABSPATH' ) || exit; use \WC_REST_Unit_Test_Case; +use \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper; class Settings extends WC_REST_Unit_Test_Case { @@ -19,8 +20,7 @@ class Settings extends WC_REST_Unit_Test_Case { */ public function setUp() { parent::setUp(); - $this->endpoint = new WC_REST_Setting_Options_Controller(); - \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register(); + SettingsHelper::register(); $this->user = $this->factory->user->create( array( 'role' => 'administrator', @@ -116,7 +116,7 @@ class Settings extends WC_REST_Unit_Test_Case { $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/settings' ) ); $this->assertEquals( 500, $response->get_status() ); - \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register(); + SettingsHelper::register(); } /** @@ -377,7 +377,7 @@ class Settings extends WC_REST_Unit_Test_Case { $controller ->expects( $this->any() ) ->method( 'get_group_settings' ) - ->will( $this->returnValue( \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register_test_settings( array() ) ) ); + ->will( $this->returnValue( SettingsHelper::register_test_settings( array() ) ) ); $controller ->expects( $this->any() ) diff --git a/unit-tests/Tests/Version4/ShippingMethods.php b/unit-tests/Tests/Version4/ShippingMethods.php index 8a8707d3582..3d59ea2464d 100644 --- a/unit-tests/Tests/Version4/ShippingMethods.php +++ b/unit-tests/Tests/Version4/ShippingMethods.php @@ -19,7 +19,7 @@ class ShippingMethods extends WC_REST_Unit_Test_Case { */ public function setUp() { parent::setUp(); - $this->endpoint = new WC_REST_Shipping_Methods_Controller(); + $this->endpoint = new \WC_REST_Shipping_Methods_Controller(); $this->user = $this->factory->user->create( array( 'role' => 'administrator', diff --git a/unit-tests/Tests/Version4/ShippingZones.php b/unit-tests/Tests/Version4/ShippingZones.php index 97034c0449c..476ab832c7d 100644 --- a/unit-tests/Tests/Version4/ShippingZones.php +++ b/unit-tests/Tests/Version4/ShippingZones.php @@ -10,6 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4; defined( 'ABSPATH' ) || exit; +use \WP_REST_Request; use \WC_REST_Unit_Test_Case; class ShippingZones extends WC_REST_Unit_Test_Case { @@ -27,8 +28,7 @@ class ShippingZones extends WC_REST_Unit_Test_Case { */ public function setUp() { parent::setUp(); - $this->endpoint = new WC_REST_Shipping_Zones_Controller(); - $this->user = $this->factory->user->create( + $this->user = $this->factory->user->create( array( 'role' => 'administrator', ) @@ -44,7 +44,7 @@ class ShippingZones extends WC_REST_Unit_Test_Case { * @return WC_Shipping_Zone */ protected function create_shipping_zone( $name, $order = 0, $locations = array() ) { - $zone = new WC_Shipping_Zone( null ); + $zone = new \WC_Shipping_Zone( null ); $zone->set_zone_name( $name ); $zone->set_zone_order( $order ); $zone->set_locations( $locations ); diff --git a/unit-tests/Tests/Version4/SystemStatus.php b/unit-tests/Tests/Version4/SystemStatus.php index b056be932d0..97ff7758ec0 100644 --- a/unit-tests/Tests/Version4/SystemStatus.php +++ b/unit-tests/Tests/Version4/SystemStatus.php @@ -9,6 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4; defined( 'ABSPATH' ) || exit; +use \WP_REST_Request; use \WC_REST_Unit_Test_Case; /** @@ -24,8 +25,7 @@ class SystemStatus extends WC_REST_Unit_Test_Case { */ public function setUp() { parent::setUp(); - $this->endpoint = new WC_REST_System_Status_Controller(); - $this->user = $this->factory->user->create( + $this->user = $this->factory->user->create( array( 'role' => 'administrator', ) @@ -110,7 +110,7 @@ class SystemStatus extends WC_REST_Unit_Test_Case { $this->assertEquals( get_option( 'woocommerce_db_version' ), $database['wc_database_version'] ); $this->assertEquals( $wpdb->prefix, $database['database_prefix'] ); - $this->assertEquals( WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database'] ); + $this->assertEquals( \WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database'] ); $this->assertArrayHasKey( 'woocommerce', $database['database_tables'], wc_print_r( $database, true ) ); $this->assertArrayHasKey( $wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], wc_print_r( $database, true ) ); } @@ -443,7 +443,7 @@ class SystemStatus extends WC_REST_Unit_Test_Case { } /** - * Provides a mocked response for external requests performed by WC_REST_System_Status_Controller. + * Provides a mocked response for external requests. * This way it is not necessary to perform a regular request to an external server which would * significantly slow down the tests. *