Add import cancel tests

This commit is contained in:
Joshua Flowers 2019-04-12 16:42:25 +08:00 committed by Jeff Stieler
parent cad94415c5
commit 61492c5f10
1 changed files with 35 additions and 0 deletions

View File

@ -185,4 +185,39 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'completed', $reports[0]['status'] ); $this->assertEquals( 'completed', $reports[0]['status'] );
} }
/**
* Test cancelling import actions.
*/
public function test_cancel_import() {
wp_set_current_user( $this->user );
// Populate all of the data.
$product = new WC_Product_Simple();
$product->set_name( 'Test Product' );
$product->set_regular_price( 25 );
$product->save();
$order = WC_Helper_Order::create_order( 1, $product );
$order->set_status( 'completed' );
$order->set_date_created( time() - ( 3 * DAY_IN_SECONDS ) );
$order->save();
// Cancel outstanding actions.
$request = new WP_REST_Request( 'POST', $this->endpoint . '/cancel' );
$response = $this->server->dispatch( $request );
$report = $response->get_data();
$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 );
}
} }