Reduce slow reports tests (#51279)

* Fix slow tests

* Lint

* Changelog

* Lint

* Lint
This commit is contained in:
Miguel Pérez Pellicer 2024-09-12 13:07:28 +04:00 committed by GitHub
parent ed9742f18b
commit c96f9f38bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 120 additions and 108 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Fix slow test for Reports

View File

@ -13,36 +13,42 @@
class WC_Helper_Queue {
/**
* Get all pending queued actions.
*
* @param string|null $group Optionally. Filter the actions by group.
* @return array Pending jobs.
*/
public static function get_all_pending() {
$jobs = WC()->queue()->search(
array(
'per_page' => -1,
'status' => 'pending',
'claimed' => false,
)
public static function get_all_pending( $group = null ) {
$args = array(
'per_page' => -1,
'status' => 'pending',
'claimed' => false,
);
return $jobs;
if ( $group ) {
$args['group'] = $group;
}
return WC()->queue()->search( $args );
}
/**
* Run all pending queued actions.
*
* @param string|null $group Optionally. Filter the actions by group.
* @return void
*/
public static function run_all_pending() {
public static function run_all_pending( $group = null ) {
$queue_runner = new ActionScheduler_QueueRunner();
while ( $jobs = self::get_all_pending() ) {
$jobs = self::get_all_pending( $group );
while ( $jobs ) {
foreach ( $jobs as $job_id => $job ) {
$queue_runner->process_action( $job_id );
}
$jobs = self::get_all_pending( $group );
}
}
/**
* Cancel all pending actions.
*

View File

@ -51,7 +51,7 @@ class WC_Admin_Tests_API_ProductsLowInStock extends WC_REST_Unit_Test_Case {
$order->save();
// Sync analytics data (used for last order date).
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', '/wc-analytics/products/low-in-stock' );
$request->set_param( 'low_in_stock', true );

View File

@ -66,7 +66,7 @@ class WC_Admin_Tests_API_Reports_Categories extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); // $25 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$uncategorized_term = get_term_by( 'slug', 'uncategorized', 'product_cat' );
@ -114,7 +114,7 @@ class WC_Admin_Tests_API_Reports_Categories extends WC_REST_Unit_Test_Case {
$product->set_category_ids( array( $second_category_id ) );
$product->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$uncategorized_term = get_term_by( 'slug', 'uncategorized', 'product_cat' );
@ -170,7 +170,7 @@ class WC_Admin_Tests_API_Reports_Categories extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); // $25 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Populate all of the data.
$product = new WC_Product_Simple();
@ -186,7 +186,7 @@ class WC_Admin_Tests_API_Reports_Categories extends WC_REST_Unit_Test_Case {
$order->set_total( 400 ); // $100 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$uncategorized_term = get_term_by( 'slug', 'uncategorized', 'product_cat' );
$params = array(

View File

@ -87,7 +87,7 @@ class WC_Admin_Tests_API_Reports_Coupons_Stats extends WC_REST_Unit_Test_Case {
$order_2c->set_date_created( $time );
$order_2c->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(

View File

@ -82,7 +82,7 @@ class WC_Admin_Tests_API_Reports_Coupons extends WC_REST_Unit_Test_Case {
$order_2c->calculate_totals();
$order_2c->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$coupon_reports = $response->get_data();
@ -132,7 +132,7 @@ class WC_Admin_Tests_API_Reports_Coupons extends WC_REST_Unit_Test_Case {
$order_1c->calculate_totals();
$order_1c->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(

View File

@ -127,7 +127,7 @@ class WC_Admin_Tests_API_Reports_Customers_Stats extends WC_REST_Unit_Test_Case
$order->set_total( 9.12 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$response = $this->server->dispatch( $request );

View File

@ -149,7 +149,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_total( 100 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( array( 'per_page' => 10 ) );
@ -164,7 +164,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
// Creating a customer should show up regardless of orders.
$customer = WC_Helper_Customer::create_customer( 'customer', 'password', 'customer@example.com' );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(
@ -221,7 +221,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_total( 100 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(
@ -317,7 +317,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->save();
// Ensure order customer data is synced to lookup table.
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$query_params = array(
'force_cache_refresh' => true,
@ -400,7 +400,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$customer->set_billing_city( '' );
$customer->set_first_name( 'customer_andrei_1' );
$customer->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request->set_query_params(
array(
@ -433,7 +433,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
// Test filter_empty param by state and postcode non empty.
$customer = WC_Helper_Customer::create_customer( 'customer_2', 'password', 'customer_2@example.com' );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request->set_query_params(
array(
@ -498,7 +498,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_total( 100 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$response = $this->server->dispatch( $request );
@ -527,7 +527,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_total( 100 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$response = $this->server->dispatch( $request );
@ -555,7 +555,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_total( 100 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$response = $this->server->dispatch( $request );
@ -584,7 +584,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
// Creating a customer should show up regardless of orders.
$customer = WC_Helper_Customer::create_customer( 'deleteme', 'password', 'deleteme@example.com' );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(
@ -602,7 +602,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
// Delete the user associated with the customer.
wp_delete_user( $customer->get_id() );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Verify they are gone.
$request = new WP_REST_Request( 'GET', $this->endpoint );
@ -630,7 +630,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_total( 100 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// update order info.
$order->set_billing_city( 'Random' );
@ -638,11 +638,11 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_billing_postcode( '54321' );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$result = CustomersDataStore::sync_order_customer( $order->get_id() );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$this->assertNotEquals( -1, $result );
@ -671,7 +671,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order2->set_total( 100 );
$order2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$customer_id = CustomersDataStore::get_existing_customer_id_from_order( $order );
$customer2_id = CustomersDataStore::get_existing_customer_id_from_order( $order2 );
@ -682,11 +682,11 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_billing_postcode( '54321' );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$result = CustomersDataStore::sync_order_customer( $order->get_id() );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Didn't update anything.
$this->assertTrue( -1 === $result );
@ -721,7 +721,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order3->set_billing_email( 'different@example.org' );
$order3->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$customer_id = CustomersDataStore::get_existing_customer_id_from_order( $order );
$customer2_id = CustomersDataStore::get_existing_customer_id_from_order( $order2 );
@ -734,11 +734,11 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order3->set_billing_postcode( '54321' );
$order3->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$result = CustomersDataStore::sync_order_customer( $order3->get_id() );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Didn't update anything.
$this->assertNotEquals( -1, $result );
@ -780,7 +780,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order3->set_total( 100 );
$order3->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$customer_id = CustomersDataStore::get_existing_customer_id_from_order( $order );
$customer2_id = CustomersDataStore::get_existing_customer_id_from_order( $order2 );
@ -794,7 +794,7 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
$order->set_date_created( time() + 60 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$latest_order = CustomersDataStore::get_last_order( $customer_id );

View File

@ -152,7 +152,7 @@ class WC_Admin_Tests_API_Reports_Downloads_Stats extends WC_REST_Unit_Test_Case
$order->save();
$order_1 = $order->get_id();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$download = new WC_Customer_Download();
$download->set_user_id( 1 );

View File

@ -169,7 +169,7 @@ class WC_Admin_Tests_API_Reports_Downloads extends WC_REST_Unit_Test_Case {
$object->set_timestamp( gmdate( 'Y-m-d H:00:00', $time - ( 2 * DAY_IN_SECONDS ) ) );
$id = $object->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
return array(
'time' => $time,

View File

@ -119,7 +119,7 @@ class WC_Admin_Tests_API_Reports_Export extends WC_REST_Unit_Test_Case {
$order->calculate_totals();
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Initiate an export of the taxes report.
$response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc-analytics/reports/taxes/export' ) );
@ -143,7 +143,7 @@ class WC_Admin_Tests_API_Reports_Export extends WC_REST_Unit_Test_Case {
$this->assertStringMatchesFormat( '%s/wc-analytics/reports/taxes/export/%d/status', $status['_links']['self'][0]['href'] );
// Run the pending export jobs.
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Check that the status shows 100% and includes a download url.
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $status_route ) );

View File

@ -119,7 +119,7 @@ class WC_Admin_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 'success', $report['status'] );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', '/wc-analytics/reports/customers' );
$response = $this->server->dispatch( $request );
@ -161,7 +161,7 @@ class WC_Admin_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 'success', $report['status'] );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', '/wc-analytics/reports/customers' );
$response = $this->server->dispatch( $request );
@ -247,7 +247,7 @@ class WC_Admin_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
}
// Check that stats exist before deleting.
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', '/wc-analytics/reports/orders' );
$request->set_query_params( array( 'per_page' => 25 ) );
@ -273,7 +273,7 @@ class WC_Admin_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 'success', $report['status'] );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Check that stats have been deleted.
$request = new WP_REST_Request( 'GET', '/wc-analytics/reports/orders' );
@ -375,7 +375,7 @@ class WC_Admin_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
$this->assertEquals( 0, $report['orders']['imported'] );
$this->assertEquals( 4, $report['orders']['total'] );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Test import status after processing.
$request = new WP_REST_Request( 'GET', $this->endpoint . '/status' );

View File

@ -154,7 +154,7 @@ class WC_Admin_Tests_API_Reports_Orders_Stats extends WC_REST_Unit_Test_Case {
$global_attribute = new WC_Product_Attribute();
$global_attribute->set_id( $size_attr_id );
$global_attribute->set_name( 'pa_size' );
$global_attribute->set_options( array( $large_term->term_id ) ); // Set to small.
$global_attribute->set_options( array( $large_term->term_id ) ); // Set to large.
$global_attribute->set_position( 1 );
$global_attribute->set_visible( true );
$global_attribute->set_variation( false );
@ -187,7 +187,8 @@ class WC_Admin_Tests_API_Reports_Orders_Stats extends WC_REST_Unit_Test_Case {
$order->save();
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
WC_Helper_Queue::run_all_pending( 'woocommerce-db-updates' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( array( 'per_page' => 15 ) );

View File

@ -69,7 +69,7 @@ class WC_Admin_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); // $25 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$expected_customer_id = CustomersDataStore::get_customer_id_by_user_id( 1 );
@ -126,7 +126,7 @@ class WC_Admin_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
)
);
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$reports = $response->get_data();
@ -238,7 +238,8 @@ class WC_Admin_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
$order->save();
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
WC_Helper_Queue::run_all_pending( 'woocommerce-db-updates' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( array( 'per_page' => 15 ) );
@ -369,7 +370,7 @@ class WC_Admin_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
$order->save();
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params( array( 'per_page' => 15 ) );
@ -438,7 +439,7 @@ class WC_Admin_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
$order_to_be_included->set_status( 'completed' );
$order_to_be_included->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Test product exclusion.
$request = new WP_REST_Request( 'GET', $this->endpoint );
@ -515,7 +516,7 @@ class WC_Admin_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
$second_order->set_status( 'on-hold' );
$second_order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Get the created orders from REST API.
$request = new WP_REST_Request( 'GET', $this->endpoint );

View File

@ -90,7 +90,7 @@ class WC_Admin_Tests_API_Reports_Performance_Indicators extends WC_REST_Unit_Tes
$object->set_user_ip_address( '1.2.3.4' );
$object->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$time = time();
$request = new WP_REST_Request( 'GET', $this->endpoint );

View File

@ -71,7 +71,7 @@ class WC_Admin_Tests_API_Reports_Products_Stats extends WC_REST_Unit_Test_Case {
$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(

View File

@ -67,7 +67,7 @@ class WC_Admin_Tests_API_Reports_Products extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); // $25 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$reports = $response->get_data();
@ -109,7 +109,7 @@ class WC_Admin_Tests_API_Reports_Products extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); // $25 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(

View File

@ -99,7 +99,7 @@ class WC_Admin_Tests_API_Reports_Taxes_Stats extends WC_REST_Unit_Test_Case {
$wc_refund = wc_create_refund( $refund );
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$reports = $response->get_data();

View File

@ -115,7 +115,7 @@ class WC_Admin_Tests_API_Reports_Taxes extends WC_REST_Unit_Test_Case {
)
);
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$reports = $response->get_data();
@ -416,6 +416,6 @@ class WC_Admin_Tests_API_Reports_Taxes extends WC_REST_Unit_Test_Case {
)
);
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
}
}

View File

@ -69,7 +69,7 @@ class WC_Admin_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); // $25 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$reports = $response->get_data();
@ -102,7 +102,7 @@ class WC_Admin_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case {
$order->set_total( 15 );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(
@ -146,7 +146,7 @@ class WC_Admin_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case {
$order->set_total( 100 ); // $25 x 4.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(

View File

@ -57,7 +57,7 @@ class WC_Admin_Tests_Reports_Coupons_Stats extends WC_Unit_Test_Case {
$order_2c->calculate_totals();
$order_2c->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new CouponsStatsDataStore();
$start_time = gmdate( 'Y-m-d 00:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -133,7 +133,7 @@ class WC_Admin_Tests_Reports_Coupons_Stats extends WC_Unit_Test_Case {
// Delete the coupon.
$coupon_1->delete( true );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$start_time = gmdate( 'Y-m-d 00:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = gmdate( 'Y-m-d 23:59:59', $order->get_date_created()->getOffsetTimestamp() );

View File

@ -59,7 +59,7 @@ class WC_Admin_Tests_Reports_Coupons extends WC_Unit_Test_Case {
$order_2c->calculate_totals();
$order_2c->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new CouponsDataStore();
$start_time = gmdate( 'Y-m-d 00:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -375,7 +375,7 @@ class WC_Admin_Tests_Reports_Coupons extends WC_Unit_Test_Case {
// Delete the coupons.
$coupon_2->delete( true );
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new CouponsDataStore();
$start_time = gmdate( 'Y-m-d 00:00:00', $order->get_date_created()->getOffsetTimestamp() );

View File

@ -29,7 +29,7 @@ class WC_Admin_Tests_Reports_Customer extends WC_Unit_Test_Case {
$product->set_regular_price( 25 );
$product->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$customer_id = DataStore::get_customer_id_by_user_id( $customer->get_id() ); // This is the customer ID from lookup table.
@ -39,7 +39,7 @@ class WC_Admin_Tests_Reports_Customer extends WC_Unit_Test_Case {
$order->save();
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Customer should have 3 orders.
$this->assertSame( 3, DataStore::get_order_count( $customer_id ) );
@ -75,7 +75,7 @@ class WC_Admin_Tests_Reports_Customer extends WC_Unit_Test_Case {
$product2->set_regular_price( 2 );
$product2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Create the first order.
$order1 = WC_Helper_Order::create_order( $customer->get_id(), $product1 );
@ -85,7 +85,7 @@ class WC_Admin_Tests_Reports_Customer extends WC_Unit_Test_Case {
$order2 = WC_Helper_Order::create_order( $customer->get_id(), $product2 );
$order2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$customer_id = DataStore::get_customer_id_by_user_id( $customer->get_id() ); // This is the customer ID from lookup table.

View File

@ -63,7 +63,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
)
);
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersStatsDataStore();
@ -208,7 +208,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order->save();
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersStatsDataStore();
@ -377,7 +377,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
)
);
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersStatsDataStore();
@ -666,7 +666,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$orders[] = $order;
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersStatsDataStore();
@ -917,7 +917,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
}
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersStatsDataStore();
@ -3865,7 +3865,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order->apply_coupon( $coupon );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Check if lookup tables are populated.
foreach ( $tables as $table ) {
@ -3996,7 +3996,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order_2->calculate_totals();
$order_2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersStatsDataStore();
@ -4544,7 +4544,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$orders[] = $order;
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersStatsDataStore();
@ -5328,7 +5328,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$orders[] = $order;
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
global $wpdb;
$res = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wc_order_stats" );
@ -6094,7 +6094,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order_0->set_total( 100 );
$order_0->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$start_time = gmdate( 'Y-m-d H:00:00', $order_0->get_date_created()->getOffsetTimestamp() );
$end_time = gmdate( 'Y-m-d H:59:59', $order_0->get_date_created()->getOffsetTimestamp() );
@ -6114,7 +6114,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order_1->set_total( 100 );
$order_1->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Time frame includes both orders -> customer is a new customer.
$start_time = gmdate( 'Y-m-d H:00:00', $order_0->get_date_created()->getOffsetTimestamp() );
@ -6153,7 +6153,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order_2->set_total( 100 );
$order_2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Time frame includes second and third order -> there is one returning customer.
$start_time = gmdate( 'Y-m-d H:i:s', $order_0_time + 1 );
@ -6204,7 +6204,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order_0->set_total( 100 );
$order_0->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$start_time = gmdate( 'Y-m-d H:00:00', $order_0->get_date_created()->getOffsetTimestamp() );
$end_time = gmdate( 'Y-m-d H:59:59', $order_0->get_date_created()->getOffsetTimestamp() );
@ -6224,7 +6224,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order_1->set_total( 100 );
$order_1->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Time frame includes both orders -> customer is a new customer.
$start_time = gmdate( 'Y-m-d H:00:00', $order_0->get_date_created()->getOffsetTimestamp() );
@ -6263,7 +6263,7 @@ class WC_Admin_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order_2->set_total( 100 );
$order_2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// Time frame includes second and third order -> there is one returning customer.
$start_time = gmdate( 'Y-m-d H:i:s', $order_0_time + 1 );

View File

@ -64,7 +64,7 @@ class WC_Admin_Tests_Reports_Orders extends WC_Unit_Test_Case {
$order->set_status( 'completed' );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -143,7 +143,7 @@ class WC_Admin_Tests_Reports_Orders extends WC_Unit_Test_Case {
)
);
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -255,7 +255,7 @@ class WC_Admin_Tests_Reports_Orders extends WC_Unit_Test_Case {
$order2->set_status( 'completed' );
$order2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new OrdersDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -310,7 +310,7 @@ class WC_Admin_Tests_Reports_Orders extends WC_Unit_Test_Case {
$order_2->set_status( 'completed' );
$order_2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = gmdate( 'Y-m-d H:59:59', $order->get_date_created()->getOffsetTimestamp() );

View File

@ -42,7 +42,7 @@ class WC_Admin_Tests_Reports_Products extends WC_Unit_Test_Case {
$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new ProductsDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -119,7 +119,7 @@ class WC_Admin_Tests_Reports_Products extends WC_Unit_Test_Case {
$order_2->set_date_created( $date_created_2 );
$order_2->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new ProductsDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -220,7 +220,7 @@ class WC_Admin_Tests_Reports_Products extends WC_Unit_Test_Case {
$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new ProductsDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -301,7 +301,7 @@ class WC_Admin_Tests_Reports_Products extends WC_Unit_Test_Case {
$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new ProductsDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -383,7 +383,7 @@ class WC_Admin_Tests_Reports_Products extends WC_Unit_Test_Case {
break;
}
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new ProductsDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -441,7 +441,7 @@ class WC_Admin_Tests_Reports_Products extends WC_Unit_Test_Case {
$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$term = wp_insert_term( 'Unused Category', 'product_cat' );

View File

@ -43,7 +43,7 @@ class WC_Admin_Tests_Reports_Revenue_Stats extends WC_Unit_Test_Case {
$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
// /reports/revenue/stats is mapped to Orders_Data_Store.
$data_store = new OrdersStatsDataStore();

View File

@ -42,7 +42,7 @@ class WC_Admin_Tests_Reports_Variations extends WC_Unit_Test_Case {
$order->set_status( 'completed' );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new VariationsDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -111,7 +111,7 @@ class WC_Admin_Tests_Reports_Variations extends WC_Unit_Test_Case {
$order->set_status( 'completed' );
$order->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new VariationsDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
@ -228,7 +228,7 @@ class WC_Admin_Tests_Reports_Variations extends WC_Unit_Test_Case {
$order_3->set_status( 'completed' );
$order_3->save();
WC_Helper_Queue::run_all_pending();
WC_Helper_Queue::run_all_pending( 'wc-admin-data' );
$data_store = new VariationsDataStore();