Repository navigation
Tests: Cover the admin branch of wp_heartbeat_settings(). - #16223
mukeshpanchal27 wants to merge 4 commits into
Conversation
`wp_heartbeat_settings()` adds `ajaxurl` only outside the admin, because admin screens define it themselves. The tests added in [65768] all run outside the admin, so they pass even when the `is_admin()` check is removed. This adds a test for admin requests, logged in and logged out. It checks that `ajaxurl` is not added, and that a valid nonce is added only for a logged-in user. Follow-up to [65768]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…` test. See #66757. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified with the added admin-context heartbeat settings test coverage.
No open issues 🎉
What changed in this PR
Adds coverage for the admin branch of wp_heartbeat_settings(), complementing the existing non-admin tests.
Changes:
- Adds a dashboard-screen test with logged-in and logged-out cases.
- Checks that admin settings omit
ajaxurland include a valid heartbeat nonce only when logged in.
| File | Description |
|---|---|
tests/phpunit/tests/general/wpHeartbeatSettings.php |
Adds the admin-context test and its authentication-state data provider. |
Review effort: Balanced
There was a problem hiding this comment.
Could you keep one logged-in dashboard case? Check that ajaxurl is absent and the heartbeat nonce verifies. The existing frontend tests already cover both login states, and the logged-out dashboard row exercises the same is_admin() branch.
I tried the single case on single-site and multisite. Removing the admin guard still failed it, so we can drop the provider and the conditional assertion.
I checked the ticket mentioned in the description. #66614 tracks the original frontend tests, so their annotations are accurate. Please leave those in place and link the admin follow-up from a current component ticket. Original heartbeat coverage.
AI review · gpt-6
… test. The logged-out case runs the same `is_admin()` branch, and the existing front-end tests already cover both login states. Drop the data provider and the conditional assertion. See #66757. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lancewillett
left a comment
There was a problem hiding this comment.
The single logged-in dashboard case covers both behaviors. It passed on single-site and multisite and failed in both when I removed the admin guard. The remaining step before landing is to link a current General component ticket for the follow-up. The existing frontend tests can keep #66614.
AI review · gpt-6.2-astra
Trac ticket: https://core.trac.wordpress.org/ticket/66820
Description
Follow-up to [65768], which added tests for
wp_heartbeat_settings().wp_heartbeat_settings()addsajaxurlonly when! is_admin(), because admin screens defineajaxurlthemselves. It adds the heartbeat nonce whenever a user is logged in.The tests from [65768] all run outside the admin. When I removed the
! is_admin()check, so thatajaxurlwas always added, all three tests still passed.This adds
test_wp_heartbeat_settings_admin(), which runs on thedashboardscreen with a logged-in user. It checks thatajaxurlis not added and that the nonce is valid forheartbeat-nonce.A logged-out admin case would run the same
is_admin()branch, and the existing front-end tests already cover both login states, so one case is enough.WP_UnitTestCaseresets the current screen after each test, so notear_down()is needed.Testing
npm run test:php -- --filter Tests_General_WpHeartbeatSettings: 4 tests pass on single site and multisite.! is_admin()check removed, the new test fails.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the untested branch, writing the test, and drafting this description. I reviewed the result.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code