From 4cbf11e5fc364c6f96718eef2f4db543534e58aa Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:31:49 +0000 Subject: [PATCH 1/3] Tests: Cover rest_output_link_header(). Add unit tests for REST API Link header output and empty REST URL handling. See #65819. --- .../tests/rest-api/restOutputLinkHeader.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/phpunit/tests/rest-api/restOutputLinkHeader.php diff --git a/tests/phpunit/tests/rest-api/restOutputLinkHeader.php b/tests/phpunit/tests/rest-api/restOutputLinkHeader.php new file mode 100644 index 0000000000000..51cf900472193 --- /dev/null +++ b/tests/phpunit/tests/rest-api/restOutputLinkHeader.php @@ -0,0 +1,52 @@ +assertSame( '', $output ); + } + + /** + * @ticket 65819 + */ + public function test_returns_early_when_rest_url_is_empty() { + add_filter( 'rest_url', '__return_empty_string' ); + + ob_start(); + rest_output_link_header(); + $output = ob_get_clean(); + + $this->assertSame( '', $output ); + } + + /** + * @ticket 65819 + * + * @requires function xdebug_get_headers + */ + public function test_sends_rest_api_link_header() { + $api_root = sanitize_url( get_rest_url() ); + + rest_output_link_header(); + + $headers = xdebug_get_headers(); + $expected = sprintf( 'Link: <%s>; rel="https://api.w.org/"', $api_root ); + + $this->assertContains( $expected, $headers ); + } +} From 3695a7505df58c9bcc5793fd244ad79f1a2457e0 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sat, 31 Oct 2026 11:13:26 +0530 Subject: [PATCH 2/3] Apply Feedback Changes Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tests/phpunit/tests/rest-api/restOutputLinkHeader.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpunit/tests/rest-api/restOutputLinkHeader.php b/tests/phpunit/tests/rest-api/restOutputLinkHeader.php index 51cf900472193..1faadef01e22c 100644 --- a/tests/phpunit/tests/rest-api/restOutputLinkHeader.php +++ b/tests/phpunit/tests/rest-api/restOutputLinkHeader.php @@ -3,6 +3,8 @@ /** * Tests for rest_output_link_header(). * + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled * @group restapi * @group xdebug * From e9e2b16b462721be61b4bcce01f5389319058219 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:48:47 +0000 Subject: [PATCH 3/3] Tests: Strengthen empty REST URL coverage for rest_output_link_header(). Assert headers are unchanged when rest_url is empty, instead of only checking the response body. See #65819. --- tests/phpunit/tests/rest-api/restOutputLinkHeader.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/rest-api/restOutputLinkHeader.php b/tests/phpunit/tests/rest-api/restOutputLinkHeader.php index 1faadef01e22c..1eeb8936e6db7 100644 --- a/tests/phpunit/tests/rest-api/restOutputLinkHeader.php +++ b/tests/phpunit/tests/rest-api/restOutputLinkHeader.php @@ -25,15 +25,17 @@ public function test_outputs_nothing_to_body() { /** * @ticket 65819 + * + * @requires function xdebug_get_headers */ public function test_returns_early_when_rest_url_is_empty() { add_filter( 'rest_url', '__return_empty_string' ); - ob_start(); + $headers_before = xdebug_get_headers(); + rest_output_link_header(); - $output = ob_get_clean(); - $this->assertSame( '', $output ); + $this->assertSame( $headers_before, xdebug_get_headers() ); } /**