Skip to content

Tests: Add unit coverage for rest_get_route_for_post_type_items() - #15288

Open
shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-get-route-for-post-type-items-65819
Open

shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-get-route-for-post-type-items-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for rest_get_route_for_post_type_items(), covering collection routes, invalid post types, non-REST types, custom namespace/base, and filter overrides.

Test-only; no production code changes.

Why

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

How

Add tests/phpunit/tests/rest-api/restGetRouteForPostTypeItems.php with @covers ::rest_get_route_for_post_type_items.

  • Returns /wp/v2/posts for the post type
  • Returns an empty string for an invalid post type
  • Returns an empty string when the post type is not show_in_rest
  • Uses custom rest_namespace and rest_base when registered
  • Allows rest_route_for_post_type_items to replace the route

Testing Instructions

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

Use of AI Tools

  • Cursor

Add unit tests for REST post type collection routes, invalid types, custom namespace/base, and filter overrides.

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 are identified for the added PHPUnit coverage of REST post-type collection routes.

No open issues 🎉

What changed in this PR

Adds direct PHPUnit coverage for rest_get_route_for_post_type_items() as part of the #65819 test cleanup effort. No production code changes are included.

Changes:

  • Tests standard collection routes and empty results for invalid or non-REST post types.
  • Verifies custom REST namespaces, bases, and filter overrides.
  • Adds an explicit @covers annotation and cleanup for registered test post types.
File Description
tests/​phpunit/​tests/​rest-api/​restGetRouteForPostTypeItems.php Adds a dedicated test class covering route generation and overrides.

Review effort: Balanced

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

github-actions Bot commented Oct 31, 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 remove the local tear_down() override. Parent set_up() already calls reset_post_types() before each core test, and this class has no earlier fixture consumer. Keep the new collection guard/filter checks.

AI review · gpt-6

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 this test-only addition of PHPUnit coverage for REST post-type collection routes.

No open issues 🎉

Review effort: Balanced

@shail-mehta

Copy link
Copy Markdown
Member Author

Thanks for the Review!

Addressed in 0564b0f

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