mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +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:
@@ -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' );
|
||||
|
||||
Reference in New Issue
Block a user