mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 14:50:29 +00:00
Tests: Reset $current_screen global between tests to avoid cross-test interdependencies.
This provides a consistent global starting state for tests that interact with admin screens. Individual tests no longer need to invoke `set_current_screen( 'front' )` (or an alternative implementation) as a reset. Follow-up to [29251], [29860], [31046], [36721], [38678], [48908], [50433]. Props hellofromTonya, johnbillion. Fixes #53431. git-svn-id: https://develop.svn.wordpress.org/trunk@51419 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -157,7 +157,27 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
|
||||
$GLOBALS[ $global ] = null;
|
||||
}
|
||||
|
||||
// Reset $wp_sitemap global so that sitemap-related dynamic $wp->public_query_vars are added when the next test runs.
|
||||
/*
|
||||
* Reset globals related to current screen to provide a consistent global starting state
|
||||
* for tests that interact with admin screens. Replaces the need for individual tests
|
||||
* to invoke `set_current_screen( 'front' )` (or an alternative implementation) as a reset.
|
||||
*
|
||||
* The globals are from `WP_Screen::set_current_screen()`.
|
||||
*
|
||||
* Why not invoke `set_current_screen( 'front' )`?
|
||||
* Performance (faster test runs with less memory usage). How so? For each test,
|
||||
* it saves creating an instance of WP_Screen, making two method calls,
|
||||
* and firing of the `current_screen` action.
|
||||
*/
|
||||
$current_screen_globals = array( 'current_screen', 'taxnow', 'typenow' );
|
||||
foreach ( $current_screen_globals as $global ) {
|
||||
$GLOBALS[ $global ] = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset $wp_sitemap global so that sitemap-related dynamic $wp->public_query_vars
|
||||
* are added when the next test runs.
|
||||
*/
|
||||
$GLOBALS['wp_sitemaps'] = null;
|
||||
|
||||
$this->unregister_all_meta_keys();
|
||||
|
||||
Reference in New Issue
Block a user