Skip to content

Tests: Add unit coverage for rest_get_route_for_taxonomy_items() - #15289

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

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

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

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

Test-only; no production code changes.

Why

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

How

Add tests/phpunit/tests/rest-api/restGetRouteForTaxonomyItems.php with @covers ::rest_get_route_for_taxonomy_items.

  • Returns /wp/v2/categories for the category taxonomy
  • Returns an empty string for an invalid taxonomy
  • Returns an empty string when the taxonomy is not show_in_rest
  • Uses custom rest_namespace and rest_base when registered
  • Allows rest_route_for_taxonomy_items to replace the route

Testing Instructions

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

Use of AI Tools

  • Cursor

Add unit tests for REST taxonomy collection routes, invalid taxonomies, 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.

🟡 Changes recommended

The tests leave the default REST base and namespace fallbacks untested and do not verify the filter’s route and taxonomy arguments.

2 open issues
What changed in this PR

Adds direct PHPUnit coverage for rest_get_route_for_taxonomy_items() as part of the REST API test cleanup tracked in #65819. No production code changes.

Changes:

  • Covers category collection routes, invalid taxonomies, and taxonomies not exposed through REST.
  • Tests custom namespaces and bases, plus filter-based route overrides.
  • Adds taxonomy cleanup and a dedicated @covers annotation.
File Description
tests/​phpunit/​tests/​rest-api/​restGetRouteForTaxonomyItems.php Adds five focused tests for taxonomy collection route generation.

Review effort: Balanced

Cover default namespace/base fallbacks and assert the filter receives the original route and taxonomy.

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 skip the normal registration defaults and do not verify each fallback independently, leaving common regressions undetected.

1 open issue
2 resolved since last review

Review effort: Balanced

Assert registration defaults, then exercise empty rest_base and empty rest_namespace fallbacks independently.

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 remain for the added taxonomy REST route tests.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

2 participants