Rewrite WC_Tests_Install::test_get_tables()

Instead of comparing all tables that exist with all tables that are registered with `WC_Install::get_tables()` (which was only introduced a few versions ago in #19436), rewrite the test to verify that all of the tables *registered* actually exist within the database.

This will prevent tests from failing when, for example, they're run against databases that may or may not have additional plugins installed/activated. This also prevents tests from failing when running WooCommerce 4.x (e.g. with WooCommerce Admin) on WordPress < 5.3, since the tables are created but the callback to register the custom tables is never hooked.
This commit is contained in:
Steve Grunwell 2020-03-12 15:00:03 +00:00
parent 5855931542
commit 7f74eace0b
1 changed files with 10 additions and 3 deletions

View File

@ -122,12 +122,19 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
global $wpdb;
$tables = $wpdb->get_col(
"SHOW TABLES WHERE `Tables_in_{$wpdb->dbname}` LIKE '{$wpdb->prefix}woocommerce\_%' OR `Tables_in_{$wpdb->dbname}` LIKE '{$wpdb->prefix}wc\_%'"
"SHOW TABLES WHERE `Tables_in_{$wpdb->dbname}` LIKE '{$wpdb->prefix}woocommerce\_%'
OR `Tables_in_{$wpdb->dbname}` LIKE '{$wpdb->prefix}wc\_%'"
);
$result = WC_Install::get_tables();
sort( $result );
$diff = array_diff( $result, $tables );
$this->assertEquals( $tables, $result );
$this->assertEmpty(
$diff,
sprintf(
'The following table(s) were returned from WC_Install::get_tables() but do not exist: %s',
implode( ', ', $diff )
)
);
}
/**