Fix unit tests after merging from trunk

This commit is contained in:
Nestor Soriano 2021-03-12 09:50:21 +01:00
parent d820fbe4a7
commit 65c1c9ec54
No known key found for this signature in database
GPG Key ID: 08110F3518C12CAD
2 changed files with 11 additions and 15 deletions

View File

@ -435,9 +435,11 @@ class WC_Settings_Products extends WC_Settings_Page {
public function save() {
$this->save_settings_for_current_section();
// Any time we update the product settings, we should flush the term count cache.
$tools_controller = WC()->get_instance_of( WC_REST_System_Status_Tools_Controller::class );
$tools_controller->execute_tool( 'recount_terms' );
/*
* Product->Inventory has a setting `Out of stock visibility`.
* Because of this, we need to recount the terms to keep them in-sync.
*/
WC()->call_function( 'wc_recount_all_terms' );
$this->do_update_options_action();
}

View File

@ -148,25 +148,19 @@ class WC_Settings_Products_Test extends WC_Settings_Unit_Test_Case {
* @testdox 'save' flushes the term count cache.
*/
public function test_save_does_recount_terms() {
// phpcs:disable Squiz.Commenting
$mock_tools_controller = new class() {
public $tool_executed;
$wc_recount_all_terms_called = false;
public function execute_tool( $tool ) {
$this->tool_executed = $tool;
}
};
// phpcs:enable Squiz.Commenting
$this->register_legacy_proxy_class_mocks(
$this->register_legacy_proxy_function_mocks(
array(
'WC_REST_System_Status_Tools_Controller' => $mock_tools_controller,
'wc_recount_all_terms' => function() use ( &$wc_recount_all_terms_called ) {
$wc_recount_all_terms_called = true;
},
)
);
$sut = new WC_Settings_Products();
$sut->save();
$this->assertEquals( 'recount_terms', $mock_tools_controller->tool_executed );
$this->assertTrue( $wc_recount_all_terms_called );
}
}