Skip to content

fix: unset current_screen global when restoring null screen state in tests (#841)#846

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

fix: unset current_screen global when restoring null screen state in tests (#841)#846
superdav42 merged 1 commit intomainfrom
feature/auto-20260414-092712

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Fixes screen state leakage in Dashboard_Widgets_Test — both finally blocks were silently skipping screen restoration when $original_screen_id was null, allowing the forced dashboard-network / dashboard screen states to leak into subsequent tests.

Changes

File: tests/WP_Ultimo/Dashboard_Widgets_Test.php

Both finally blocks in test_enqueue_scripts_enqueues_activity_stream_on_index and test_enqueue_scripts_skips_activity_stream_on_per_site_dashboard updated:

  • Changed if ($original_screen_id)if (null !== $original_screen_id) (strict null check avoids falsy string '' or 0 bypassing restoration)
  • Added else { unset($GLOBALS['current_screen']); } to explicitly clear the global when there was no original screen

This follows the WordPress core test practice recommended in wordpress-develop PR #1380 and abstract-testcase.php.

Verification

The fix matches the pattern prescribed in the CodeRabbit review finding on PR #821. Both test methods now properly restore the global screen state regardless of whether a screen was active before the test ran.

Resolves #841

…t teardown

Both finally blocks in Dashboard_Widgets_Test were skipping screen
restoration when $original_screen_id was null/falsy, allowing the
forced screen state set by each test (dashboard-network / dashboard)
to leak into subsequent tests.

Changed the guard from `if ($original_screen_id)` to
`if (null !== $original_screen_id)` and added an explicit
`unset($GLOBALS['current_screen'])` in the else branch so that
a previously-null screen state is fully restored after each test.

Resolves #841
@superdav42 superdav42 added the origin:interactive Created by interactive user session label Apr 14, 2026
@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

Issue: #841 — Dashboard_Widgets_Test screen state leakage
Fix: Both finally blocks in Dashboard_Widgets_Test now explicitly call unset($GLOBALS['current_screen']) when $original_screen_id is null, preventing forced screen states from leaking into subsequent tests.

Change: tests/WP_Ultimo/Dashboard_Widgets_Test.php

  • Lines 165–169 and 214–218: changed if ($original_screen_id)if (null !== $original_screen_id) with else { unset($GLOBALS['current_screen']); }

Testing: Follows WordPress core pattern from wordpress-develop PR #1380; no behavior change when screen was previously set, explicit cleanup when it was not.


aidevops.sh v3.8.24 plugin for OpenCode v1.4.3 with claude-sonnet-4-6 spent 1m on this as a headless worker. Overall, 13s since this issue was created.

@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

@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 58 minutes and 4 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 58 minutes and 4 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: 3bf4cc5d-518d-4712-a78f-d3665214276f

📥 Commits

Reviewing files that changed from the base of the PR and between 9e53593 and c68a763.

📒 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-092712

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 1e6d704 into main Apr 14, 2026
9 of 11 checks passed
@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for 791aa8b 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.83 MB 956.50 ms (+85.50 ms / +9% ) 167.50 ms (+8.50 ms / +5% ) 1134.00 ms (+104.50 ms / +9% ) 2190.00 ms (+122.00 ms / +6% ) 2101.40 ms (+114.90 ms / +5% ) 88.70 ms (-3.80 ms / -4% )
1 56 49.02 MB 970.50 ms 150.00 ms 1122.50 ms 2156.00 ms 2072.60 ms 82.35 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.

quality-debt: tests/WP_Ultimo/Dashboard_Widgets_Test.php — PR #821 review feedback (high)

1 participant