You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tests: Add unit coverage for rest_cookie_check_errors() - #15294
Adds a dedicated PHPUnit class for rest_cookie_check_errors(), covering existing-result passthrough, missing/invalid/valid nonces, and skipping when another auth method is in use.
Test-only; no production code changes.
Why
rest_cookie_check_errors() had no direct @covers coverage. Small helper coverage fits the #65819 test cleanup track.
How
Add tests/phpunit/tests/rest-api/restCookieCheckErrors.php with @covers ::rest_cookie_check_errors.
Returns an existing non-empty result unchanged
Clears the current user and returns true when no nonce is present
Returns rest_cookie_invalid_nonce for an invalid nonce
Returns true for a valid wp_rest nonce
Skips the cookie check when the user is logged in via another auth method
Testing Instructions
npm run test:php -- --filter Tests_REST_API_RestCookieCheckErrors
npm run test:php -- --filter Tests_REST_API_RestCookieCheckErrors -c tests/phpunit/multisite.xml
npm run test:php -- --filter Tests_REST_API_RestCookieCheckErrors --order-by=random
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The test teardown leaves $GLOBALS['wp_rest_server'] populated, allowing shared routes and captured nonce headers to leak into subsequent tests; it should be reset to null.
The missing-nonce branch also returns true, so this test would still pass if a valid nonce were mistakenly treated as absent and the authenticated user were cleared. Assert that get_current_user_id() remains $user_id after the call so the test distinguishes successful cookie authentication from an anonymous request.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
No active review issues were identified for the test-only addition of PHPUnit coverage for REST cookie authentication.
No open issues 🎉
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trac ticket: #65819
What
Adds a dedicated PHPUnit class for
rest_cookie_check_errors(), covering existing-result passthrough, missing/invalid/valid nonces, and skipping when another auth method is in use.Test-only; no production code changes.
Why
rest_cookie_check_errors()had no direct@coverscoverage. Small helper coverage fits the #65819 test cleanup track.How
Add
tests/phpunit/tests/rest-api/restCookieCheckErrors.phpwith@covers ::rest_cookie_check_errors.truewhen no nonce is presentrest_cookie_invalid_noncefor an invalid noncetruefor a validwp_restnonceTesting Instructions
npm run test:php -- --filter Tests_REST_API_RestCookieCheckErrorsnpm run test:php -- --filter Tests_REST_API_RestCookieCheckErrors -c tests/phpunit/multisite.xmlnpm run test:php -- --filter Tests_REST_API_RestCookieCheckErrors --order-by=randomnpm run test:php -- --group restapiUse of AI Tools