Make WordPress Core

Changeset 26006


Ignore:
Timestamp:
11/04/2013 10:46:44 PM (13 years ago)
Author:
wonderboymusic
Message:

WP_UnitTestCase::go_to() tried its best to clean up global space, but ultimately fell short. Because it was blowing away WP every time it was called, it was dropping all the query vars that were registered for custom taxonomies and custom post types (ouch).

Introduces _cleanup_query_vars(). This is a prerequisite for the unit tests on #20767. All unit tests pass with this change.

See #20767.
Fixes #25818.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp.php

    r25991 r26006  
    606606                $this->handle_404();
    607607                $this->register_globals();
    608                
     608
    609609                /**
    610610                 * Fires once the WordPress environment has been set up.
  • trunk/tests/phpunit/includes/testcase.php

    r26005 r26006  
    187187                $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
    188188                $GLOBALS['wp'] = new WP();
    189 
    190                 // clean out globals to stop them polluting wp and wp_query
    191                 foreach ($GLOBALS['wp']->public_query_vars as $v) {
    192                         unset($GLOBALS[$v]);
    193                 }
    194                 foreach ($GLOBALS['wp']->private_query_vars as $v) {
    195                         unset($GLOBALS[$v]);
    196                 }
     189                _cleanup_query_vars();
    197190
    198191                $GLOBALS['wp']->main($parts['query']);
  • trunk/tests/phpunit/includes/utils.php

    r25254 r26006  
    364364        unset( $GLOBALS['wp_taxonomies'][$taxonomy_name] );
    365365}
     366
     367function _cleanup_query_vars() {
     368        // clean out globals to stop them polluting wp and wp_query
     369        foreach ( $GLOBALS['wp']->public_query_vars as $v )
     370                unset( $GLOBALS[$v] );
     371
     372        foreach ( $GLOBALS['wp']->private_query_vars as $v )
     373                unset( $GLOBALS[$v] );
     374
     375        foreach ( get_taxonomies( array() , 'objects' ) as $t ) {
     376                if ( ! empty( $t->query_var ) )
     377                        $GLOBALS['wp']->add_query_var( $t->query_var );
     378        }
     379
     380        foreach ( get_post_types( array() , 'objects' ) as $t ) {
     381                if ( ! empty( $t->query_var ) )
     382                        $GLOBALS['wp']->add_query_var( $t->query_var );
     383        }
     384}
Note: See TracChangeset for help on using the changeset viewer.