Skip to content

Tests: Add unit coverage for rest_get_route_for_post() - #15286

Draft
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/rest-get-route-for-post-65819
Draft

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/rest-get-route-for-post-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for rest_get_route_for_post(), covering route generation for posts, invalid posts, non-REST post types, and filter overrides.

Test-only; no production code changes.

Why

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

How

Add tests/phpunit/tests/rest-api/restGetRouteForPost.php with @covers ::rest_get_route_for_post.

  • Returns /wp/v2/posts/{id} for a post
  • Returns an empty string for an invalid post
  • Returns an empty string when the post type is not show_in_rest
  • Allows rest_route_for_post to replace the route

Testing Instructions

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

Use of AI Tools

  • Cursor

Add unit tests for REST route generation, invalid posts, non-REST post types, 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

There are no active review issues for this test-only change adding direct coverage of rest_get_route_for_post().

No open issues 🎉

What changed in this PR

Adds direct PHPUnit coverage for rest_get_route_for_post() as part of the #65819 test cleanup effort. This is a test-only change with no production code modifications.

Changes:

  • Verifies route generation for posts and empty results for invalid posts or post types not exposed through REST.
  • Tests route overrides through the rest_route_for_post filter.
  • Adds explicit @covers metadata for the helper.
File Description
tests/​phpunit/​tests/​rest-api/​restGetRouteForPost.php Adds a dedicated test class covering route generation, empty results, and filter overrides.

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