From 5c4a15d0fcd1e9763fccfdd31d4aac98345cf902 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 8 Jun 2016 03:03:16 +0000 Subject: [PATCH] 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 --- tests/phpunit/includes/install.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpunit/includes/install.php b/tests/phpunit/includes/install.php index f2c5c158d7..5db0cc1c5a 100644 --- a/tests/phpunit/includes/install.php +++ b/tests/phpunit/includes/install.php @@ -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' );