Fix failing `test_cancel_import` and `WC_Tests_API_Reports_Variations` php tests (https://github.com/woocommerce/woocommerce-admin/pull/8456)

* Assert the pending action explicitly to fix failing test_cancel_import with latest woo

* Use function lambda

* Fix WC_Tests_API_Reports_Variations by assigning parent_id to variations
This commit is contained in:
Chi-Hsuan Huang 2022-03-11 06:39:59 +08:00 committed by GitHub
parent 03c428969c
commit 7c8c0ee893
2 changed files with 22 additions and 2 deletions

View File

@ -200,7 +200,14 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
// Verify there are actions to cancel.
$pending_actions = WC_Helper_Queue::get_all_pending();
$this->assertCount( 2, $pending_actions ); // 1 for the user, 1 for order.
$pending_hooks = array_map(
function ( $action ) {
return $action->get_hook();
},
$pending_actions
);
$this->assertContains( 'wc-admin_import_orders', $pending_hooks );
$this->assertContains( 'wc-admin_import_customers', $pending_hooks );
// Cancel outstanding actions.
$request = new WP_REST_Request( 'POST', $this->endpoint . '/cancel' );
@ -212,7 +219,14 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
// Verify there are no pending actions.
$pending_actions = WC_Helper_Queue::get_all_pending();
$this->assertCount( 0, $pending_actions );
$pending_hooks = array_map(
function ( $action ) {
return $action->get_hook();
},
$pending_actions
);
$this->assertNotContains( 'wc-admin_import_orders', $pending_hooks );
$this->assertNotContains( 'wc-admin_import_customers', $pending_hooks );
}
/**

View File

@ -25,6 +25,9 @@ class WC_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case {
*/
public function setUp() {
parent::setUp();
$this->product = new WC_Product_Variable();
$this->product->set_name( 'Variable Product' );
$this->product->save();
$this->user = $this->factory->user->create(
array(
@ -55,6 +58,7 @@ class WC_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case {
// Populate all of the data.
$variation = new WC_Product_Variation();
$variation->set_parent_id( $this->product->get_id() );
$variation->set_name( 'Test Variation' );
$variation->set_regular_price( 25 );
$variation->set_attributes( array( 'color' => 'green' ) );
@ -95,12 +99,14 @@ class WC_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case {
// Populate all of the data.
$variation = new WC_Product_Variation();
$variation->set_parent_id( $this->product->get_id() );
$variation->set_name( 'Test Variation' );
$variation->set_regular_price( 25 );
$variation->set_attributes( array( 'color' => 'green' ) );
$variation->save();
$variation_2 = new WC_Product_Variation();
$variation_2->set_parent_id( $this->product->get_id() );
$variation_2->set_name( 'Test Variation 2' );
$variation_2->set_regular_price( 100 );
$variation_2->set_attributes( array( 'color' => 'red' ) );