Skip to content

fix(tests): restore null screen state with unset in Dashboard_Widgets_Test finally blocks#849

Merged
superdav42 merged 1 commit intomainfrom
feature/auto-20260414-093049
Apr 14, 2026
Merged

fix(tests): restore null screen state with unset in Dashboard_Widgets_Test finally blocks#849
superdav42 merged 1 commit intomainfrom
feature/auto-20260414-093049

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Fixes leaking screen state in Dashboard_Widgets_Test when no screen existed before test execution.

Both finally blocks used if ($original_screen_id) as the guard before calling set_current_screen(). When $original_screen_id is null (no screen was active before the test), the guard evaluates as falsy and the forced dashboard-network/dashboard screen leaks into subsequent tests.

Fix: replace if ($original_screen_id) with if (null !== $original_screen_id) and add an else branch that calls unset($GLOBALS['current_screen']) — the WordPress-recommended way to restore a previously-null screen state (see wordpress-develop/tests/phpunit/includes/abstract-testcase.php).

Applies to both test methods:

  • test_enqueue_scripts_enqueues_activity_stream_on_index (line 165-167)
  • test_enqueue_scripts_skips_activity_stream_on_per_site_dashboard (line 212-214)

Changes

  • tests/WP_Ultimo/Dashboard_Widgets_Test.php — two finally blocks updated

Verification

The fix matches the pattern used in WordPress core test infrastructure. The change prevents screen state leakage when tests run in isolation (no prior screen context).

Resolves #835

…_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
@superdav42 superdav42 added the origin:interactive Created by interactive user session label Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 34 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 56 minutes and 34 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c8ea508f-96f5-45fd-8a89-2014c4c69227

📥 Commits

Reviewing files that changed from the base of the PR and between 09a8977 and 4af34e8.

📒 Files selected for processing (1)
  • tests/WP_Ultimo/Dashboard_Widgets_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260414-093049

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@superdav42 superdav42 merged commit 0551fd2 into main Apr 14, 2026
9 of 11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

Fixes leaking screen state in Dashboard_Widgets_Test when no screen existed before test execution.
Both finally blocks used if ($original_screen_id) as the guard before calling set_current_screen(). When $original_screen_id is null (no screen was active before the test), the guard evaluates as falsy and the forced dashboard-network/dashboard screen leaks into subsequent tests.
Fix: replace if ($original_screen_id) with if (null !== $original_screen_id) and add an else branch that calls unset($GLOBALS['current_screen']) — the WordPress-recommended way to restore a previously-null screen state (see wordpress-develop/tests/phpunit/includes/abstract-testcase.php).
Applies to both test methods:

  • test_enqueue_scripts_enqueues_activity_stream_on_index (line 165-167)
  • test_enqueue_scripts_skips_activity_stream_on_per_site_dashboard (line 212-214)

Changes

  • tests/WP_Ultimo/Dashboard_Widgets_Test.php — two finally blocks updated

Verification

The fix matches the pattern used in WordPress core test infrastructure. The change prevents screen state leakage when tests run in isolation (no prior screen context).


Merged via PR #849 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.8.24 spent 13m on this as a headless bash routine.

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

Issue: #835 — Review followup: PR #821 — t806: test: harden Dashboard_Widgets_Test global cleanup with try/finally

What was done:

The CodeRabbit bot flagged that both finally blocks in Dashboard_Widgets_Test.php used if ($original_screen_id) as the screen-restore guard. When $original_screen_id is null (no screen was active before the test), this guard evaluates as falsy and the forced dashboard-network/dashboard screen state leaks into subsequent tests.

Fix applied (both finally blocks, lines 165-167 and 212-214):

  • Changed if ($original_screen_id)if (null !== $original_screen_id)
  • Added else { unset($GLOBALS['current_screen']); } to explicitly restore the null state

This matches the WordPress-recommended pattern from wordpress-develop/tests/phpunit/includes/abstract-testcase.php.

Outcome: B — Premise correct, fix implemented and merged.

Verification: PHP Lint + Code Quality checks passed. Cypress E2E failures are pre-existing environment setup failures unrelated to this test-file change.

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for abc8ca0 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.78 MB 893.00 ms 168.00 ms (+7.50 ms / +4% ) 1062.00 ms 2020.00 ms 1921.25 ms 97.70 ms (+8.55 ms / +9% )
1 56 49.02 MB 910.00 ms 146.00 ms 1054.00 ms 2062.00 ms (+42.00 ms / +2% ) 1979.05 ms (+47.00 ms / +2% ) 83.15 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

origin:interactive Created by interactive user session

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review followup: PR #821 — t806: test: harden Dashboard_Widgets_Test global cleanup with try/finally

1 participant