Skip to content

Tests: Add unit coverage for rest_cookie_collect_status() - #15293

Closed
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/rest-cookie-collect-status-65819
Closed

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/rest-cookie-collect-status-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for rest_cookie_collect_status(), covering the valid-cookie status and failure statuses collected from auth cookie actions.

Test-only; no production code changes.

Why

rest_cookie_collect_status() had no direct @covers coverage. Small helper coverage fits the #65819 test cleanup track.

How

Add tests/phpunit/tests/rest-api/restCookieCollectStatus.php with @covers ::rest_cookie_collect_status.

  • Sets $wp_rest_auth_cookie to true on auth_cookie_valid
  • Stores the failure status for malformed, expired, bad_username, and bad_hash

Testing Instructions

  1. npm run test:php -- --filter Tests_REST_API_RestCookieCollectStatus
  2. npm run test:php -- --filter Tests_REST_API_RestCookieCollectStatus -c tests/phpunit/multisite.xml
  3. npm run test:php -- --filter Tests_REST_API_RestCookieCollectStatus --order-by=random
  4. npm run test:php -- --group restapi

Use of AI Tools

  • Cursor

Add unit tests for REST auth cookie status collection on valid and failure actions.

See #65819.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the test-only addition covering REST cookie status collection.

No open issues 🎉

What changed in this PR

Adds dedicated PHPUnit coverage for rest_cookie_collect_status() as part of the #65819 test cleanup effort. No production code changes.

Changes:

  • Verifies that auth_cookie_valid sets the cookie status to true.
  • Uses a data provider to check malformed, expired, bad-username, and bad-hash statuses.
  • Adds @covers metadata and clears the status global during teardown.
File Description
tests/​phpunit/​tests/​rest-api/​restCookieCollectStatus.php Adds tests for valid-cookie and failure-status collection.

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 31, 2026 17:30
@github-actions

Copy link
Copy Markdown

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:

Props shailu25.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asserts the cookie-status callback converts auth success to boolean true and failure action names to meaningful status strings. This checks WordPress callback behavior, not just hook execution.

Local randomized single-site and multisite checks passed alongside related existing tests; PHPCS passed.

Optional: Four failure rows share one substring branch; one representative failure can suffice unless preserving registration coverage is intentional. No further failure matrix.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Verify `rest_cookie_collect_status()` records successful authentication and the failure status associated with cookie validation actions.

Developed in: #15293

Props shailu25.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@65143 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Verify `rest_cookie_collect_status()` records successful authentication and the failure status associated with cookie validation actions.

Developed in: WordPress/wordpress-develop#15293

Props shailu25.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@65143


git-svn-id: http://core.svn.wordpress.org/trunk@64292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants