diff --git a/plugins/woocommerce-admin/tests/api/reports-import.php b/plugins/woocommerce-admin/tests/api/reports-import.php index f3678863618..0621fb61c61 100644 --- a/plugins/woocommerce-admin/tests/api/reports-import.php +++ b/plugins/woocommerce-admin/tests/api/reports-import.php @@ -202,6 +202,10 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case { $order->set_date_created( time() - ( 3 * DAY_IN_SECONDS ) ); $order->save(); + // Verify there are actions to cancel. + $pending_actions = WC_Helper_Queue::get_all_pending(); + $this->assertCount( 1, $pending_actions ); + // Cancel outstanding actions. $request = new WP_REST_Request( 'POST', $this->endpoint . '/cancel' ); $response = $this->server->dispatch( $request ); @@ -209,15 +213,9 @@ class WC_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(); - // @todo It may be better to compare against outstanding actions - // pulled from the import API once #1850 is complete. - $request = new WP_REST_Request( 'GET', '/wc/v4/reports/orders' ); - $response = $this->server->dispatch( $request ); - $reports = $response->get_data(); - - $this->assertEquals( 200, $response->get_status() ); - $this->assertCount( 0, $reports ); + // Verify there are no pending actions. + $pending_actions = WC_Helper_Queue::get_all_pending(); + $this->assertCount( 0, $pending_actions ); } } diff --git a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php index 57b5c779c71..f3aea96da3f 100644 --- a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php +++ b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-queue.php @@ -12,11 +12,11 @@ */ class WC_Helper_Queue { /** - * Run all pending queued actions. + * Get all pending queued actions. * - * @return void + * @return array Pending jobs. */ - public static function run_all_pending() { + public static function get_all_pending() { $jobs = WC()->queue()->search( array( 'per_page' => -1, @@ -25,6 +25,17 @@ class WC_Helper_Queue { ) ); + return $jobs; + } + + /** + * Run all pending queued actions. + * + * @return void + */ + public static function run_all_pending() { + $jobs = self::get_all_pending(); + foreach ( $jobs as $job ) { $job->execute(); }