Re-implement the flushing of the term count cache that was lost on merge

Also add unit tests for it.
This commit is contained in:
Nestor Soriano 2021-02-02 09:31:11 +01:00
parent 8a60e7e147
commit e5f234ec0f
No known key found for this signature in database
GPG Key ID: 08110F3518C12CAD
2 changed files with 39 additions and 0 deletions

View File

@ -428,6 +428,19 @@ class WC_Settings_Products extends WC_Settings_Page {
return apply_filters( 'woocommerce_downloadable_products_settings', $settings );
}
/**
* Save settings and trigger the 'woocommerce_update_options_'.id action.
*/
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' );
$this->do_update_options_action();
}
}
return new WC_Settings_Products();

View File

@ -143,4 +143,30 @@ class WC_Settings_Products_Test extends WC_Settings_Unit_Test_Case {
$this->assertEquals( $expected, $settings_ids_and_types );
}
/**
* @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;
public function execute_tool( $tool ) {
$this->tool_executed = $tool;
}
};
// phpcs:enable Squiz.Commenting
$this->register_legacy_proxy_class_mocks(
array(
'WC_REST_System_Status_Tools_Controller' => $mock_tools_controller,
)
);
$sut = new WC_Settings_Products();
$sut->save();
$this->assertEquals( 'recount_terms', $mock_tools_controller->tool_executed );
}
}