Skip to content

Tests: Add unit coverage for rest_output_link_header() - #15284

Closed
shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-output-link-header-65819
Closed

shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-output-link-header-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for rest_output_link_header(), covering empty body output, the empty REST URL early return, and the REST API Link header when xdebug is available.

Test-only; no production code changes.

Why

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

How

Add tests/phpunit/tests/rest-api/restOutputLinkHeader.php with @covers ::rest_output_link_header.

  • Writes nothing to the response body
  • Outputs nothing when rest_url is filtered to an empty string
  • Sends the https://api.w.org/ Link header (@requires function xdebug_get_headers)

Testing Instructions

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

Use of AI Tools

  • Cursor

Add unit tests for REST API Link header output and empty REST URL handling.

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 lack process isolation, causing bootstrap output to bypass the intended code paths, and the empty-URL test does not assert that headers remain unchanged.

2 open issues
What changed in this PR

Adds dedicated PHPUnit coverage for rest_output_link_header() as part of the REST API test cleanup in Trac #65819. No production code changes.

Changes:

  • Adds a test class with explicit @covers metadata.
  • Checks response-body output with normal and empty REST URLs.
  • Adds an Xdebug-dependent assertion for the REST API Link header.
File Description
tests/​phpunit/​tests/​rest-api/​restOutputLinkHeader.php Adds three tests for REST API link-header behavior.

Review effort: Balanced

shail-mehta and others added 2 commits October 31, 2026 11:13
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Assert headers are unchanged when rest_url is empty, instead of only checking the response body.

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 were reported for the test-only addition of direct PHPUnit coverage for rest_output_link_header().

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 31, 2026 17:24
@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.

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

Props shailu25.

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.

The actual HTTP-header assertions passed locally with Xdebug enabled, in both single-site and multisite randomized runs. All three new methods executed with zero skips; PHPCS passed. The separate-process setup follows the existing header tests.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Verify the REST discovery link, RSD API element, and HTTP link header use the configured REST URL and are suppressed when that URL is disabled.

Developed in: #15282, #15283, #15284

Props shailu25.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@65140 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Verify the REST discovery link, RSD API element, and HTTP link header use the configured REST URL and are suppressed when that URL is disabled.

Developed in: WordPress/wordpress-develop#15282, WordPress/wordpress-develop#15283, WordPress/wordpress-develop#15284

Props shailu25.
See #65819.

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


git-svn-id: http://core.svn.wordpress.org/trunk@64289 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

@shail-mehta
shail-mehta deleted the tests/rest-output-link-header-65819 branch November 2, 2026 04:16
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