Fixing tests

This commit is contained in:
Mike Jolley 2019-06-10 13:39:46 +01:00
parent 191eb4865b
commit 5d65448e97
90 changed files with 374 additions and 984 deletions

View File

@ -119,7 +119,7 @@ abstract class AbstractController extends WP_REST_Controller {
* Bulk create, update and delete items. * Bulk create, update and delete items.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function batch_items( $request ) {
/** /**

View File

@ -96,7 +96,7 @@ abstract class AbstractObjectsController extends AbstractPostsController {
* @since 3.0.0 * @since 3.0.0
* @param WC_Data $object Object data. * @param WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @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 ) { protected function prepare_object_for_response( $object, $request ) {
// translators: %s: Class method name. // translators: %s: Class method name.
@ -120,7 +120,7 @@ abstract class AbstractObjectsController extends AbstractPostsController {
* Get a single item. * Get a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_item( $request ) {
$object = $this->get_object( (int) $request['id'] ); $object = $this->get_object( (int) $request['id'] );
@ -169,7 +169,7 @@ abstract class AbstractObjectsController extends AbstractPostsController {
* Create a single item. * Create a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
if ( ! empty( $request['id'] ) ) { if ( ! empty( $request['id'] ) ) {
@ -215,7 +215,7 @@ abstract class AbstractObjectsController extends AbstractPostsController {
* Update a single post. * Update a single post.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function update_item( $request ) {
$object = $this->get_object( (int) $request['id'] ); $object = $this->get_object( (int) $request['id'] );
@ -337,7 +337,7 @@ abstract class AbstractObjectsController extends AbstractPostsController {
* Get a collection of posts. * Get a collection of posts.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$query_args = $this->prepare_objects_query( $request ); $query_args = $this->prepare_objects_query( $request );
@ -397,7 +397,7 @@ abstract class AbstractObjectsController extends AbstractPostsController {
* Delete a single item. * Delete a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
$force = (bool) $request['force']; $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. * Fires after a single object is deleted or trashed via the REST API.
* *
* @param WC_Data $object The deleted or trashed object. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );

View File

@ -132,7 +132,7 @@ abstract class AbstractPostsController extends AbstractController {
* Get a single item. * Get a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -158,7 +158,7 @@ abstract class AbstractPostsController extends AbstractController {
* Create a single item. * Create a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
if ( ! empty( $request['id'] ) ) { if ( ! empty( $request['id'] ) ) {
@ -239,7 +239,7 @@ abstract class AbstractPostsController extends AbstractController {
* Update a single post. * Update a single post.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function update_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -293,7 +293,7 @@ abstract class AbstractPostsController extends AbstractController {
* Get a collection of posts. * Get a collection of posts.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$args = array(); $args = array();
@ -401,7 +401,7 @@ abstract class AbstractPostsController extends AbstractController {
* Delete a single item. * Delete a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
$id = (int) $request['id']; $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. * Fires after a single item is deleted or trashed via the REST API.
* *
* @param object $post The deleted or trashed item. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request ); do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request );

View File

@ -266,7 +266,7 @@ abstract class AbstractTermsContoller extends AbstractController {
* Get terms associated with a taxonomy. * Get terms associated with a taxonomy.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$taxonomy = $this->get_taxonomy( $request ); $taxonomy = $this->get_taxonomy( $request );
@ -530,7 +530,7 @@ abstract class AbstractTermsContoller extends AbstractController {
* Delete a single term from a taxonomy. * Delete a single term from a taxonomy.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
$taxonomy = $this->get_taxonomy( $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. * Fires after a single term is deleted via the REST API.
* *
* @param WP_Term $term The deleted term. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( "woocommerce_rest_delete_{$taxonomy}", $term, $response, $request ); do_action( "woocommerce_rest_delete_{$taxonomy}", $term, $response, $request );

View File

@ -200,7 +200,7 @@ class Coupons extends AbstractObjectsController {
* @since 3.0.0 * @since 3.0.0
* @param WC_Data $object Object data. * @param WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_object_for_response( $object, $request ) { public function prepare_object_for_response( $object, $request ) {
$data = $this->get_formatted_item_data( $object ); $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, * The dynamic portion of the hook name, $this->post_type,
* refers to object type being prepared for the response. * 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 WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @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. * Get a collection of posts and add the code search option to \WP_Query.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
add_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10, 2 ); add_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10, 2 );

View File

@ -93,7 +93,7 @@ class CustomerDownloads extends AbstractController {
* *
* @param stdClass $download Download object. * @param stdClass $download Download object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $download, $request ) {
$data = array( $data = array(
@ -122,7 +122,7 @@ class CustomerDownloads extends AbstractController {
/** /**
* Filter customer download data returned from the REST API. * 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 stdClass $download Download object used to create response.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -268,7 +268,7 @@ class Customers extends AbstractController {
* Get all customers. * Get all customers.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$prepared_args = array(); $prepared_args = array();
@ -366,7 +366,7 @@ class Customers extends AbstractController {
* *
* @throws WC_REST_Exception On invalid params. * @throws WC_REST_Exception On invalid params.
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
try { try {
@ -420,7 +420,7 @@ class Customers extends AbstractController {
* Get a single customer. * Get a single customer.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -441,7 +441,7 @@ class Customers extends AbstractController {
* *
* @throws WC_REST_Exception On invalid params. * @throws WC_REST_Exception On invalid params.
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function update_item( $request ) {
try { try {
@ -502,7 +502,7 @@ class Customers extends AbstractController {
* Delete a single customer. * Delete a single customer.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -547,7 +547,7 @@ class Customers extends AbstractController {
* Fires after a customer is deleted via the REST API. * Fires after a customer is deleted via the REST API.
* *
* @param WP_User $user_data User data. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( 'woocommerce_rest_delete_customer', $user_data, $response, $request ); 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_User $user_data User object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $user_data, $request ) {
$customer = new \WC_Customer( $user_data->ID ); $customer = new \WC_Customer( $user_data->ID );
@ -574,7 +574,7 @@ class Customers extends AbstractController {
/** /**
* Filter customer data returned from the REST API. * 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_User $user_data User object used to create response.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -77,7 +77,7 @@ class Data extends AbstractController {
* *
* @since 3.5.0 * @since 3.5.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$data = array(); $data = array();
@ -113,7 +113,7 @@ class Data extends AbstractController {
* *
* @param stdClass $resource Resource data. * @param stdClass $resource Resource data.
* @param \WP_REST_Request $request Request 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( $resource, $request ) { public function prepare_item_for_response( $resource, $request ) {
$data = array( $data = array(

View File

@ -155,7 +155,7 @@ class Continents extends DataController {
* *
* @since 3.5.0 * @since 3.5.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$continents = WC()->countries->get_continents(); $continents = WC()->countries->get_continents();
@ -175,7 +175,7 @@ class Continents extends DataController {
* *
* @since 3.5.0 * @since 3.5.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$data = $this->get_continent( strtoupper( $request['location'] ), $request ); $data = $this->get_continent( strtoupper( $request['location'] ), $request );
@ -191,7 +191,7 @@ class Continents extends DataController {
* @since 3.5.0 * @since 3.5.0
* @param object $item Data object. * @param object $item Data object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$data = $this->add_additional_fields_to_object( $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. * 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 array $item The original list of continent(s), countries, and states.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -102,7 +102,7 @@ class Countries extends DataController {
* *
* @since 3.5.0 * @since 3.5.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$countries = WC()->countries->get_countries(); $countries = WC()->countries->get_countries();
@ -122,7 +122,7 @@ class Countries extends DataController {
* *
* @since 3.5.0 * @since 3.5.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$data = $this->get_country( strtoupper( $request['location'] ), $request ); $data = $this->get_country( strtoupper( $request['location'] ), $request );
@ -138,7 +138,7 @@ class Countries extends DataController {
* @since 3.5.0 * @since 3.5.0
* @param object $item Data object. * @param object $item Data object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$data = $this->add_additional_fields_to_object( $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. * 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 array $data The original country's states list.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -101,7 +101,7 @@ class Currencies extends DataController {
* Return the list of currencies. * Return the list of currencies.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$currencies = get_woocommerce_currencies(); $currencies = get_woocommerce_currencies();
@ -118,7 +118,7 @@ class Currencies extends DataController {
* Return information for a specific currency. * Return information for a specific currency.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$data = $this->get_currency( strtoupper( $request['currency'] ), $request ); $data = $this->get_currency( strtoupper( $request['currency'] ), $request );
@ -132,7 +132,7 @@ class Currencies extends DataController {
* Return information for the current site currency. * Return information for the current site currency.
* *
* @param \WP_REST_Request $request Request data. * @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 ) { public function get_current_item( $request ) {
$currency = get_option( 'woocommerce_currency' ); $currency = get_option( 'woocommerce_currency' );
@ -144,7 +144,7 @@ class Currencies extends DataController {
* *
* @param object $item Data object. * @param object $item Data object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$data = $this->add_additional_fields_to_object( $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. * 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 array $item Currency data.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -50,7 +50,7 @@ class DownloadIPs extends DataController {
* *
* @since 3.5.0 * @since 3.5.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
global $wpdb; global $wpdb;
@ -86,7 +86,7 @@ class DownloadIPs extends DataController {
* @since 3.5.0 * @since 3.5.0
* @param object $item Data object. * @param object $item Data object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$data = $this->add_additional_fields_to_object( $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. * 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 array $item The original item.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -347,7 +347,7 @@ class Leaderboards extends Data {
* Return all leaderboards. * Return all leaderboards.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$persisted_query = json_decode( $request['persisted_query'], true ); $persisted_query = json_decode( $request['persisted_query'], true );
@ -402,7 +402,7 @@ class Leaderboards extends Data {
* *
* @param object $item Data object. * @param object $item Data object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$data = $this->add_additional_fields_to_object( $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. * 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 array $item The original item.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -105,7 +105,7 @@ class NetworkOrders extends Orders {
* *
* @param \WP_REST_Request $request Full details about the request. * @param \WP_REST_Request $request Full details about the request.
* *
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function network_orders( $request ) { public function network_orders( $request ) {
$blog_id = $request->get_param( 'blog_id' ); $blog_id = $request->get_param( 'blog_id' );

View File

@ -225,7 +225,7 @@ class OrderNotes extends AbstractController {
* Create a single order note. * Create a single order note.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
if ( ! empty( $request['id'] ) ) { if ( ! empty( $request['id'] ) ) {
@ -271,7 +271,7 @@ class OrderNotes extends AbstractController {
* Get a single order note. * Get a single order note.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -297,7 +297,7 @@ class OrderNotes extends AbstractController {
* Delete a single order note. * Delete a single order note.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
$id = (int) $request['id']; $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 ) ); 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( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -340,7 +340,7 @@ class OrderNotes extends AbstractController {
* Fires after a order note is deleted or trashed via the REST API. * 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_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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); 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_Comment $note Order note object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $note, $request ) {
$data = array( $data = array(
@ -377,7 +377,7 @@ class OrderNotes extends AbstractController {
/** /**
* Filter order note object returned from the REST API. * 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_Comment $note Order note object used to create response.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -177,7 +177,7 @@ class OrderRefunds extends Orders {
* @param WC_Data $object Object data. * @param WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @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 ) { public function prepare_object_for_response( $object, $request ) {
$this->request = $request; $this->request = $request;
@ -208,7 +208,7 @@ class OrderRefunds extends Orders {
* The dynamic portion of the hook name, $this->post_type, * The dynamic portion of the hook name, $this->post_type,
* refers to object type being prepared for the response. * 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 WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */
@ -221,7 +221,7 @@ class OrderRefunds extends Orders {
* @param WP_Post $post Post object. * @param WP_Post $post Post object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $post, $request ) {
$order = wc_get_order( (int) $request['order_id'] ); $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 * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
* prepared for the response. * 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_Post $post Post object.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */
@ -377,7 +377,7 @@ class OrderRefunds extends Orders {
* Create a single item. * Create a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
if ( ! empty( $request['id'] ) ) { if ( ! empty( $request['id'] ) ) {

View File

@ -293,7 +293,7 @@ class Orders extends AbstractObjectsController {
* @since 3.0.0 * @since 3.0.0
* @param \WC_Data $object Object data. * @param \WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_object_for_response( $object, $request ) { public function prepare_object_for_response( $object, $request ) {
$this->request = $request; $this->request = $request;
@ -311,7 +311,7 @@ class Orders extends AbstractObjectsController {
* The dynamic portion of the hook name, $this->post_type, * The dynamic portion of the hook name, $this->post_type,
* refers to object type being prepared for the response. * 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 WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -114,7 +114,7 @@ class PaymentGateways extends AbstractController {
* Get payment gateways. * Get payment gateways.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$payment_gateways = WC()->payment_gateways->payment_gateways(); $payment_gateways = WC()->payment_gateways->payment_gateways();
@ -132,7 +132,7 @@ class PaymentGateways extends AbstractController {
* Get a single payment gateway. * Get a single payment gateway.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$gateway = $this->get_gateway( $request ); $gateway = $this->get_gateway( $request );
@ -149,7 +149,7 @@ class PaymentGateways extends AbstractController {
* Update A Single Payment Method. * Update A Single Payment Method.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function update_item( $request ) { public function update_item( $request ) {
$gateway = $this->get_gateway( $request ); $gateway = $this->get_gateway( $request );
@ -223,7 +223,7 @@ class PaymentGateways extends AbstractController {
* Get a gateway based on the current request object. * Get a gateway based on the current request object.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|null * @return \WP_REST_Response|null
*/ */
public function get_gateway( $request ) { public function get_gateway( $request ) {
$gateway = null; $gateway = null;
@ -243,7 +243,7 @@ class PaymentGateways extends AbstractController {
* *
* @param WC_Payment_Gateway $gateway Payment gateway object. * @param WC_Payment_Gateway $gateway Payment gateway object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $gateway, $request ) {
$order = (array) get_option( 'woocommerce_gateway_order' ); $order = (array) get_option( 'woocommerce_gateway_order' );
@ -269,7 +269,7 @@ class PaymentGateways extends AbstractController {
/** /**
* Filter payment gateway objects returned from the REST API. * 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 WC_Payment_Gateway $gateway Payment gateway object.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -135,7 +135,7 @@ class ProductAttributeTerms extends AbstractTermsContoller {
* *
* @param WP_Term $item Term object. * @param WP_Term $item Term object.
* @param \WP_REST_Request $request Request params. * @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 ) { public function prepare_item_for_response( $item, $request ) {
// Get term order. // Get term order.
@ -163,7 +163,7 @@ class ProductAttributeTerms extends AbstractTermsContoller {
* *
* Allows modification of the term data right before it is returned. * 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 object $item The original term object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -357,7 +357,7 @@ class ProductAttributes extends AbstractController {
* Delete a single attribute. * Delete a single attribute.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
$force = isset( $request['force'] ) ? (bool) $request['force'] : false; $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 ) ); 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( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -393,7 +393,7 @@ class ProductAttributes extends AbstractController {
* Fires after a single attribute is deleted via the REST API. * Fires after a single attribute is deleted via the REST API.
* *
* @param stdObject $attribute The deleted attribute. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request ); do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request );
@ -406,7 +406,7 @@ class ProductAttributes extends AbstractController {
* *
* @param obj $item Term object. * @param obj $item Term object.
* @param \WP_REST_Request $request Request params. * @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 ) { public function prepare_item_for_response( $item, $request ) {
$data = array( $data = array(
@ -431,7 +431,7 @@ class ProductAttributes extends AbstractController {
* *
* Allows modification of the product attribute data right before it is returned. * 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 object $item The original attribute object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -35,7 +35,7 @@ class ProductCategories extends AbstractTermsContoller {
* *
* @param WP_Term $item Term object. * @param WP_Term $item Term object.
* @param \WP_REST_Request $request Request instance. * @param \WP_REST_Request $request Request instance.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $item, $request ) { public function prepare_item_for_response( $item, $request ) {
// Get category display type. // Get category display type.
@ -86,7 +86,7 @@ class ProductCategories extends AbstractTermsContoller {
* *
* Allows modification of the term data right before it is returned. * 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 object $item The original term object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -726,7 +726,7 @@ class ProductReviews extends AbstractController {
* Filter product reviews object returned from the REST API. * Filter product reviews 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 $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. * @param \WP_REST_Request $request Request object.
*/ */
return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request ); return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request );

View File

@ -35,7 +35,7 @@ class ProductShippingClasses extends AbstractTermsContoller {
* *
* @param obj $item Term object. * @param obj $item Term object.
* @param \WP_REST_Request $request Request params. * @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 ) { public function prepare_item_for_response( $item, $request ) {
$data = array( $data = array(
@ -59,7 +59,7 @@ class ProductShippingClasses extends AbstractTermsContoller {
* *
* Allows modification of the term data right before it is returned. * 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 object $item The original term object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -35,7 +35,7 @@ class ProductTags extends AbstractTermsContoller {
* *
* @param obj $item Term object. * @param obj $item Term object.
* @param \WP_REST_Request $request Request params. * @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 ) { public function prepare_item_for_response( $item, $request ) {
$data = array( $data = array(
@ -59,7 +59,7 @@ class ProductTags extends AbstractTermsContoller {
* *
* Allows modification of the term data right before it is returned. * 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 object $item The original term object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -174,7 +174,7 @@ class ProductVariations extends Products {
* *
* @param WC_Data $object Object data. * @param WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_object_for_response( $object, $request ) { public function prepare_object_for_response( $object, $request ) {
$data = array( $data = array(
@ -238,7 +238,7 @@ class ProductVariations extends Products {
* The dynamic portion of the hook name, $this->post_type, * The dynamic portion of the hook name, $this->post_type,
* refers to object type being prepared for the response. * 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 WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @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. * @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 ) { public function delete_item( $request ) {
$force = (bool) $request['force']; $force = (bool) $request['force'];
@ -684,7 +684,7 @@ class ProductVariations extends Products {
$object->delete( true ); $object->delete( true );
$result = 0 === $object->get_id(); $result = 0 === $object->get_id();
$response = new WP_REST_Response(); $response = new \WP_REST_Response();
$response->set_data( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -733,7 +733,7 @@ class ProductVariations extends Products {
* Fires after a single object is deleted or trashed via the REST API. * Fires after a single object is deleted or trashed via the REST API.
* *
* @param WC_Data $object The deleted or trashed object. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
@ -746,7 +746,7 @@ class ProductVariations extends Products {
* *
* @since 3.0.0 * @since 3.0.0
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function batch_items( $request ) {
$items = array_filter( $request->get_params() ); $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. * 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. * @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 ) { public function get_items( $request ) {
add_filter( 'posts_where', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_filter' ), 10, 2 ); add_filter( 'posts_where', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_filter' ), 10, 2 );

View File

@ -149,7 +149,7 @@ class Products extends AbstractObjectsController {
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* *
* @since 3.0.0 * @since 3.0.0
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_object_for_response( $object, $request ) { public function prepare_object_for_response( $object, $request ) {
$context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $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, * The dynamic portion of the hook name, $this->post_type,
* refers to object type being prepared for the response. * 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 WC_Data $object Object data.
* @param \WP_REST_Request $request Request object. * @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. * 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. * @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 ) { public function get_items( $request ) {
add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 ); 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. * @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 ) { public function delete_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -1500,7 +1500,7 @@ class Products extends AbstractObjectsController {
$object->delete( true ); $object->delete( true );
$result = 0 === $object->get_id(); $result = 0 === $object->get_id();
$response = new WP_REST_Response(); $response = new \WP_REST_Response();
$response->set_data( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -1555,7 +1555,7 @@ class Products extends AbstractObjectsController {
* Fires after a single object is deleted or trashed via the REST API. * Fires after a single object is deleted or trashed via the REST API.
* *
* @param WC_Data $object The deleted or trashed object. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );

View File

@ -191,7 +191,7 @@ class Reports extends AbstractController {
* *
* @param stdClass $report Report data. * @param stdClass $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = array( $data = array(
@ -225,7 +225,7 @@ class Reports extends AbstractController {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -103,7 +103,7 @@ class Categories extends Reports {
* *
* @param stdClass $report Report data. * @param stdClass $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -121,7 +121,7 @@ class Categories extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -100,7 +100,7 @@ class CouponStats extends Reports {
* *
* @param stdClass $report Report data. * @param stdClass $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = get_object_vars( $report ); $data = get_object_vars( $report );
@ -117,7 +117,7 @@ class CouponStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -91,7 +91,7 @@ class Coupons extends Reports {
* *
* @param stdClass $report Report data. * @param stdClass $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -109,7 +109,7 @@ class Coupons extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -88,7 +88,7 @@ class CustomerStats extends Reports {
* *
* @param Array $report Report data. * @param Array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -105,7 +105,7 @@ class CustomerStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -120,7 +120,7 @@ class Customers extends Reports {
* *
* @param array $report Report data. * @param array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $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. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -103,7 +103,7 @@ class DownloadStats extends Reports {
* *
* @param Array $report Report data. * @param Array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -120,7 +120,7 @@ class DownloadStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -80,7 +80,7 @@ class Downloads extends Reports {
* *
* @param Array $report Report data. * @param Array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -112,7 +112,7 @@ class Downloads extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -110,7 +110,7 @@ class Import extends Reports {
* Import data based on user request params. * Import data based on user request params.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function import_items( $request ) { public function import_items( $request ) {
$query_args = $this->prepare_objects_query( $request ); $query_args = $this->prepare_objects_query( $request );
@ -153,7 +153,7 @@ class Import extends Reports {
* *
* @param object $item Data object. * @param object $item Data object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$data = $this->add_additional_fields_to_object( $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. * 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 array $item The original item.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */
@ -227,7 +227,7 @@ class Import extends Reports {
* Cancel all queued import actions. * Cancel all queued import actions.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function cancel_import( $request ) { public function cancel_import( $request ) {
\WC_Admin_Reports_Sync::clear_queued_actions(); \WC_Admin_Reports_Sync::clear_queued_actions();
@ -247,7 +247,7 @@ class Import extends Reports {
* Delete all imported items. * Delete all imported items.
* *
* @param \WP_REST_Request $request Request data. * @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 ) { public function delete_imported_items( $request ) {
$delete = \WC_Admin_Reports_Sync::delete_report_data(); $delete = \WC_Admin_Reports_Sync::delete_report_data();
@ -274,7 +274,7 @@ class Import extends Reports {
* Get the status of the current import. * Get the status of the current import.
* *
* @param \WP_REST_Request $request Request data. * @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 ) { public function get_import_status( $request ) {
$result = array( $result = array(
@ -296,7 +296,7 @@ class Import extends Reports {
* Get the total orders and customers based on user supplied params. * Get the total orders and customers based on user supplied params.
* *
* @param \WP_REST_Request $request Request data. * @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 ) { public function get_import_totals( $request ) {
$query_args = $this->prepare_objects_query( $request ); $query_args = $this->prepare_objects_query( $request );

View File

@ -110,7 +110,7 @@ class OrderStats extends Reports {
* *
* @param Array $report Report data. * @param Array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -127,7 +127,7 @@ class OrderStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -99,7 +99,7 @@ class Orders extends Reports {
* *
* @param stdClass $report Report data. * @param stdClass $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -117,7 +117,7 @@ class Orders extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -323,7 +323,7 @@ class PerformanceIndicators extends Reports {
* *
* @param stdClass $stat_data Report data. * @param stdClass $stat_data Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $stat_data, $request ) { public function prepare_item_for_response( $stat_data, $request ) {
$context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $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. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -115,7 +115,7 @@ class ProductStats extends Reports {
* *
* @param Array $report Report data. * @param Array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -132,7 +132,7 @@ class ProductStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -93,7 +93,7 @@ class Products extends Reports {
* *
* @param Array $report Report data. * @param Array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -111,7 +111,7 @@ class Products extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -99,7 +99,7 @@ class RevenueStats extends Reports {
* *
* @param Array $report Report data. * @param Array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -116,7 +116,7 @@ class RevenueStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -183,7 +183,7 @@ class Stock extends Reports {
* *
* @param WC_Product $product Report data. * @param WC_Product $product Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $product, $request ) { public function prepare_item_for_response( $product, $request ) {
$data = array( $data = array(
@ -209,7 +209,7 @@ class Stock extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 WC_Product $product The original product object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -45,7 +45,7 @@ class StockStats extends Reports {
* *
* @param WC_Product $report Report data. * @param WC_Product $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -62,7 +62,7 @@ class StockStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 WC_Product $product The original bject.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -126,7 +126,7 @@ class TaxStats extends Reports {
* *
* @param stdClass $report Report data. * @param stdClass $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = get_object_vars( $report ); $data = get_object_vars( $report );
@ -143,7 +143,7 @@ class TaxStats extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -91,7 +91,7 @@ class Taxes extends Reports {
* *
* @param stdClass $report Report data. * @param stdClass $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $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. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -93,7 +93,7 @@ class Variations extends Reports {
* *
* @param array $report Report data. * @param array $report Report data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $report, $request ) { public function prepare_item_for_response( $report, $request ) {
$data = $report; $data = $report;
@ -111,7 +111,7 @@ class Variations extends Reports {
* *
* Allows modification of the report data right before it is returned. * 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 object $report The original report object.
* @param \WP_REST_Request $request Request used to generate the response. * @param \WP_REST_Request $request Request used to generate the response.
*/ */

View File

@ -75,7 +75,7 @@ class Settings extends AbstractController {
* Update a setting. * Update a setting.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function update_item( $request ) { public function update_item( $request ) {
$options_controller = new \WC_REST_Setting_Options_Controller(); $options_controller = new \WC_REST_Setting_Options_Controller();
@ -89,7 +89,7 @@ class Settings extends AbstractController {
* *
* @since 3.0.0 * @since 3.0.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$groups = apply_filters( 'woocommerce_settings_groups', array() ); $groups = apply_filters( 'woocommerce_settings_groups', array() );
@ -145,7 +145,7 @@ class Settings extends AbstractController {
* @since 3.0.0 * @since 3.0.0
* @param array $item Group object. * @param array $item Group object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$context = empty( $request['context'] ) ? 'view' : $request['context']; $context = empty( $request['context'] ) ? 'view' : $request['context'];

View File

@ -106,7 +106,7 @@ class SettingsOptions extends AbstractController {
* *
* @since 3.0.0 * @since 3.0.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$setting = $this->get_setting( $request['group_id'], $request['id'] ); $setting = $this->get_setting( $request['group_id'], $request['id'] );
@ -125,7 +125,7 @@ class SettingsOptions extends AbstractController {
* *
* @since 3.0.0 * @since 3.0.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$settings = $this->get_group_settings( $request['group_id'] ); $settings = $this->get_group_settings( $request['group_id'] );
@ -277,7 +277,7 @@ class SettingsOptions extends AbstractController {
* *
* @since 3.0.0 * @since 3.0.0
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function batch_items( $request ) {
// Get the request params. // Get the request params.
@ -304,7 +304,7 @@ class SettingsOptions extends AbstractController {
* *
* @since 3.0.0 * @since 3.0.0
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function update_item( $request ) { public function update_item( $request ) {
$setting = $this->get_setting( $request['group_id'], $request['id'] ); $setting = $this->get_setting( $request['group_id'], $request['id'] );
@ -347,7 +347,7 @@ class SettingsOptions extends AbstractController {
* @since 3.0.0 * @since 3.0.0
* @param object $item Setting object. * @param object $item Setting object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
unset( $item['option_key'] ); unset( $item['option_key'] );

View File

@ -95,7 +95,7 @@ class ShippingMethods extends AbstractController {
* Get shipping methods. * Get shipping methods.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$wc_shipping = \WC_Shipping::instance(); $wc_shipping = \WC_Shipping::instance();
@ -112,7 +112,7 @@ class ShippingMethods extends AbstractController {
* Get a single Shipping Method. * Get a single Shipping Method.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$wc_shipping = \WC_Shipping::instance(); $wc_shipping = \WC_Shipping::instance();
@ -132,7 +132,7 @@ class ShippingMethods extends AbstractController {
* *
* @param WC_Shipping_Method $method Shipping method object. * @param WC_Shipping_Method $method Shipping method object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $method, $request ) {
$data = array( $data = array(
@ -153,7 +153,7 @@ class ShippingMethods extends AbstractController {
/** /**
* Filter shipping methods object returned from the REST API. * 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 WC_Shipping_Method $method Shipping method object used to create response.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -51,7 +51,7 @@ class ShippingZoneLocations extends AbstractShippingZonesController {
* Get all Shipping Zone Locations. * Get all Shipping Zone Locations.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$zone = $this->get_zone( (int) $request['id'] ); $zone = $this->get_zone( (int) $request['id'] );
@ -76,7 +76,7 @@ class ShippingZoneLocations extends AbstractShippingZonesController {
* Update all Shipping Zone Locations. * Update all Shipping Zone Locations.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function update_items( $request ) { public function update_items( $request ) {
$zone = $this->get_zone( (int) $request['id'] ); $zone = $this->get_zone( (int) $request['id'] );
@ -120,7 +120,7 @@ class ShippingZoneLocations extends AbstractShippingZonesController {
* *
* @param array $item Shipping Zone Location. * @param array $item Shipping Zone Location.
* @param \WP_REST_Request $request Request object. * @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 ) { public function prepare_item_for_response( $item, $request ) {
$context = empty( $request['context'] ) ? 'view' : $request['context']; $context = empty( $request['context'] ) ? 'view' : $request['context'];

View File

@ -102,7 +102,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController {
* Get a single Shipping Zone Method. * Get a single Shipping Zone Method.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$zone = $this->get_zone( $request['zone_id'] ); $zone = $this->get_zone( $request['zone_id'] );
@ -135,7 +135,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController {
* Get all Shipping Zone Methods. * Get all Shipping Zone Methods.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$zone = $this->get_zone( $request['zone_id'] ); $zone = $this->get_zone( $request['zone_id'] );
@ -235,7 +235,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController {
// Actually delete. // Actually delete.
$zone->delete_shipping_method( $instance_id ); $zone->delete_shipping_method( $instance_id );
$response = new WP_REST_Response(); $response = new \WP_REST_Response();
$response->set_data( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -247,7 +247,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController {
* Fires after a method is deleted via the REST API. * Fires after a method is deleted via the REST API.
* *
* @param object $method * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( 'woocommerce_rest_delete_shipping_zone_method', $method, $response, $request ); 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. * Update A Single Shipping Zone Method.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function update_item( $request ) { public function update_item( $request ) {
$zone = $this->get_zone( $request['zone_id'] ); $zone = $this->get_zone( $request['zone_id'] );
@ -352,7 +352,7 @@ class ShippingZoneMethods extends AbstractShippingZonesController {
* *
* @param array $item Shipping Zone Method. * @param array $item Shipping Zone Method.
* @param \WP_REST_Request $request Request object. * @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 ) { public function prepare_item_for_response( $item, $request ) {
$method = array( $method = array(

View File

@ -92,7 +92,7 @@ class ShippingZones extends AbstractShippingZonesController {
* Get a single Shipping Zone. * Get a single Shipping Zone.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response|\WP_Error * @return \WP_REST_Response|\WP_Error
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$zone = $this->get_zone( $request->get_param( 'id' ) ); $zone = $this->get_zone( $request->get_param( 'id' ) );
@ -112,7 +112,7 @@ class ShippingZones extends AbstractShippingZonesController {
* Get all Shipping Zones. * Get all Shipping Zones.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$rest_of_the_world = \WC_Shipping_Zones::get_zone_by( 'zone_id', 0 ); $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 ); $previous = $this->get_item( $request );
$zone->delete(); $zone->delete();
$response = new WP_REST_Response(); $response = new \WP_REST_Response();
$response->set_data( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -234,7 +234,7 @@ class ShippingZones extends AbstractShippingZonesController {
* *
* @param array $item Shipping Zone. * @param array $item Shipping Zone.
* @param \WP_REST_Request $request Request object. * @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 ) { public function prepare_item_for_response( $item, $request ) {
$data = array( $data = array(

View File

@ -60,7 +60,7 @@ class SystemStatus extends AbstractController {
* Get a system status info, by section. * Get a system status info, by section.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$schema = $this->get_item_schema(); $schema = $this->get_item_schema();
@ -1162,7 +1162,7 @@ class SystemStatus extends AbstractController {
* *
* @param array $system_status System status data. * @param array $system_status System status data.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
* @return WP_REST_Response * @return \WP_REST_Response
*/ */
public function prepare_item_for_response( $system_status, $request ) { public function prepare_item_for_response( $system_status, $request ) {
$data = $this->add_additional_fields_to_object( $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. * 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 mixed $system_status System status
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -206,7 +206,7 @@ class SystemStatusTools extends AbstractController {
* Get a list of system status tools. * Get a list of system status tools.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$tools = array(); $tools = array();
@ -232,7 +232,7 @@ class SystemStatusTools extends AbstractController {
* Return a single tool. * Return a single tool.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function get_item( $request ) { public function get_item( $request ) {
$tools = $this->get_tools(); $tools = $this->get_tools();
@ -257,7 +257,7 @@ class SystemStatusTools extends AbstractController {
* Update (execute) a tool. * Update (execute) a tool.
* *
* @param \WP_REST_Request $request Request data. * @param \WP_REST_Request $request Request data.
* @return \WP_Error|WP_REST_Response * @return \WP_Error\WP_REST_Response
*/ */
public function update_item( $request ) { public function update_item( $request ) {
$tools = $this->get_tools(); $tools = $this->get_tools();
@ -294,7 +294,7 @@ class SystemStatusTools extends AbstractController {
* *
* @param array $item Object. * @param array $item Object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $item, $request ) {
$context = empty( $request['context'] ) ? 'view' : $request['context']; $context = empty( $request['context'] ) ? 'view' : $request['context'];

View File

@ -158,7 +158,7 @@ class TaxClasses extends AbstractController {
* Create a single tax. * Create a single tax.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
$exists = false; $exists = false;
@ -210,7 +210,7 @@ class TaxClasses extends AbstractController {
* Delete a single tax class. * Delete a single tax class.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
global $wpdb; global $wpdb;
@ -265,7 +265,7 @@ class TaxClasses extends AbstractController {
// Delete tax rates in the selected class. // Delete tax rates in the selected class.
$wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) ); $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( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -277,7 +277,7 @@ class TaxClasses extends AbstractController {
* Fires after a tax class is deleted via the REST API. * Fires after a tax class is deleted via the REST API.
* *
* @param stdClass $tax_class The tax data. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request ); 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 array $tax_class Tax class data.
* @param \WP_REST_Request $request Request 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_class, $request ) { public function prepare_item_for_response( $tax_class, $request ) {
$data = $tax_class; $data = $tax_class;
@ -307,7 +307,7 @@ class TaxClasses extends AbstractController {
/** /**
* Filter tax object returned from the REST API. * 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 stdClass $tax_class Tax object used to create response.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -197,7 +197,7 @@ class Taxes extends AbstractController {
* Get all taxes and allow filtering by tax code. * Get all taxes and allow filtering by tax code.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
global $wpdb; global $wpdb;
@ -376,7 +376,7 @@ class Taxes extends AbstractController {
* Create a single tax. * Create a single tax.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
if ( ! empty( $request['id'] ) ) { if ( ! empty( $request['id'] ) ) {
@ -409,7 +409,7 @@ class Taxes extends AbstractController {
* Get a single tax. * Get a single tax.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -429,7 +429,7 @@ class Taxes extends AbstractController {
* Update a single tax. * Update a single tax.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function update_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -463,7 +463,7 @@ class Taxes extends AbstractController {
* Delete a single tax. * Delete a single tax.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
global $wpdb; global $wpdb;
@ -495,7 +495,7 @@ class Taxes extends AbstractController {
* Fires after a tax is deleted via the REST API. * Fires after a tax is deleted via the REST API.
* *
* @param stdClass $tax The tax data. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request ); do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request );
@ -508,7 +508,7 @@ class Taxes extends AbstractController {
* *
* @param stdClass $tax Tax object. * @param stdClass $tax Tax object.
* @param \WP_REST_Request $request Request 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 ) { public function prepare_item_for_response( $tax, $request ) {
global $wpdb; global $wpdb;
@ -559,7 +559,7 @@ class Taxes extends AbstractController {
/** /**
* Filter tax object returned from the REST API. * 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 stdClass $tax Tax object used to create response.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -222,7 +222,7 @@ class Webhooks extends AbstractController {
* Get all webhooks. * Get all webhooks.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_items( $request ) {
$args = array(); $args = array();
@ -292,7 +292,7 @@ class Webhooks extends AbstractController {
* Get a single item. * Get a single item.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function get_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -311,7 +311,7 @@ class Webhooks extends AbstractController {
* Create a single webhook. * Create a single webhook.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function create_item( $request ) {
if ( ! empty( $request['id'] ) ) { if ( ! empty( $request['id'] ) ) {
@ -371,7 +371,7 @@ class Webhooks extends AbstractController {
* Update a single webhook. * Update a single webhook.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function update_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -445,7 +445,7 @@ class Webhooks extends AbstractController {
* Delete a single webhook. * Delete a single webhook.
* *
* @param \WP_REST_Request $request Full details about the request. * @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 ) { public function delete_item( $request ) {
$id = (int) $request['id']; $id = (int) $request['id'];
@ -469,7 +469,7 @@ class Webhooks extends AbstractController {
/* translators: %s: post type */ /* 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 ) ); 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( $response->set_data(
array( array(
'deleted' => true, 'deleted' => true,
@ -481,7 +481,7 @@ class Webhooks extends AbstractController {
* Fires after a single item is deleted or trashed via the REST API. * Fires after a single item is deleted or trashed via the REST API.
* *
* @param WC_Webhook $webhook The deleted or trashed item. * @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. * @param \WP_REST_Request $request The request sent to the API.
*/ */
do_action( 'woocommerce_rest_delete_webhook_object', $webhook, $response, $request ); do_action( 'woocommerce_rest_delete_webhook_object', $webhook, $response, $request );
@ -547,7 +547,7 @@ class Webhooks extends AbstractController {
* *
* @param int $id Webhook ID. * @param int $id Webhook ID.
* @param \WP_REST_Request $request Request object. * @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 ) { public function prepare_item_for_response( $id, $request ) {
$webhook = wc_get_webhook( $id ); $webhook = wc_get_webhook( $id );
@ -583,7 +583,7 @@ class Webhooks extends AbstractController {
/** /**
* Filter webhook object returned from the REST API. * 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 WC_Webhook $webhook Webhook object used to create response.
* @param \WP_REST_Request $request Request object. * @param \WP_REST_Request $request Request object.
*/ */

View File

@ -0,0 +1,48 @@
<?php
/**
* Abstract for reports tests - these tests can only run if WC Admin exists.
*/
namespace WooCommerce\RestApi\UnitTests;
defined( 'ABSPATH' ) || exit;
use \WooCommerce\RestApi\UnitTests\Bootstrap;
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\Helpers\CustomerHelper;
/**
* Class AbstractReportsTest.
*/
abstract class AbstractReportsTest extends WC_REST_Unit_Test_Case {
/**
* Setup test reports categories data.
*/
public function setUp() {
if ( Bootstrap::skip_report_tests() ) {
$this->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.
}
}

View File

@ -22,6 +22,9 @@ namespace WooCommerce\RestApi\UnitTests;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; 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 * Abstract Rest API Test Class

View File

@ -26,7 +26,7 @@ class Bootstrap {
*/ */
public static function init() { public static function init() {
self::$wc_tests_dir = dirname( dirname( dirname( __FILE__ ) ) ) . '/woocommerce/tests'; 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 ) { if ( ! self::$wp_tests_dir ) {
self::$wp_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; self::$wp_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
@ -36,6 +36,15 @@ class Bootstrap {
self::load_framework(); 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. * Setup hooks.
*/ */
@ -46,6 +55,10 @@ class Bootstrap {
\tests_add_filter( 'muplugins_loaded', function() { \tests_add_filter( 'muplugins_loaded', function() {
require_once dirname( dirname( __DIR__ ) ) . '/woocommerce/woocommerce.php'; require_once dirname( dirname( __DIR__ ) ) . '/woocommerce/woocommerce.php';
require_once dirname( __DIR__ ) . '/woocommerce-rest-api.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() { \tests_add_filter( 'setup_theme', function() {
@ -57,6 +70,13 @@ class Bootstrap {
\WC_Install::install(); \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. $GLOBALS['wp_roles'] = null; // WPCS: override ok.
\wp_roles(); \wp_roles();
} ); } );
@ -83,9 +103,9 @@ class Bootstrap {
require_once __DIR__ . '/Helpers/ProductHelper.php'; require_once __DIR__ . '/Helpers/ProductHelper.php';
require_once __DIR__ . '/Helpers/ShippingHelper.php'; require_once __DIR__ . '/Helpers/ShippingHelper.php';
require_once __DIR__ . '/Helpers/SettingsHelper.php'; require_once __DIR__ . '/Helpers/SettingsHelper.php';
require_once __DIR__ . '/Helpers/ReportsHelper.php';
require_once __DIR__ . '/Helpers/QueueHelper.php'; require_once __DIR__ . '/Helpers/QueueHelper.php';
require_once __DIR__ . '/AbstractRestApiTest.php'; require_once __DIR__ . '/AbstractRestApiTest.php';
require_once __DIR__ . '/AbstractReportsTest.php';
} }
} }

View File

@ -1,27 +0,0 @@
<?php
/**
* Helper code for wc-admin unit tests.
*
* @package WooCommerce\Tests\Framework\Helpers
*/
namespace WooCommerce\RestApi\UnitTests\Helpers;
defined( 'ABSPATH' ) || exit;
/**
* Class ReportsHelper.
*/
class ReportsHelper {
/**
* Delete everything in the lookup tables.
*/
public static function reset_stats_dbs() {
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.
}
}

View File

@ -3,12 +3,20 @@
* @package WooCommerce\Tests\API * @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 * Product Controller "products attributes terms" REST API Test
* *
* @since 3.6.0 * @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. * Endpoints.

View File

@ -3,12 +3,20 @@
* @package WooCommerce\Tests\API * @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 * Product Controller "products attributes" REST API Test
* *
* @since 3.6.0 * @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. * Endpoints.

View File

@ -3,12 +3,20 @@
* @package WooCommerce\Tests\API * @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 * Product Categories Controller REST API Test
* *
* @since 3.6.0 * @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. * Endpoints.

View File

@ -3,12 +3,20 @@
* @package WooCommerce\Tests\API * @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 * Blocks Product Controller REST API Test
* *
* @since 3.6.0 * @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. * Endpoints.

View File

@ -1,257 +0,0 @@
<?php
/**
* File for the WC_Tests_API_Functions class.
*
* @package WooCommerce\Tests\API
*/
namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
defined( 'ABSPATH' ) || exit;
use \WC_Unit_Test_Case;
/**
* REST API Functions.
* @since 2.6.0
*/
class Functions extends WC_Unit_Test_Case {
/**
* @var string path to the WP upload dir.
*/
private $upload_dir_path;
/**
* @var string WP upload dir URL.
*/
private $upload_dir_url;
/**
* @var string Name of the file used in wc_rest_upload_image_from_url() tests.
*/
private $file_name;
/**
* Run setup code for unit tests.
*/
public function setUp() {
parent::setUp();
// Callback used by WP_HTTP_TestCase to decide whether to perform HTTP requests or to provide a mocked response.
$this->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;
}
}

View File

@ -10,9 +10,6 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WooCommerce\RestApi\UnitTests\AbstractRestApiTest; 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 * Abstract Rest API Test Class

View File

@ -10,16 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
/** /**
* Class Categories * Class Categories
*/ */
class Categories extends WC_REST_Unit_Test_Case { class Categories extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -28,21 +24,6 @@ class Categories extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/categories'; 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. * Test route registration.
* *
@ -60,9 +41,6 @@ class Categories extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports() { public function test_get_reports() {
ReportsHelper::reset_stats_dbs();
wp_set_current_user( $this->user );
// Populate all of the data. // Populate all of the data.
$product = new WC_Product_Simple(); $product = new WC_Product_Simple();
$product->set_name( 'Test Product' ); $product->set_name( 'Test Product' );
@ -100,11 +78,8 @@ class Categories extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports_categories_param() { public function test_get_reports_categories_param() {
ReportsHelper::reset_stats_dbs();
wp_set_current_user( $this->user );
// Populate all of the data. // Populate all of the data.
$product = new WC_Product_Simple(); $product = new \WC_Product_Simple();
$product->set_name( 'Test Product' ); $product->set_name( 'Test Product' );
$product->set_regular_price( 25 ); $product->set_regular_price( 25 );
$product->save(); $product->save();
@ -174,8 +149,6 @@ class Categories extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -9,17 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
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;
/** /**
* Class Coupons * Class Coupons
*/ */
class Coupons extends WC_REST_Unit_Test_Case { class Coupons extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -28,19 +23,6 @@ class Coupons extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/coupons'; 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. * Test route registration.
*/ */
@ -54,9 +36,6 @@ class Coupons extends WC_REST_Unit_Test_Case {
* Test getting basic reports. * Test getting basic reports.
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Simple product. // Simple product.
$product = new WC_Product_Simple(); $product = new WC_Product_Simple();
$product->set_name( 'Test Product' ); $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. * Test getting basic reports with the `coupons` param.
*/ */
public function test_get_reports_coupons_param() { public function test_get_reports_coupons_param() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Simple product. // Simple product.
$product = new WC_Product_Simple(); $product = new WC_Product_Simple();
$product->set_name( 'Test Product' ); $product->set_name( 'Test Product' );
@ -183,8 +159,6 @@ class Coupons extends WC_REST_Unit_Test_Case {
* Test reports schema. * Test reports schema.
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -9,17 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
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;
/** /**
* Class CouponsStats * Class CouponsStats
*/ */
class CouponsStats extends WC_REST_Unit_Test_Case { class CouponsStats extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -28,19 +23,6 @@ class CouponsStats extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/coupons/stats'; 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. * Test route registration.
*/ */
@ -54,9 +36,6 @@ class CouponsStats extends WC_REST_Unit_Test_Case {
* Test getting reports. * Test getting reports.
*/ */
public function test_get_reports() { public function test_get_reports() {
ReportsHelper::reset_stats_dbs();
wp_set_current_user( $this->user );
// Populate all of the data. // Populate all of the data.
// Simple product. // Simple product.
$product = new WC_Product_Simple(); $product = new WC_Product_Simple();
@ -153,8 +132,6 @@ class CouponsStats extends WC_REST_Unit_Test_Case {
* Test reports schema. * Test reports schema.
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,12 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
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;
/** /**
* Reports Customers Stats REST API Test Class * Reports Customers Stats REST API Test Class
@ -23,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class CustomerStats extends WC_REST_Unit_Test_Case { class CustomerStats extends AbstractReportsTest {
/** /**
* Endpoint. * Endpoint.
* *
@ -31,21 +26,6 @@ class CustomerStats extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/customers/stats'; 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. * Test route registration.
* *
@ -63,8 +43,6 @@ class CustomerStats extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();
@ -96,9 +74,6 @@ class CustomerStats extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
$test_customers = array(); $test_customers = array();
// Create 10 test customers. // Create 10 test customers.

View File

@ -10,12 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
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;
/** /**
* Reports Customers REST API Test Class * Reports Customers REST API Test Class
@ -23,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Customers extends WC_REST_Unit_Test_Case { class Customers extends AbstractReportsTest {
/** /**
* Endpoint. * Endpoint.
* *
@ -31,21 +26,6 @@ class Customers extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/customers'; 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. * Test route registration.
* *
@ -148,12 +128,12 @@ class Customers extends WC_REST_Unit_Test_Case {
$product->set_regular_price( 25 ); $product->set_regular_price( 25 );
$product->save(); $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_status( 'processing' );
$order->set_total( 100 ); $order->set_total( 100 );
$order->save(); $order->save();
\WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); QueueHelper::run_all_pending();
$request = new WP_REST_Request( 'GET', $this->endpoint ); $request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( array( 'per_page' => 10 ) ); $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'] ); $this->assertEquals( $admin_id, $reports[0]['user_id'] );
// Creating a customer should show up regardless of orders. // 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 = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( $request->set_query_params(
@ -194,9 +174,6 @@ class Customers extends WC_REST_Unit_Test_Case {
public function test_get_reports() { public function test_get_reports() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
\WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper::reset_stats_dbs();
$test_customers = array(); $test_customers = array();
$customer_names = array( 'Alice', 'Betty', 'Catherine', 'Dan', 'Eric', 'Fred', 'Greg', 'Henry', 'Ivan', 'Justin' ); $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++ ) { for ( $i = 1; $i <= 10; $i++ ) {
$name = $customer_names[ $i - 1 ]; $name = $customer_names[ $i - 1 ];
$email = 'customer+' . strtolower( $name ) . '@example.com'; $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->set_first_name( $name );
$customer->save(); $customer->save();
$test_customers[] = $customer; $test_customers[] = $customer;
} }
// Create a test product for use in an order. // 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_name( 'Test Product' );
$product->set_regular_price( 25 ); $product->set_regular_price( 25 );
$product->save(); $product->save();
// Place an order for the first test customer. // 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_status( 'processing' );
$order->set_total( 100 ); $order->set_total( 100 );
$order->save(); $order->save();
\WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); QueueHelper::run_all_pending();
$request = new WP_REST_Request( 'GET', $this->endpoint ); $request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( $request->set_query_params(
@ -342,8 +319,6 @@ class Customers extends WC_REST_Unit_Test_Case {
* Test customer first and last name. * Test customer first and last name.
*/ */
public function test_customer_name() { public function test_customer_name() {
wp_set_current_user( $this->user );
$customer = wp_insert_user( $customer = wp_insert_user(
array( array(
'user_login' => 'daenerys', 'user_login' => 'daenerys',
@ -353,7 +328,7 @@ class Customers extends WC_REST_Unit_Test_Case {
); );
// Test shipping name and empty billing name. // 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_first_name( '' );
$order->set_billing_last_name( '' ); $order->set_billing_last_name( '' );
$order->set_shipping_first_name( 'Daenerys' ); $order->set_shipping_first_name( 'Daenerys' );
@ -362,7 +337,7 @@ class Customers extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); $order->set_total( 100 );
$order->save(); $order->save();
\WooCommerce\RestApi\UnitTests\Helpers\QueueHelper::run_all_pending(); QueueHelper::run_all_pending();
$request = new WP_REST_Request( 'GET', $this->endpoint ); $request = new WP_REST_Request( 'GET', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
@ -379,7 +354,7 @@ class Customers extends WC_REST_Unit_Test_Case {
$order->save(); $order->save();
do_action( 'woocommerce_update_customer', $customer ); 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 = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( array( 'orderby' => 'username' ) ); // Cache busting. $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 ); 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 = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( array( 'orderby' => 'name' ) ); // Cache busting. $request->set_query_params( array( 'orderby' => 'name' ) ); // Cache busting.

View File

@ -9,10 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
/** /**
* Reports Customers Stats REST API Test Class * Reports Customers Stats REST API Test Class
@ -20,7 +17,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class DownloadStats extends WC_REST_Unit_Test_Case { class DownloadStats extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -29,19 +26,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/downloads/stats'; 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. * Test route registration.
*/ */
@ -56,8 +40,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case {
*/ */
public function test_get_report() { public function test_get_report() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$prod_download = new \WC_Product_Download(); $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() { public function test_get_report_with_user_filter() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
$time = time(); $time = time();
// First set of data. // First set of data.
@ -236,8 +217,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case {
*/ */
public function test_get_report_orderby() { public function test_get_report_orderby() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$prod_download = new \WC_Product_Download(); $prod_download = new \WC_Product_Download();
@ -346,8 +325,6 @@ class DownloadStats extends WC_REST_Unit_Test_Case {
* Test reports schema. * Test reports schema.
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -9,10 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
/** /**
* Reports Customers Stats REST API Test Class * Reports Customers Stats REST API Test Class
@ -20,7 +17,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Downloads extends WC_REST_Unit_Test_Case { class Downloads extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -29,19 +26,6 @@ class Downloads extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/downloads'; 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. * Test route registration.
*/ */
@ -56,8 +40,6 @@ class Downloads extends WC_REST_Unit_Test_Case {
*/ */
public function test_get_report() { public function test_get_report() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$prod_download = new \WC_Product_Download(); $prod_download = new \WC_Product_Download();
@ -112,8 +94,7 @@ class Downloads extends WC_REST_Unit_Test_Case {
*/ */
public function filter_setup() { public function filter_setup() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
$time = time(); $time = time();
// First set of data. // First set of data.
@ -402,8 +383,6 @@ class Downloads extends WC_REST_Unit_Test_Case {
* Test reports schema. * Test reports schema.
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -9,10 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
/** /**
* Reports Customers Stats REST API Test Class * Reports Customers Stats REST API Test Class
@ -20,7 +17,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Import extends WC_REST_Unit_Test_Case { class Import extends AbstractReportsTest {
/** /**
* Endpoint. * Endpoint.

View File

@ -9,13 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
/** /**
* Class OrderStats * Class OrderStats
*/ */
class OrderStats extends WC_REST_Unit_Test_Case { class OrderStats extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -24,21 +23,6 @@ class OrderStats extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/orders/stats'; 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. * Test route registration.
* *
@ -56,8 +40,6 @@ class OrderStats extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
// @todo Update after report interface is done. // @todo Update after report interface is done.
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) ); $response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$reports = $response->get_data(); $reports = $response->get_data();
@ -85,8 +67,6 @@ class OrderStats extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,11 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
/** /**
* Reports Orders REST API Test Class * Reports Orders REST API Test Class
@ -22,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Orders extends WC_REST_Unit_Test_Case { class Orders extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -31,21 +27,6 @@ class Orders extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/orders'; 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. * Test route registration.
* *
@ -63,11 +44,8 @@ class Orders extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$product = new WC_Product_Simple(); $product = new \WC_Product_Simple();
$product->set_name( 'Test Product' ); $product->set_name( 'Test Product' );
$product->set_regular_price( 25 ); $product->set_regular_price( 25 );
$product->save(); $product->save();
@ -117,8 +95,6 @@ class Orders extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -9,16 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
/** /**
* PerformanceIndicators * PerformanceIndicators
*/ */
class PerformanceIndicators extends WC_REST_Unit_Test_Case { class PerformanceIndicators extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -27,19 +23,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/performance-indicators'; 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. * Test route registration.
*/ */
@ -55,8 +38,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case {
*/ */
public function test_get_indicators() { public function test_get_indicators() {
global $wpdb; 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. // Populate all of the data. We'll create an order and a download.
$prod_download = new \WC_Product_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() { public function test_get_indicators_empty_request() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
$time = time(); $time = time();
$request = new WP_REST_Request( 'GET', $this->endpoint ); $request = new WP_REST_Request( 'GET', $this->endpoint );
@ -159,8 +138,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case {
* Test schema. * Test schema.
*/ */
public function test_indicators_schema() { public function test_indicators_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();
@ -178,8 +155,6 @@ class PerformanceIndicators extends WC_REST_Unit_Test_Case {
* Test schema for /allowed indicators endpoint. * Test schema for /allowed indicators endpoint.
*/ */
public function test_indicators_schema_allowed() { public function test_indicators_schema_allowed() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint . '/allowed' ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint . '/allowed' );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,16 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
/** /**
* Class ProductStats * Class ProductStats
*/ */
class ProductStats extends WC_REST_Unit_Test_Case { class ProductStats extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -28,21 +24,6 @@ class ProductStats extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/products/stats'; 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. * Test route registration.
* *
@ -60,9 +41,6 @@ class ProductStats extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports() { public function test_get_reports() {
ReportsHelper::reset_stats_dbs();
wp_set_current_user( $this->user );
// Populate all of the data. // Populate all of the data.
$product = new \WC_Product_Simple(); $product = new \WC_Product_Simple();
$product->set_name( 'Test Product' ); $product->set_name( 'Test Product' );
@ -144,8 +122,6 @@ class ProductStats extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,10 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
/** /**
* Reports Products REST API Test Class * Reports Products REST API Test Class
@ -21,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Products extends WC_REST_Unit_Test_Case { class Products extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -30,21 +27,6 @@ class Products extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/products'; 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. * Test route registration.
* *
@ -62,9 +44,6 @@ class Products extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$product = new \WC_Product_Simple(); $product = new \WC_Product_Simple();
$product->set_name( 'Test Product' ); $product->set_name( 'Test Product' );
@ -99,9 +78,6 @@ class Products extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports_products_param() { public function test_get_reports_products_param() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$product = new \WC_Product_Simple(); $product = new \WC_Product_Simple();
$product->set_name( 'Test Product' ); $product->set_name( 'Test Product' );
@ -166,8 +142,6 @@ class Products extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,13 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
/** /**
* Class RevenueStats * Class RevenueStats
*/ */
class RevenueStats extends WC_REST_Unit_Test_Case { class RevenueStats extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -32,21 +31,6 @@ class RevenueStats extends WC_REST_Unit_Test_Case {
*/ */
protected $orders = array(); 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. * Test route registration.
* *

View File

@ -10,9 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
/** /**
* Reports Customers Stats REST API Test Class * Reports Customers Stats REST API Test Class
@ -20,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Stock extends WC_REST_Unit_Test_Case { class Stock extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -29,19 +27,6 @@ class Stock extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/stock'; 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. * Test route registration.
*/ */
@ -55,9 +40,6 @@ class Stock extends WC_REST_Unit_Test_Case {
* Test getting reports. * Test getting reports.
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$low_stock = new \WC_Product_Simple(); $low_stock = new \WC_Product_Simple();
$low_stock->set_name( 'Test low stock' ); $low_stock->set_name( 'Test low stock' );
@ -111,8 +93,6 @@ class Stock extends WC_REST_Unit_Test_Case {
* Test reports schema. * Test reports schema.
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -9,14 +9,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
/** /**
* Class StockStats * Class StockStats
*/ */
class StockStats extends WC_REST_Unit_Test_Case { class StockStats extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -25,19 +23,6 @@ class StockStats extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/stock/stats'; 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. * Test route registration.
*/ */
@ -51,9 +36,6 @@ class StockStats extends WC_REST_Unit_Test_Case {
* Test getting reports. * Test getting reports.
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
$number_of_low_stock = 3; $number_of_low_stock = 3;
for ( $i = 1; $i <= $number_of_low_stock; $i++ ) { for ( $i = 1; $i <= $number_of_low_stock; $i++ ) {
$low_stock = new \WC_Product_Simple(); $low_stock = new \WC_Product_Simple();
@ -128,8 +110,6 @@ class StockStats extends WC_REST_Unit_Test_Case {
* Test reports schema. * Test reports schema.
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,16 +10,12 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
/** /**
* TaxStats * TaxStats
*/ */
class TaxStats extends WC_REST_Unit_Test_Case { class TaxStats extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -28,21 +24,6 @@ class TaxStats extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/taxes/stats'; 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. * Test route registration.
* *
@ -61,11 +42,9 @@ class TaxStats extends WC_REST_Unit_Test_Case {
*/ */
public function test_get_reports() { public function test_get_reports() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$tax = WC_Tax::_insert_tax_rate( $tax = \WC_Tax::_insert_tax_rate(
array( array(
'tax_rate_country' => 'US', 'tax_rate_country' => 'US',
'tax_rate_state' => '', 'tax_rate_state' => '',
@ -143,8 +122,6 @@ class TaxStats extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,11 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
/** /**
* Reports Customers Stats REST API Test Class * Reports Customers Stats REST API Test Class
@ -22,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\QueueHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Taxes extends WC_REST_Unit_Test_Case { class Taxes extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -31,21 +27,6 @@ class Taxes extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/taxes'; 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. * Test route registration.
* *
@ -64,8 +45,6 @@ class Taxes extends WC_REST_Unit_Test_Case {
*/ */
public function test_get_reports() { public function test_get_reports() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$product = new \WC_Product_Simple(); $product = new \WC_Product_Simple();
@ -132,8 +111,6 @@ class Taxes extends WC_REST_Unit_Test_Case {
*/ */
public function test_get_reports_taxes_param() { public function test_get_reports_taxes_param() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$product = new \WC_Product_Simple(); $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() { public function test_get_reports_orderby_tax_rate() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
$wpdb->insert( $wpdb->insert(
$wpdb->prefix . 'woocommerce_tax_rates', $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() { public function test_get_reports_orderby_tax_code() {
global $wpdb; global $wpdb;
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
$wpdb->insert( $wpdb->insert(
$wpdb->prefix . 'woocommerce_tax_rates', $wpdb->prefix . 'woocommerce_tax_rates',
@ -354,8 +327,6 @@ class Taxes extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -10,10 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
use \WP_REST_Request;
use \WooCommerce\RestApi\UnitTests\Helpers\ReportsHelper;
use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
/** /**
* Reports Customers Stats REST API Test Class * Reports Customers Stats REST API Test Class
@ -21,7 +18,7 @@ use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
* @package WooCommerce\Tests\API * @package WooCommerce\Tests\API
* @since 3.5.0 * @since 3.5.0
*/ */
class Variations extends WC_REST_Unit_Test_Case { class Variations extends AbstractReportsTest {
/** /**
* Endpoints. * Endpoints.
@ -30,21 +27,6 @@ class Variations extends WC_REST_Unit_Test_Case {
*/ */
protected $endpoint = '/wc/v4/reports/variations'; 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. * Test route registration.
* *
@ -62,9 +44,6 @@ class Variations extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports() { public function test_get_reports() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$variation = new \WC_Product_Variation(); $variation = new \WC_Product_Variation();
$variation->set_name( 'Test Variation' ); $variation->set_name( 'Test Variation' );
@ -102,9 +81,6 @@ class Variations extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_get_reports_variations_param() { public function test_get_reports_variations_param() {
wp_set_current_user( $this->user );
ReportsHelper::reset_stats_dbs();
// Populate all of the data. // Populate all of the data.
$variation = new \WC_Product_Variation(); $variation = new \WC_Product_Variation();
$variation->set_name( 'Test Variation' ); $variation->set_name( 'Test Variation' );
@ -177,8 +153,6 @@ class Variations extends WC_REST_Unit_Test_Case {
* @since 3.5.0 * @since 3.5.0
*/ */
public function test_reports_schema() { public function test_reports_schema() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); $request = new WP_REST_Request( 'OPTIONS', $this->endpoint );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
$data = $response->get_data(); $data = $response->get_data();

View File

@ -11,6 +11,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WC_REST_Unit_Test_Case; use \WC_REST_Unit_Test_Case;
use \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper;
class Settings extends WC_REST_Unit_Test_Case { class Settings extends WC_REST_Unit_Test_Case {
@ -19,8 +20,7 @@ class Settings extends WC_REST_Unit_Test_Case {
*/ */
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->endpoint = new WC_REST_Setting_Options_Controller(); SettingsHelper::register();
\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register();
$this->user = $this->factory->user->create( $this->user = $this->factory->user->create(
array( array(
'role' => 'administrator', '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' ) ); $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/settings' ) );
$this->assertEquals( 500, $response->get_status() ); $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 $controller
->expects( $this->any() ) ->expects( $this->any() )
->method( 'get_group_settings' ) ->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 $controller
->expects( $this->any() ) ->expects( $this->any() )

View File

@ -19,7 +19,7 @@ class ShippingMethods extends WC_REST_Unit_Test_Case {
*/ */
public function setUp() { public function setUp() {
parent::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( $this->user = $this->factory->user->create(
array( array(
'role' => 'administrator', 'role' => 'administrator',

View File

@ -10,6 +10,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case; use \WC_REST_Unit_Test_Case;
class ShippingZones extends 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() { public function setUp() {
parent::setUp(); parent::setUp();
$this->endpoint = new WC_REST_Shipping_Zones_Controller(); $this->user = $this->factory->user->create(
$this->user = $this->factory->user->create(
array( array(
'role' => 'administrator', 'role' => 'administrator',
) )
@ -44,7 +44,7 @@ class ShippingZones extends WC_REST_Unit_Test_Case {
* @return WC_Shipping_Zone * @return WC_Shipping_Zone
*/ */
protected function create_shipping_zone( $name, $order = 0, $locations = array() ) { 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_name( $name );
$zone->set_zone_order( $order ); $zone->set_zone_order( $order );
$zone->set_locations( $locations ); $zone->set_locations( $locations );

View File

@ -9,6 +9,7 @@ namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case; use \WC_REST_Unit_Test_Case;
/** /**
@ -24,8 +25,7 @@ class SystemStatus extends WC_REST_Unit_Test_Case {
*/ */
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->endpoint = new WC_REST_System_Status_Controller(); $this->user = $this->factory->user->create(
$this->user = $this->factory->user->create(
array( array(
'role' => 'administrator', '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( get_option( 'woocommerce_db_version' ), $database['wc_database_version'] );
$this->assertEquals( $wpdb->prefix, $database['database_prefix'] ); $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( '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 ) ); $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 * This way it is not necessary to perform a regular request to an external server which would
* significantly slow down the tests. * significantly slow down the tests.
* *