Make WordPress Core

Changeset 53396


Ignore:
Timestamp:
05/15/2022 03:55:11 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/conditionals.php

    r53395 r53396  
    16191619        /**
    16201620         * @ticket 55104
    1621          * @expectedIncorrectUsage is_main_query
    1622          */
    1623         public function test_is_main_query_returns_false_if_wp_query_is_not_set() {
     1621         */
     1622        public function test_conditional_tags_trigger_doing_it_wrong_and_return_false_if_wp_query_is_not_set() {
    16241623                unset( $GLOBALS['wp_query'] );
    16251624
    1626                 $this->assertFalse( is_main_query() );
     1625                $functions = get_class_methods( 'WP_Query' );
     1626
     1627                foreach ( $functions as $function_name ) {
     1628                        // Only test `is_*()` conditional tags.
     1629                        if ( ! str_starts_with( $function_name, 'is_' ) ) {
     1630                                continue;
     1631                        }
     1632
     1633                        if ( 'is_comments_popup' === $function_name ) {
     1634                                // `is_comments_popup()` is deprecated as of WP 4.5.
     1635                                $this->setExpectedDeprecated( $function_name );
     1636                        } else {
     1637                                // All the other functions should throw a `_doing_it_wrong()` notice.
     1638                                $this->setExpectedIncorrectUsage( $function_name );
     1639                        }
     1640
     1641                        $this->assertFalse( call_user_func( $function_name ) );
     1642                }
    16271643        }
    16281644
Note: See TracChangeset for help on using the changeset viewer.