Fix unit tests for the LookupDataStore class
This commit is contained in:
parent
d3131a67e6
commit
2fe8cce9b0
|
@ -37,15 +37,6 @@ class LookupDataStore {
|
|||
*/
|
||||
private $is_feature_visible;
|
||||
|
||||
/**
|
||||
* Does the lookup table exist?
|
||||
*
|
||||
* TODO: Remove once the lookup table is created via data migration.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $lookup_table_exists;
|
||||
|
||||
/**
|
||||
* LookupDataStore constructor. Makes the feature hidden by default.
|
||||
*/
|
||||
|
@ -55,8 +46,6 @@ class LookupDataStore {
|
|||
$this->lookup_table_name = $wpdb->prefix . 'wc_product_attributes_lookup';
|
||||
$this->is_feature_visible = false;
|
||||
|
||||
$this->lookup_table_exists = $this->check_lookup_table_exists();
|
||||
|
||||
$this->init_hooks();
|
||||
}
|
||||
|
||||
|
@ -194,7 +183,7 @@ AND table_name = %s;',
|
|||
* @param null|array $changeset Changes as provided by 'get_changes' method in the product object, null if it's being created.
|
||||
*/
|
||||
public function on_product_changed( $product, $changeset = null ) {
|
||||
if ( ! $this->lookup_table_exists ) {
|
||||
if ( ! $this->check_lookup_table_exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -253,7 +242,7 @@ AND table_name = %s;',
|
|||
* @param int $action The action to perform, one of the ACTION_ constants.
|
||||
*/
|
||||
private function run_update_callback( int $product_id, int $action ) {
|
||||
if ( ! $this->lookup_table_exists ) {
|
||||
if ( ! $this->check_lookup_table_exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -346,7 +335,7 @@ AND table_name = %s;',
|
|||
* @param int|\WC_Product $product Product object or product id.
|
||||
*/
|
||||
public function on_product_deleted( $product ) {
|
||||
if ( ! $this->lookup_table_exists ) {
|
||||
if ( ! $this->check_lookup_table_exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,14 @@ class LookupDataStoreTest extends \WC_Unit_Test_Case {
|
|||
*/
|
||||
private $lookup_table_name;
|
||||
|
||||
/**
|
||||
* Runs after all the tests in the class.
|
||||
*/
|
||||
public static function tearDownAfterClass() {
|
||||
parent::tearDownAfterClass();
|
||||
wc_get_container()->get( DataRegenerator::class )->delete_all_attributes_lookup_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs before each test.
|
||||
*/
|
||||
|
@ -40,19 +48,15 @@ class LookupDataStoreTest extends \WC_Unit_Test_Case {
|
|||
$this->lookup_table_name = $wpdb->prefix . 'wc_product_attributes_lookup';
|
||||
$this->sut = new LookupDataStore();
|
||||
|
||||
// Initiating regeneration with a fake queue will just create the lookup table in the database.
|
||||
add_filter(
|
||||
'woocommerce_queue_class',
|
||||
function() {
|
||||
return FakeQueue::class;
|
||||
}
|
||||
);
|
||||
$this->get_instance_of( DataRegenerator::class )->initiate_regeneration();
|
||||
|
||||
$queue = WC()->get_instance_of( \WC_Queue::class );
|
||||
$queue->clear_methods_called();
|
||||
|
||||
$this->reset_legacy_proxy_mocks();
|
||||
$this->register_legacy_proxy_class_mocks(
|
||||
array(
|
||||
\WC_Queue::class => new FakeQueue(),
|
||||
)
|
||||
);
|
||||
|
||||
// Initiating regeneration with a fake queue will just create the lookup table in the database.
|
||||
$this->get_instance_of( DataRegenerator::class )->initiate_regeneration();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue