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:
parent
8a60e7e147
commit
e5f234ec0f
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue