WordPress.org

Make WordPress Core

Ticket #37207: 37207.diff

File 37207.diff, 1.6 KB (added by mboynes, 6 years ago)

Store $wp's query vars after bootstrap to restore on tearDown

  • 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

     
    154154
    155155        return $uploads;
    156156}
     157
     158/**
     159 * Restore the global `$wp`'s query vars back to the state after WP was loaded.
     160 */
     161function _restore_wp_query_vars() {
     162        $GLOBALS['wp']->public_query_vars  = $GLOBALS['wp_bootstrapped']->public_query_vars;
     163        $GLOBALS['wp']->private_query_vars = $GLOBALS['wp_bootstrapped']->private_query_vars;
     164}
  • tests/phpunit/includes/testcase.php

     
    146146                }
    147147                $wp_query = new WP_Query();
    148148                $wp = new WP();
     149                _restore_wp_query_vars();
    149150                $post = null;
    150151                remove_theme_support( 'html5' );
    151152                remove_filter( 'query', array( $this, '_create_temporary_tables' ) );