From d841231933bf41ba66442925b9b29059f9803b27 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 31 Aug 2020 03:57:50 +0000 Subject: [PATCH] Tests: Reset the `$wp_sitemap` global after each test, so that sitemaps are re-initialized when the next test runs. This ensures consistent results in query var tests, regardless of whether they are run in isolation or as part of a larger group of tests. Props pbiron, peterwilsoncc. Fixes #51154. git-svn-id: https://develop.svn.wordpress.org/trunk@48908 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 3 +++ tests/phpunit/tests/query/vars.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 9895bcf691..259d601f93 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -161,6 +161,9 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase { $GLOBALS[ $global ] = null; } + // Reset $wp_sitemap global so that sitemap-related dynamic $wp->public_query_vars are added when the next test runs. + $GLOBALS['wp_sitemaps'] = null; + $this->unregister_all_meta_keys(); remove_theme_support( 'html5' ); remove_filter( 'query', array( $this, '_create_temporary_tables' ) ); diff --git a/tests/phpunit/tests/query/vars.php b/tests/phpunit/tests/query/vars.php index f644061da4..051fceb3ab 100644 --- a/tests/phpunit/tests/query/vars.php +++ b/tests/phpunit/tests/query/vars.php @@ -9,6 +9,7 @@ class Tests_Query_Vars extends WP_UnitTestCase { /** * @ticket 35115 + * @ticket 51154 */ public function testPublicQueryVarsAreAsExpected() { global $wp; @@ -70,6 +71,9 @@ class Tests_Query_Vars extends WP_UnitTestCase { // Dynamically added public query vars: 'post_format', 'rest_route', + 'sitemap', + 'sitemap-subtype', + 'sitemap-stylesheet', ), $wp->public_query_vars,