From 9ab7f4b1448fee7ab62c764bccff923cdbc82ba8 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 1 Jul 2014 18:51:46 +0000 Subject: [PATCH] Avoid polluted `$table_prefix` and `$_wp_switched_stack` in multisite unit tests. Add `WP_TESTS_TABLE_PREFIX` in `bootstrap.php` to ensure the original value for `$table_prefix` is always available. Props jeremyfelt. Fixes #28692. git-svn-id: https://develop.svn.wordpress.org/trunk@28943 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/bootstrap.php | 1 + tests/phpunit/includes/testcase.php | 5 +++++ tests/phpunit/tests/ms.php | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 74e3654050..830ff8e5b2 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -23,6 +23,7 @@ if ( !is_readable( $config_file_path ) ) { } require_once $config_file_path; +define( 'WP_TESTS_TABLE_PREFIX', $table_prefix ); define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' ); if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 345c7492d0..b7149fcbb2 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -35,6 +35,11 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { global $wpdb, $wp_query, $post; $this->expectedDeprecated(); $wpdb->query( 'ROLLBACK' ); + if ( is_multisite() ) { + while ( ms_is_switched() ) { + restore_current_blog(); + } + } $wp_query = new WP_Query(); $post = null; remove_theme_support( 'html5' ); diff --git a/tests/phpunit/tests/ms.php b/tests/phpunit/tests/ms.php index 11ec9c96b4..185133d1e6 100644 --- a/tests/phpunit/tests/ms.php +++ b/tests/phpunit/tests/ms.php @@ -1510,8 +1510,9 @@ class Tests_MS extends WP_UnitTestCase { * @param string $path REQUEST_URI of the boot strap request. */ function _setup_host_request( $domain, $path ) { - global $current_site, $current_blog, $wpdb, $table_prefix; + global $current_site, $current_blog, $table_prefix; + $table_prefix = WP_TESTS_TABLE_PREFIX; $current_site = $current_blog = null; $_SERVER['HTTP_HOST'] = $domain; $_SERVER['REQUEST_URI'] = $path;