mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Build/Test Tools: Reset main query object after each test.
This resets the main query variable, `$wp_the_query` during the `WP_UnitTestCase_Base::tear_down` method that runs after each PHPUnit test. This ensures any changes to the main query object is reset after each test to avoid cross contamination between tests, similar to how other globals are reset. Props flixos90, spacedmonkey, joemcgill. Fixes #58776. git-svn-id: https://develop.svn.wordpress.org/trunk@56212 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
598
package-lock.json
generated
598
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -142,15 +142,18 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
|
||||
* After a test method runs, resets any state in WordPress the test method might have changed.
|
||||
*/
|
||||
public function tear_down() {
|
||||
global $wpdb, $wp_query, $wp;
|
||||
global $wpdb, $wp_the_query, $wp_query, $wp;
|
||||
$wpdb->query( 'ROLLBACK' );
|
||||
if ( is_multisite() ) {
|
||||
while ( ms_is_switched() ) {
|
||||
restore_current_blog();
|
||||
}
|
||||
}
|
||||
$wp_query = new WP_Query();
|
||||
$wp = new WP();
|
||||
|
||||
// Reset query, main query, and WP globals similar to wp-settings.php.
|
||||
$wp_the_query = new WP_Query();
|
||||
$wp_query = $wp_the_query;
|
||||
$wp = new WP();
|
||||
|
||||
// Reset globals related to the post loop and `setup_postdata()`.
|
||||
$post_globals = array( 'post', 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages' );
|
||||
|
||||
@@ -25,9 +25,6 @@ class Tests_Query_IsTerm extends WP_UnitTestCase {
|
||||
public function set_up() {
|
||||
parent::set_up();
|
||||
|
||||
$GLOBALS['wp_the_query'] = new WP_Query();
|
||||
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
|
||||
|
||||
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
|
||||
create_initial_taxonomies();
|
||||
|
||||
Reference in New Issue
Block a user