From 4af34e80376e7653dd75e1b9e88858ca82748eee Mon Sep 17 00:00:00 2001 From: David Stone Date: Tue, 14 Apr 2026 09:32:57 -0600 Subject: [PATCH] fix(tests): restore null screen state with unset in Dashboard_Widgets_Test finally blocks When no screen existed before a test, $original_screen_id is null. The old guard 'if ($original_screen_id)' is falsy for null, so the forced dashboard-network / dashboard screen leaked into subsequent tests. Fix: use 'if (null !== $original_screen_id)' and add an else branch that calls unset($GLOBALS['current_screen']) to restore the pre-test null state. Applies to both finally blocks (lines 165-167, 212-214). This is the WordPress-recommended approach for reverting to a null screen state in test environments (see wordpress-develop abstract-testcase.php). Resolves #835 --- tests/WP_Ultimo/Dashboard_Widgets_Test.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/WP_Ultimo/Dashboard_Widgets_Test.php b/tests/WP_Ultimo/Dashboard_Widgets_Test.php index d3a2a640..d61dda54 100644 --- a/tests/WP_Ultimo/Dashboard_Widgets_Test.php +++ b/tests/WP_Ultimo/Dashboard_Widgets_Test.php @@ -162,8 +162,10 @@ public function test_enqueue_scripts_enqueues_activity_stream_on_index(): void { $wp_scripts->queue = $original_queue; $wp_scripts->done = $original_done; } - if ($original_screen_id) { + if (null !== $original_screen_id) { set_current_screen($original_screen_id); + } else { + unset($GLOBALS['current_screen']); } $pagenow = $original; } @@ -209,8 +211,10 @@ public function test_enqueue_scripts_skips_activity_stream_on_per_site_dashboard $wp_scripts->queue = $original_queue; $wp_scripts->done = $original_done; } - if ($original_screen_id) { + if (null !== $original_screen_id) { set_current_screen($original_screen_id); + } else { + unset($GLOBALS['current_screen']); } $pagenow = $original; }