From a314c6c2346939ad8f8aae2192957157f6423e91 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 18 Oct 2015 05:00:40 +0000 Subject: [PATCH] Preserve the public and private query var properties on the global `WP` instance when using `WP_UnitTestCase::go_to()`. These properties apply to the application state, not the current request. See #34346 git-svn-id: https://develop.svn.wordpress.org/trunk@35258 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 5d3a793e32..b666515d3f 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -126,7 +126,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { } function tearDown() { - global $wpdb, $wp_query, $post; + global $wpdb, $wp_query, $wp, $post; $wpdb->query( 'ROLLBACK' ); if ( is_multisite() ) { while ( ms_is_switched() ) { @@ -134,6 +134,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { } } $wp_query = new WP_Query(); + $wp = new WP(); $post = null; remove_theme_support( 'html5' ); remove_filter( 'query', array( $this, '_create_temporary_tables' ) ); @@ -419,7 +420,14 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']); $GLOBALS['wp_the_query'] = new WP_Query(); $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; + + $public_query_vars = $GLOBALS['wp']->public_query_vars; + $private_query_vars = $GLOBALS['wp']->private_query_vars; + $GLOBALS['wp'] = new WP(); + $GLOBALS['wp']->public_query_vars = $public_query_vars; + $GLOBALS['wp']->private_query_vars = $private_query_vars; + _cleanup_query_vars(); $GLOBALS['wp']->main($parts['query']);