From 183dc1a3478625c5d0421bdb3fee5beffa020d59 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 15 May 2022 15:55:11 +0000 Subject: [PATCH] Tests: Expand the test for conditional tags returning early if `$wp_query` is not set. When called too early, conditional query tags should throw a `_doing_it_wrong()` notice and return `false`. This commit verifies that behavior not only for `is_main_query()`, but for all the other conditional tags too. Follow-up to [16947], [17068], [17083], [18699], [37985], [53395]. See #55104. git-svn-id: https://develop.svn.wordpress.org/trunk@53396 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/query/conditionals.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index c4f31830d6..1bed9d0782 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -1618,12 +1618,28 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { /** * @ticket 55104 - * @expectedIncorrectUsage is_main_query */ - public function test_is_main_query_returns_false_if_wp_query_is_not_set() { + public function test_conditional_tags_trigger_doing_it_wrong_and_return_false_if_wp_query_is_not_set() { unset( $GLOBALS['wp_query'] ); - $this->assertFalse( is_main_query() ); + $functions = get_class_methods( 'WP_Query' ); + + foreach ( $functions as $function_name ) { + // Only test `is_*()` conditional tags. + if ( ! str_starts_with( $function_name, 'is_' ) ) { + continue; + } + + if ( 'is_comments_popup' === $function_name ) { + // `is_comments_popup()` is deprecated as of WP 4.5. + $this->setExpectedDeprecated( $function_name ); + } else { + // All the other functions should throw a `_doing_it_wrong()` notice. + $this->setExpectedIncorrectUsage( $function_name ); + } + + $this->assertFalse( call_user_func( $function_name ) ); + } } }