Skip to content

Tests: Cover prepare_item_for_response() in navigation fallback controller - #14385

Closed
rejaulalomkhan wants to merge 1 commit into
WordPress:trunkfrom
rejaulalomkhan:tests/66073-navigation-fallback-prepare-item
Closed

rejaulalomkhan wants to merge 1 commit into
WordPress:trunkfrom
rejaulalomkhan:tests/66073-navigation-fallback-prepare-item

Conversation

@rejaulalomkhan

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/40538
See also: https://core.trac.wordpress.org/ticket/66073

Description

In tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php, test_prepare_item() was an empty stub annotated with @doesNotPerformAssertions.

This PR replaces the stub with test coverage for WP_REST_Navigation_Fallback_Controller::prepare_item_for_response():

  • test_prepare_item(): Verifies the WP_REST_Response instance, HTTP 200 status, returned id data, and the presence and embeddability of the self link.
  • test_prepare_item_limit_fields(): Verifies that requesting specific _fields limits the response and properly omits _links when not requested.

Follow-up to [64273].

Testing Instructions

  1. Run vendor/bin/phpcs tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php
  2. Run vendor/bin/phpunit --filter WP_REST_Navigation_Fallback_Controller_Test
  3. Run vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter WP_REST_Navigation_Fallback_Controller_Test

All tests pass cleanly.


Use of AI Tools:
I used Antigravity (Gemini 2.5 Pro) to analyze prepare_item_for_response() in WP_REST_Navigation_Fallback_Controller, verify _fields handling, run local PHPCS and PHPUnit test suites, and write test assertions following core REST controller test conventions.

…oller.

Replace empty test_prepare_item() stub with assertions for response status, returned ID, and self link. Add test_prepare_item_limit_fields() to verify _links exclusion when fields are limited.

See #40538, #66073.
@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. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rejaulalomkhan.

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

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

The test-only changes match the controller’s existing behavior, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Adds focused test coverage for the navigation fallback controller’s response preparation, replacing an empty test stub.

Changes:

  • Verifies response type, status, navigation ID, and embeddable self link.
  • Checks that _fields=id preserves the ID and omits links.
File Description
tests/​phpunit/​tests/​rest-api/​rest-navigation-fallback-controller.php Adds response preparation and field-filtering assertions.

Review effort: Balanced

wporg-sync pushed a commit that referenced this pull request Oct 17, 2026
Replace the empty `test_prepare_item()` stub with assertions for the navigation ID, response status, and embeddable `self` link returned by `WP_REST_Navigation_Fallback_Controller::prepare_item_for_response()`. Verify that requesting only `id` through `_fields` omits links.

Developed in: #14385

Props rejaulalomkhan.
See #40538, #66073.


git-svn-id: https://develop.svn.wordpress.org/trunk@64452 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 17, 2026
Replace the empty `test_prepare_item()` stub with assertions for the navigation ID, response status, and embeddable `self` link returned by `WP_REST_Navigation_Fallback_Controller::prepare_item_for_response()`. Verify that requesting only `id` through `_fields` omits links.

Developed in: WordPress/wordpress-develop#14385

Props rejaulalomkhan.
See #40538, #66073.

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


git-svn-id: http://core.svn.wordpress.org/trunk@63602 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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