Make WordPress Core

Ticket #37207: 37207.2.diff

File 37207.2.diff, 1.6 KB (added by mboynes, 9 years ago)

Only restore query vars if not running core unit tests

  • tests/phpunit/includes/bootstrap.php

     
    8686// Delete any default posts & related data
    8787_delete_all_posts();
    8888
     89// Store query vars to reset after each test
     90$GLOBALS['wp_bootstrapped'] = clone $GLOBALS['wp'];
     91
    8992require dirname( __FILE__ ) . '/testcase.php';
    9093require dirname( __FILE__ ) . '/testcase-rest-api.php';
    9194require dirname( __FILE__ ) . '/testcase-xmlrpc.php';
  • tests/phpunit/includes/functions.php

     
    161161
    162162        return $uploads;
    163163}
     164
     165/**
     166 * Restore the global `$wp`'s query vars back to the state after WP was loaded.
     167 */
     168function _restore_wp_query_vars() {
     169        $GLOBALS['wp']->public_query_vars  = $GLOBALS['wp_bootstrapped']->public_query_vars;
     170        $GLOBALS['wp']->private_query_vars = $GLOBALS['wp_bootstrapped']->private_query_vars;
     171}
  • tests/phpunit/includes/testcase.php

     
    151151                }
    152152                $wp_query = new WP_Query();
    153153                $wp = new WP();
     154                if ( ! defined( 'WP_RUN_CORE_TESTS' ) || ! WP_RUN_CORE_TESTS ) {
     155                        _restore_wp_query_vars();
     156                }
    154157                $post = null;
    155158                remove_theme_support( 'html5' );
    156159                remove_filter( 'query', array( $this, '_create_temporary_tables' ) );