Tests: Disable `foreign_key_checks` while dropping existing tables.

To ensure a clean run, the test suite drops all tables before installing, by simply looping over the table list and dropping them if they exist. This works well for Core, but may fail when a plugin has created a table with foreign key constraints in a previous test run.

Many plugins choose to base their test suite on the Core setup, so making life easier for them is a plus, even if Core doesn't directly need this change.

Props javorszky.

Fixes #37046.



git-svn-id: https://develop.svn.wordpress.org/trunk@37654 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2016-06-08 03:03:16 +00:00
parent 6da085cfe4
commit 5c4a15d0fc
1 changed files with 2 additions and 0 deletions

View File

@ -40,6 +40,7 @@ $wpdb->select( DB_NAME, $wpdb->dbh );
echo "Installing..." . PHP_EOL;
$wpdb->query( "SET foreign_key_checks = 0" );
foreach ( $wpdb->tables() as $table => $prefixed_table ) {
$wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
}
@ -51,6 +52,7 @@ foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
if ( $multisite )
$wpdb->$table = $prefixed_table;
}
$wpdb->query( "SET foreign_key_checks = 1" );
// Prefill a permalink structure so that WP doesn't try to determine one itself.
add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );