Fix table creation detection in DataRegeneratorTest

This commit is contained in:
Nestor Soriano 2021-05-05 11:50:43 +02:00
parent f53f959d03
commit 9dcdfddc15
No known key found for this signature in database
GPG Key ID: 08110F3518C12CAD
1 changed files with 5 additions and 3 deletions

View File

@ -94,9 +94,11 @@ class DataRegeneratorTest extends \WC_Unit_Test_Case {
$this->sut->initiate_regeneration();
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $this->lookup_table_name ) );
$this->assertEquals( $this->lookup_table_name, $wpdb->get_var( $query ) );
// Try to insert a row to verify that the table exists.
// We can't use the regular table existence detection mechanisms because PHPUnit creates all tables as temporary.
$wpdb->query( 'INSERT INTO ' . $this->lookup_table_name . " VALUES (1, 1, 'taxonomy', 1, 1, 1 )" );
$value = $wpdb->get_var( 'SELECT product_id FROM ' . $this->lookup_table_name . ' LIMIT 1' );
$this->assertEquals( 1, $value );
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
}