From 2f5cad3ac6c96d966771236c99984a7ebfd3ac0b Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 13:29:10 -0500 Subject: [PATCH 01/20] Adds reset of current screen goals to base tearDown. --- tests/phpunit/includes/abstract-testcase.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 1c7fe55e6d652..1bad99bf18220 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -160,6 +160,15 @@ public function tearDown() { // Reset $wp_sitemap global so that sitemap-related dynamic $wp->public_query_vars are added when the next test runs. $GLOBALS['wp_sitemaps'] = null; + /* + * Reset globals related to current screen. + * Ticket #53431 + */ + $current_screen_globals = array( 'current_screen', 'taxnow', 'typenow' ); + foreach ( $current_screen_globals as $global ) { + $GLOBALS[ $global ] = null; + } + $this->unregister_all_meta_keys(); remove_theme_support( 'html5' ); remove_filter( 'query', array( $this, '_create_temporary_tables' ) ); From ac6222ba40202022a4d949e6acdc8f7b0d21e6e7 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 13:31:05 -0500 Subject: [PATCH 02/20] Removes current screen reset from Tests_Admin_includesPlugin. --- tests/phpunit/tests/admin/includesPlugin.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/phpunit/tests/admin/includesPlugin.php b/tests/phpunit/tests/admin/includesPlugin.php index cbbc181b460f1..e1154254b321e 100644 --- a/tests/phpunit/tests/admin/includesPlugin.php +++ b/tests/phpunit/tests/admin/includesPlugin.php @@ -97,8 +97,6 @@ function test_submenu_position( $position, $expected_position ) { // Clean up the temporary user. wp_delete_user( $admin_user ); - // Reset current screen. - set_current_screen( 'front' ); // Verify the menu was inserted at the expected position. $this->assertSame( 'custom-position', $submenu[ $parent ][ $expected_position ][2] ); @@ -207,8 +205,6 @@ function test_submenu_helpers_position( $position, $expected_position ) { // Clean up the temporary user. wp_delete_user( $admin_user ); - // Reset current screen. - set_current_screen( 'front' ); foreach ( $actual_positions as $test => $actual_position ) { // Verify the menu was inserted at the expected position. @@ -292,8 +288,6 @@ function test_position_when_parent_slug_child_slug_are_the_same() { // Clean up the temporary user. wp_set_current_user( $current_user ); wp_delete_user( $admin_user ); - // Reset current screen. - set_current_screen( 'front' ); // Verify the menu was inserted at the expected position. $this->assertSame( 'main_slug', $submenu['main_slug'][0][2] ); @@ -325,8 +319,6 @@ function test_passing_string_as_position_fires_doing_it_wrong() { // Clean up the temporary user. wp_set_current_user( $current_user ); wp_delete_user( $admin_user ); - // Reset current screen. - set_current_screen( 'front' ); // Verify the menu was inserted at the expected position. $this->assertSame( 'submenu_page_1', $submenu['main_slug'][1][2] ); From 379a4054e365c8ba555929c918717c2926546bcf Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 13:43:33 -0500 Subject: [PATCH 03/20] Adds inline documentation for the base reset circuit to explain the reasoning. --- tests/phpunit/includes/abstract-testcase.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 1bad99bf18220..9ff3354bf9708 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -161,8 +161,14 @@ public function tearDown() { $GLOBALS['wp_sitemaps'] = null; /* - * Reset globals related to current screen. - * Ticket #53431 + * 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' )` 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? It saves instantiating an instance of WP_Screen, + * making 2 method calls, and firing of the `current_screen` action. */ $current_screen_globals = array( 'current_screen', 'taxnow', 'typenow' ); foreach ( $current_screen_globals as $global ) { From 0848ffe54d5bb0ed7dffa0f6dab4a07878cd542b Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 13:49:10 -0500 Subject: [PATCH 04/20] Removes current screen reset from Tests_Adminbar. --- tests/phpunit/tests/adminbar.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index 2004e30ae3f52..31d6a4667be5d 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -400,8 +400,6 @@ public function test_admin_bar_has_no_archives_link_if_no_static_front_page() { $wp_admin_bar = $this->get_standard_admin_bar(); $node = $wp_admin_bar->get_node( 'archive' ); - set_current_screen( 'front' ); - $this->assertNull( $node ); } @@ -415,8 +413,6 @@ public function test_admin_bar_contains_view_archive_link_if_static_front_page() $wp_admin_bar = $this->get_standard_admin_bar(); $node = $wp_admin_bar->get_node( 'archive' ); - set_current_screen( 'front' ); - $this->assertNotNull( $node ); } @@ -429,8 +425,6 @@ public function test_admin_bar_has_no_archives_link_for_pages() { $wp_admin_bar = $this->get_standard_admin_bar(); $node = $wp_admin_bar->get_node( 'archive' ); - set_current_screen( 'front' ); - $this->assertNull( $node ); } @@ -508,7 +502,6 @@ public function test_admin_bar_has_no_archives_link_for_non_public_cpt() { $wp_admin_bar = $this->get_standard_admin_bar(); $node = $wp_admin_bar->get_node( 'archive' ); - set_current_screen( 'front' ); unregister_post_type( 'foo-non-public' ); $this->assertNull( $node ); @@ -532,7 +525,6 @@ public function test_admin_bar_has_no_archives_link_for_cpt_without_archive() { $wp_admin_bar = $this->get_standard_admin_bar(); $node = $wp_admin_bar->get_node( 'archive' ); - set_current_screen( 'front' ); unregister_post_type( 'foo-non-public' ); $this->assertNull( $node ); @@ -556,7 +548,6 @@ public function test_admin_bar_has_no_archives_link_for_cpt_not_shown_in_admin_b $wp_admin_bar = $this->get_standard_admin_bar(); $node = $wp_admin_bar->get_node( 'archive' ); - set_current_screen( 'front' ); unregister_post_type( 'foo-non-public' ); $this->assertNull( $node ); @@ -679,7 +670,6 @@ public function test_customize_link() { ); $wp_customize->start_previewing_theme(); - set_current_screen( 'front' ); $wp_admin_bar = $this->get_standard_admin_bar(); $node = $wp_admin_bar->get_node( 'customize' ); $this->assertNotEmpty( $node ); From b0d5be6953b7a16db76d8454a894b359cc327d26 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 13:49:49 -0500 Subject: [PATCH 05/20] Removes current screen reset from Tests_REST_API. --- tests/phpunit/tests/rest-api.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index f6e057ba8d89e..538d0f9d42c78 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -793,8 +793,6 @@ public function test_rest_url_scheme() { // Reset. update_option( 'siteurl', $_siteurl ); - set_current_screen( 'front' ); - } /** From 763b50b97c5c2186f64c55fcd7ddb3035cca406b Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 13:55:46 -0500 Subject: [PATCH 06/20] Removes global reset from Tests_URL. --- tests/phpunit/tests/url.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/phpunit/tests/url.php b/tests/phpunit/tests/url.php index 67240a73b40bc..9ecb7d90ac766 100644 --- a/tests/phpunit/tests/url.php +++ b/tests/phpunit/tests/url.php @@ -199,8 +199,6 @@ function data_home_urls() { } function test_home_url_from_admin() { - $screen = get_current_screen(); - // Pretend to be in the site admin. set_current_screen( 'dashboard' ); $home = get_option( 'home' ); @@ -243,13 +241,9 @@ function test_home_url_from_admin() { $this->assertSame( $home, home_url() ); update_option( 'home', set_url_scheme( $home, 'http' ) ); - - $GLOBALS['current_screen'] = $screen; } function test_network_home_url_from_admin() { - $screen = get_current_screen(); - // Pretend to be in the site admin. set_current_screen( 'dashboard' ); $home = network_home_url(); @@ -268,8 +262,6 @@ function test_network_home_url_from_admin() { $this->assertSame( $home, network_home_url() ); $_SERVER['HTTPS'] = 'on'; $this->assertSame( $home_https, network_home_url() ); - - $GLOBALS['current_screen'] = $screen; } function test_set_url_scheme() { From f76c19505a83b69de5bceaab9ebcb9c9e94b0aef Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:07:46 -0500 Subject: [PATCH 07/20] Removes reset from Tests_Admin_includesScreen. --- tests/phpunit/tests/admin/includesScreen.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index 09432dedca96e..d5d88c908c6fc 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -155,15 +155,8 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase { ), ); - function setUp() { - parent::setUp(); - set_current_screen( 'front' ); - } - function tearDown() { unset( $GLOBALS['wp_taxonomies']['old-or-new'] ); - unset( $GLOBALS['screen'] ); - unset( $GLOBALS['current_screen'] ); parent::tearDown(); } @@ -311,6 +304,7 @@ function test_help_tabs() { 'callback' => false, ); + set_current_screen( 'front' ); $screen = get_current_screen(); $screen->add_help_tab( $tab_args ); $this->assertSame( @@ -372,6 +366,7 @@ function test_help_tabs_priority() { // Don't include a priority. ); + set_current_screen( 'front' ); $screen = get_current_screen(); // Add help tabs. @@ -440,6 +435,7 @@ function test_options() { 'option' => $option, ); + set_current_screen( 'front' ); $screen = get_current_screen(); $screen->add_option( $option, $option_args ); @@ -456,8 +452,6 @@ function test_options() { } function test_in_admin() { - $screen = get_current_screen(); - set_current_screen( 'edit.php' ); $this->assertTrue( get_current_screen()->in_admin() ); $this->assertTrue( get_current_screen()->in_admin( 'site' ) ); @@ -481,8 +475,6 @@ function test_in_admin() { $this->assertFalse( get_current_screen()->in_admin( 'site' ) ); $this->assertFalse( get_current_screen()->in_admin( 'network' ) ); $this->assertFalse( get_current_screen()->in_admin( 'user' ) ); - - $GLOBALS['current_screen'] = $screen; } /** From 48f2137bff4f92e09d372565ef93d1e9202f78ab Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:11:52 -0500 Subject: [PATCH 08/20] Removes reset from Tests_Admin_includesTemplate. --- tests/phpunit/tests/admin/includesTemplate.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/phpunit/tests/admin/includesTemplate.php b/tests/phpunit/tests/admin/includesTemplate.php index 6cb6cda3d4244..48c5accf772e6 100644 --- a/tests/phpunit/tests/admin/includesTemplate.php +++ b/tests/phpunit/tests/admin/includesTemplate.php @@ -234,8 +234,6 @@ public function test_wp_add_dashboard_widget() { // This doesn't actually get removed due to the invalid priority. remove_meta_box( 'dashboard2', 'dashboard', 'normal' ); - - set_current_screen( 'front' ); } } From 058dab55d3d1910c6d5e6ebdec940caf029881ad Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:13:05 -0500 Subject: [PATCH 09/20] Removes reset from Tests_Dependencies_jQuery. --- tests/phpunit/tests/dependencies/jquery.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/phpunit/tests/dependencies/jquery.php b/tests/phpunit/tests/dependencies/jquery.php index 082d0e6bd00c8..f1ee89e853c03 100644 --- a/tests/phpunit/tests/dependencies/jquery.php +++ b/tests/phpunit/tests/dependencies/jquery.php @@ -82,8 +82,6 @@ function test_dont_allow_deregister_core_scripts_in_admin() { wp_deregister_script( $library ); $this->assertTrue( wp_script_is( $library, 'registered' ) ); } - - set_current_screen( 'front' ); } /** From 972f0f46eb23cb32ecc4621866fe289c97e43b29 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:14:00 -0500 Subject: [PATCH 10/20] Removes reset from Tests_L10n_GetUserLocale. --- tests/phpunit/tests/l10n/getUserLocale.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/phpunit/tests/l10n/getUserLocale.php b/tests/phpunit/tests/l10n/getUserLocale.php index f1d6f3828aa8f..eae697febc543 100644 --- a/tests/phpunit/tests/l10n/getUserLocale.php +++ b/tests/phpunit/tests/l10n/getUserLocale.php @@ -20,12 +20,6 @@ public function setUp() { wp_set_current_user( $this->user_id ); } - public function tearDown() { - set_current_screen( 'front' ); - - parent::tearDown(); - } - public function test_user_locale_property() { set_current_screen( 'dashboard' ); $this->assertSame( 'de_DE', get_user_locale() ); From ba8ad86e2782ba452b4dd0f24b25facfb3566075 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:15:28 -0500 Subject: [PATCH 11/20] Removes reset from Tests_L10n_LoadTextdomain. --- tests/phpunit/tests/l10n/loadTextdomain.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/phpunit/tests/l10n/loadTextdomain.php b/tests/phpunit/tests/l10n/loadTextdomain.php index ec54a0e6cd917..ef62106d0a6de 100644 --- a/tests/phpunit/tests/l10n/loadTextdomain.php +++ b/tests/phpunit/tests/l10n/loadTextdomain.php @@ -195,8 +195,6 @@ public function test_load_muplugin_textdomain_user_locale() { load_muplugin_textdomain( 'wp-tests-domain' ); - set_current_screen( 'front' ); - $this->assertSame( get_user_locale(), $this->locale ); } @@ -215,8 +213,6 @@ public function test_load_plugin_textdomain_user_locale() { load_plugin_textdomain( 'wp-tests-domain' ); - set_current_screen( 'front' ); - $this->assertSame( get_user_locale(), $this->locale ); } @@ -235,8 +231,6 @@ public function test_load_theme_textdomain_user_locale() { load_theme_textdomain( 'wp-tests-domain' ); - set_current_screen( 'front' ); - $this->assertSame( get_user_locale(), $this->locale ); } } From d49809ba138add1a720247ba2399b91b35f3874b Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:19:09 -0500 Subject: [PATCH 12/20] Removes reset from Tests_L10n_LoadTextdomainJustInTime. --- tests/phpunit/tests/l10n/loadTextdomainJustInTime.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php b/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php index dd380c3d0c11e..3619e8110c414 100644 --- a/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php +++ b/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php @@ -211,8 +211,6 @@ public function test_plugin_translation_with_user_locale() { $expected = i18n_plugin_test(); - set_current_screen( 'front' ); - $this->assertSame( 'Das ist ein Dummy Plugin', $expected ); } @@ -228,7 +226,6 @@ public function test_theme_translation_with_user_locale() { $expected = i18n_theme_test(); - set_current_screen( 'front' ); switch_theme( WP_DEFAULT_THEME ); $this->assertSame( 'Das ist ein Dummy Theme', $expected ); From 8b0480dacea2ff5e7dbacf3adf21fda8d7eb60de Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:20:29 -0500 Subject: [PATCH 13/20] Removes reset from Tests_L10n_wpLocalSwitcher. --- tests/phpunit/tests/l10n/wpLocaleSwitcher.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/phpunit/tests/l10n/wpLocaleSwitcher.php b/tests/phpunit/tests/l10n/wpLocaleSwitcher.php index 029bb2bc826c3..726863eeee784 100644 --- a/tests/phpunit/tests/l10n/wpLocaleSwitcher.php +++ b/tests/phpunit/tests/l10n/wpLocaleSwitcher.php @@ -284,8 +284,6 @@ public function test_switch_to_site_locale_if_user_locale_is_set() { $wp_locale_switcher = $locale_switcher; - set_current_screen( 'front' ); - $this->assertFalse( $locale_switched_user_locale ); $this->assertTrue( $locale_switched_site_locale ); $this->assertSame( $site_locale, $site_locale_after_switch ); @@ -335,8 +333,6 @@ public function test_switch_to_different_site_locale_if_user_locale_is_set() { $wp_locale_switcher = $locale_switcher; - set_current_screen( 'front' ); - remove_filter( 'locale', array( $this, 'filter_locale' ) ); $this->assertFalse( $locale_switched_user_locale ); @@ -382,8 +378,6 @@ public function test_multiple_switches_to_site_locale_and_user_locale() { $wp_locale_switcher = $locale_switcher; - set_current_screen( 'front' ); - $this->assertSame( 'en_US', get_locale() ); $this->assertSame( 'This is a dummy plugin', $expected ); } From 9f515df38d173334a20c270c162478e6867f409c Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:24:11 -0500 Subject: [PATCH 14/20] Removes reset from Tests_Post_Attachments. --- tests/phpunit/tests/post/attachments.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php index 0a03d77ed6c0b..7b03d4b7f2ccf 100644 --- a/tests/phpunit/tests/post/attachments.php +++ b/tests/phpunit/tests/post/attachments.php @@ -410,9 +410,6 @@ public function test_wp_get_attachment_url_should_not_force_https_when_administe $url = wp_get_attachment_url( $attachment_id ); - // Cleanup. - set_current_screen( 'front' ); - $this->assertSame( set_url_scheme( $url, 'http' ), $url ); } @@ -438,7 +435,6 @@ public function test_wp_get_attachment_url_should_force_https_when_administering $url = wp_get_attachment_url( $attachment_id ); // Cleanup. - set_current_screen( 'front' ); remove_filter( 'upload_dir', '_upload_dir_https' ); $this->assertSame( 'https', parse_url( $url, PHP_URL_SCHEME ) ); From 426aba7ccfa6beffd2df34504e37dceab7fa89a7 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:29:39 -0500 Subject: [PATCH 15/20] Removes reset from Tests_Query_Conditionals. --- tests/phpunit/tests/query/conditionals.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index c4f36bee8ec16..2fb22f50c72af 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -17,8 +17,6 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { function setUp() { parent::setUp(); - set_current_screen( 'front' ); - update_option( 'comments_per_page', 5 ); update_option( 'posts_per_page', 5 ); From c770535d43ca57b860fec6abed7107fe65aa6d13 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:30:33 -0500 Subject: [PATCH 16/20] Removes reset from Tests_Query_IsTerm. --- tests/phpunit/tests/query/isTerm.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/phpunit/tests/query/isTerm.php b/tests/phpunit/tests/query/isTerm.php index 77d7a597d9ede..822d57147c140 100644 --- a/tests/phpunit/tests/query/isTerm.php +++ b/tests/phpunit/tests/query/isTerm.php @@ -25,8 +25,6 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { function setUp() { parent::setUp(); - set_current_screen( 'front' ); - $GLOBALS['wp_the_query'] = new WP_Query(); $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; From 61af82230d9b9331662d61247ed90c2bab4d6078 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:31:25 -0500 Subject: [PATCH 17/20] Removes reset from Tests_Query_PostStatus. --- tests/phpunit/tests/query/postStatus.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/phpunit/tests/query/postStatus.php b/tests/phpunit/tests/query/postStatus.php index 7d4a236b50fc7..ffa0aaf3fb037 100644 --- a/tests/phpunit/tests/query/postStatus.php +++ b/tests/phpunit/tests/query/postStatus.php @@ -211,7 +211,6 @@ public function test_protected_should_be_included_when_in_the_admin() { ); $this->assertContains( "post_status = 'foo", $q->request ); - set_current_screen( 'front' ); } public function test_private_statuses_should_be_included_when_current_user_can_read_private_posts() { From 9fc057fe3b4771f14a27021209f780743891bde6 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:46:36 -0500 Subject: [PATCH 18/20] Removes alternative reset implementations. --- .../tests/menu/wpAjaxMenuQuickSearch.php | 26 ------------------- .../phpunit/tests/user/wpSendUserRequest.php | 3 --- 2 files changed, 29 deletions(-) diff --git a/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php b/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php index ed9c2cf25ab02..232b729c231d2 100644 --- a/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php +++ b/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php @@ -5,32 +5,6 @@ */ class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase { - /** - * Current screen. - * - * @var mixed - */ - protected $current_screen; - - /** - * Set up. Workaround set_current_screen( null ) not working due to $hook_suffix not being set. - */ - function setUp() { - parent::setUp(); - - global $current_screen; - $this->current_screen = $current_screen; - } - - /** - * Tear down. Workaround set_current_screen( null ) not working due to $hook_suffix not being set. - */ - function tearDown() { - global $current_screen; - $current_screen = $this->current_screen; - parent::tearDown(); - } - /** * Test search returns results for pages. * diff --git a/tests/phpunit/tests/user/wpSendUserRequest.php b/tests/phpunit/tests/user/wpSendUserRequest.php index 0b4d19af80040..d3ab88793947c 100644 --- a/tests/phpunit/tests/user/wpSendUserRequest.php +++ b/tests/phpunit/tests/user/wpSendUserRequest.php @@ -79,9 +79,6 @@ public function tearDown() { reset_phpmailer_instance(); unset( $GLOBALS['locale'] ); - unset( $GLOBALS['current_screen'] ); - unset( $GLOBALS['taxnow'] ); - unset( $GLOBALS['typenow'] ); restore_previous_locale(); parent::tearDown(); From a538457bfb0d4eff7184f5c68ad5f05cf90f6ee6 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Jun 2021 14:51:52 -0500 Subject: [PATCH 19/20] Improves inline doc. --- tests/phpunit/includes/abstract-testcase.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 9ff3354bf9708..69fa2f3088e19 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -162,13 +162,14 @@ public function tearDown() { /* * 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' )` as a reset. + * 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? It saves instantiating an instance of WP_Screen, - * making 2 method calls, and firing of the `current_screen` action. + * Performance (faster test runs with less memory usage). How so? For each test, it saves instantiating an instance + * of WP_Screen, making 2 method calls, and firing of the `current_screen` action. */ $current_screen_globals = array( 'current_screen', 'taxnow', 'typenow' ); foreach ( $current_screen_globals as $global ) { From 35808948e8b7db54b77506a2eeb021a2ee97a4b8 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Tue, 22 Jun 2021 18:11:01 -0500 Subject: [PATCH 20/20] Replaces "front" with "edit.php" as front would not have tabs or options. --- tests/phpunit/tests/admin/includesScreen.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index d5d88c908c6fc..1eab0827bca82 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -304,7 +304,7 @@ function test_help_tabs() { 'callback' => false, ); - set_current_screen( 'front' ); + set_current_screen( 'edit.php' ); $screen = get_current_screen(); $screen->add_help_tab( $tab_args ); $this->assertSame( @@ -366,7 +366,7 @@ function test_help_tabs_priority() { // Don't include a priority. ); - set_current_screen( 'front' ); + set_current_screen( 'edit.php' ); $screen = get_current_screen(); // Add help tabs. @@ -435,7 +435,7 @@ function test_options() { 'option' => $option, ); - set_current_screen( 'front' ); + set_current_screen( 'edit.php' ); $screen = get_current_screen(); $screen->add_option( $option, $option_args );