Skip to content

Tests: Add unit coverage for rest_get_avatar_sizes() and rest_get_avatar_urls() - #15250

Open
shail-mehta wants to merge 4 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-get-avatar-sizes-65819
Open

shail-mehta wants to merge 4 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-get-avatar-sizes-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for rest_get_avatar_sizes() and rest_get_avatar_urls(), covering default sizes, filtered sizes, and URL keys.

Test-only; no production code changes.

Why

These helpers had no direct @covers coverage. Small helper coverage fits the #65819 test cleanup track.

How

Add tests/phpunit/tests/rest-api/restGetAvatarSizes.php with @covers for both functions.

Testing Instructions

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

Use of AI Tools

  • Cursor

Add unit tests for default sizes, filtered sizes, and URL keys.

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

No active review issues block the test-only addition of REST API avatar helper coverage.

No open issues 🎉

What changed in this PR

Adds direct PHPUnit coverage for the REST API avatar helpers as part of the test cleanup tracked in #65819. This is a test-only change with no production code changes.

Changes:

  • Tests default and filtered avatar sizes.
  • Verifies avatar URL keys and values for both size sets.
  • Adds explicit @covers annotations for both helpers.
File Description
tests/​phpunit/​tests/​rest-api/​restGetAvatarSizes.php Adds four tests covering avatar sizes and corresponding URLs.

Review effort: Balanced

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

github-actions Bot commented Oct 30, 2026 •

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, lancewillett.

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.

Please narrow this to the distinct filtered-size behavior: the REST users/comments controller tests and schema fixture already cover default avatar sizes and URLs. For the retained URL check, avoid computing the expectation with get_avatar_url() exactly as production does; assert independently expected URL components for the fixed email and requested sizes. One filtered URL check can exercise both helpers without repeating the default-size matrix.

AI review · gpt-6

Drop default-size cases already covered elsewhere and assert independent Gravatar URL components for filtered sizes.

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.

🟡 Changes recommended

The tests leave default avatar sizes unverified and use substring assertions that can accept incorrect sizes, allowing regressions to pass.

2 open issues

Review effort: Balanced

Parse the Gravatar query string so filtered-size URL checks require the exact s parameter.

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.

🔵 Needs a closer look

Human review is needed to weigh an unpublished coverage gap, since the sole test overrides avatar sizes and would miss regressions in the defaults.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@shail-mehta

Copy link
Copy Markdown
Member Author

Thanks @lancewillett - addressed your feedback: filtered-size coverage only, with independent Gravatar URL checks (exact s query value, no get_avatar_url() mirroring).

Copilot asked to restore default size/URL tests; leaving those out since you noted they’re already covered in the REST users/comments controller tests and schema fixture.

Happy to change further if needed.

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