From ad5031e51d0da83ea427a8060423c772a083ab15 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Thu, 16 Jul 2026 16:42:05 -0400 Subject: [PATCH 1/6] Add unit tests for `status_header()` function --- .../phpunit/tests/functions/statusHeader.php | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 tests/phpunit/tests/functions/statusHeader.php diff --git a/tests/phpunit/tests/functions/statusHeader.php b/tests/phpunit/tests/functions/statusHeader.php new file mode 100644 index 0000000000000..51dcc2ad3adea --- /dev/null +++ b/tests/phpunit/tests/functions/statusHeader.php @@ -0,0 +1,134 @@ +get_args(); + $this->assertNotEmpty( $args, 'The status_header filter was not called.' ); + + $actual_header = $args[0][0]; + $this->assertMatchesRegularExpression( $expected_regex, $actual_header ); + $this->assertSame( (int) $code, $args[0][1], 'The status code passed to the filter does not match.' ); + + if ( $description ) { + $this->assertSame( $description, $args[0][2], 'The description passed to the filter does not match.' ); + } else { + $this->assertSame( get_status_header_desc( $code ), $args[0][2], 'The default description passed to the filter does not match.' ); + } + } + + /** + * Data provider for test_status_header_filter(). + * + * @return array + */ + public function data_status_header(): array { + return array( + '200 OK' => array( + 200, + '', + '/^HTTP\/1\.[012] 200 OK$/', + ), + '404 Not Found' => array( + 404, + '', + '/^HTTP\/1\.[012] 404 Not Found$/', + ), + 'Custom description' => array( + 200, + 'Everything is Fine', + '/^HTTP\/1\.[012] 200 Everything is Fine$/', + ), + '301 Moved Permanently' => array( + 301, + '', + '/^HTTP\/1\.[012] 301 Moved Permanently$/', + ), + ); + } + + /** + * Tests that status_header() returns early for unknown status codes without a description. + * + * @ticket 65650 + */ + public function test_status_header_unknown_code_returns_early() { + $filter = new MockAction(); + add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); + + status_header( 999 ); + + $this->assertEmpty( $filter->get_args(), 'The status_header filter should not have been called for an unknown status code without description.' ); + } + + /** + * Tests that status_header() works with unknown status codes if a description is provided. + * + * @ticket 65650 + */ + public function test_status_header_unknown_code_with_description() { + $filter = new MockAction(); + add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); + + status_header( 999, 'Custom Status' ); + + $args = $filter->get_args(); + $this->assertNotEmpty( $args, 'The status_header filter should have been called when a description is provided.' ); + $this->assertMatchesRegularExpression( '/^HTTP\/1\.[012] 999 Custom Status$/', $args[0][0] ); + } + + /** + * Tests that status_header() respects the server protocol. + * + * @ticket 65650 + */ + public function test_status_header_respects_protocol() { + $old_protocol = $_SERVER['SERVER_PROTOCOL'] ?? null; + $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; + + $filter = new MockAction(); + add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); + + status_header( 200 ); + + $args = $filter->get_args(); + $this->assertStringStartsWith( 'HTTP/1.1 200 OK', $args[0][0] ); + + // Reset protocol. + if ( null === $old_protocol ) { + unset( $_SERVER['SERVER_PROTOCOL'] ); + } else { + $_SERVER['SERVER_PROTOCOL'] = $old_protocol; + } + } +} From dd6b536f61991062abe8754ce6bbe1b0bdc1a716 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Thu, 16 Jul 2026 16:44:17 -0400 Subject: [PATCH 2/6] Revert "Add unit tests for `status_header()` function" This reverts commit ad5031e51d0da83ea427a8060423c772a083ab15. --- .../phpunit/tests/functions/statusHeader.php | 134 ------------------ 1 file changed, 134 deletions(-) delete mode 100644 tests/phpunit/tests/functions/statusHeader.php diff --git a/tests/phpunit/tests/functions/statusHeader.php b/tests/phpunit/tests/functions/statusHeader.php deleted file mode 100644 index 51dcc2ad3adea..0000000000000 --- a/tests/phpunit/tests/functions/statusHeader.php +++ /dev/null @@ -1,134 +0,0 @@ -get_args(); - $this->assertNotEmpty( $args, 'The status_header filter was not called.' ); - - $actual_header = $args[0][0]; - $this->assertMatchesRegularExpression( $expected_regex, $actual_header ); - $this->assertSame( (int) $code, $args[0][1], 'The status code passed to the filter does not match.' ); - - if ( $description ) { - $this->assertSame( $description, $args[0][2], 'The description passed to the filter does not match.' ); - } else { - $this->assertSame( get_status_header_desc( $code ), $args[0][2], 'The default description passed to the filter does not match.' ); - } - } - - /** - * Data provider for test_status_header_filter(). - * - * @return array - */ - public function data_status_header(): array { - return array( - '200 OK' => array( - 200, - '', - '/^HTTP\/1\.[012] 200 OK$/', - ), - '404 Not Found' => array( - 404, - '', - '/^HTTP\/1\.[012] 404 Not Found$/', - ), - 'Custom description' => array( - 200, - 'Everything is Fine', - '/^HTTP\/1\.[012] 200 Everything is Fine$/', - ), - '301 Moved Permanently' => array( - 301, - '', - '/^HTTP\/1\.[012] 301 Moved Permanently$/', - ), - ); - } - - /** - * Tests that status_header() returns early for unknown status codes without a description. - * - * @ticket 65650 - */ - public function test_status_header_unknown_code_returns_early() { - $filter = new MockAction(); - add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); - - status_header( 999 ); - - $this->assertEmpty( $filter->get_args(), 'The status_header filter should not have been called for an unknown status code without description.' ); - } - - /** - * Tests that status_header() works with unknown status codes if a description is provided. - * - * @ticket 65650 - */ - public function test_status_header_unknown_code_with_description() { - $filter = new MockAction(); - add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); - - status_header( 999, 'Custom Status' ); - - $args = $filter->get_args(); - $this->assertNotEmpty( $args, 'The status_header filter should have been called when a description is provided.' ); - $this->assertMatchesRegularExpression( '/^HTTP\/1\.[012] 999 Custom Status$/', $args[0][0] ); - } - - /** - * Tests that status_header() respects the server protocol. - * - * @ticket 65650 - */ - public function test_status_header_respects_protocol() { - $old_protocol = $_SERVER['SERVER_PROTOCOL'] ?? null; - $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; - - $filter = new MockAction(); - add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); - - status_header( 200 ); - - $args = $filter->get_args(); - $this->assertStringStartsWith( 'HTTP/1.1 200 OK', $args[0][0] ); - - // Reset protocol. - if ( null === $old_protocol ) { - unset( $_SERVER['SERVER_PROTOCOL'] ); - } else { - $_SERVER['SERVER_PROTOCOL'] = $old_protocol; - } - } -} From 159a8604b0a142351ec17ec65237efe08fe58940 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Thu, 16 Jul 2026 16:51:04 -0400 Subject: [PATCH 3/6] Add unit tests for `status_header()` function --- .../phpunit/tests/functions/statusHeader.php | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 tests/phpunit/tests/functions/statusHeader.php diff --git a/tests/phpunit/tests/functions/statusHeader.php b/tests/phpunit/tests/functions/statusHeader.php new file mode 100644 index 0000000000000..51dcc2ad3adea --- /dev/null +++ b/tests/phpunit/tests/functions/statusHeader.php @@ -0,0 +1,134 @@ +get_args(); + $this->assertNotEmpty( $args, 'The status_header filter was not called.' ); + + $actual_header = $args[0][0]; + $this->assertMatchesRegularExpression( $expected_regex, $actual_header ); + $this->assertSame( (int) $code, $args[0][1], 'The status code passed to the filter does not match.' ); + + if ( $description ) { + $this->assertSame( $description, $args[0][2], 'The description passed to the filter does not match.' ); + } else { + $this->assertSame( get_status_header_desc( $code ), $args[0][2], 'The default description passed to the filter does not match.' ); + } + } + + /** + * Data provider for test_status_header_filter(). + * + * @return array + */ + public function data_status_header(): array { + return array( + '200 OK' => array( + 200, + '', + '/^HTTP\/1\.[012] 200 OK$/', + ), + '404 Not Found' => array( + 404, + '', + '/^HTTP\/1\.[012] 404 Not Found$/', + ), + 'Custom description' => array( + 200, + 'Everything is Fine', + '/^HTTP\/1\.[012] 200 Everything is Fine$/', + ), + '301 Moved Permanently' => array( + 301, + '', + '/^HTTP\/1\.[012] 301 Moved Permanently$/', + ), + ); + } + + /** + * Tests that status_header() returns early for unknown status codes without a description. + * + * @ticket 65650 + */ + public function test_status_header_unknown_code_returns_early() { + $filter = new MockAction(); + add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); + + status_header( 999 ); + + $this->assertEmpty( $filter->get_args(), 'The status_header filter should not have been called for an unknown status code without description.' ); + } + + /** + * Tests that status_header() works with unknown status codes if a description is provided. + * + * @ticket 65650 + */ + public function test_status_header_unknown_code_with_description() { + $filter = new MockAction(); + add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); + + status_header( 999, 'Custom Status' ); + + $args = $filter->get_args(); + $this->assertNotEmpty( $args, 'The status_header filter should have been called when a description is provided.' ); + $this->assertMatchesRegularExpression( '/^HTTP\/1\.[012] 999 Custom Status$/', $args[0][0] ); + } + + /** + * Tests that status_header() respects the server protocol. + * + * @ticket 65650 + */ + public function test_status_header_respects_protocol() { + $old_protocol = $_SERVER['SERVER_PROTOCOL'] ?? null; + $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; + + $filter = new MockAction(); + add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); + + status_header( 200 ); + + $args = $filter->get_args(); + $this->assertStringStartsWith( 'HTTP/1.1 200 OK', $args[0][0] ); + + // Reset protocol. + if ( null === $old_protocol ) { + unset( $_SERVER['SERVER_PROTOCOL'] ); + } else { + $_SERVER['SERVER_PROTOCOL'] = $old_protocol; + } + } +} From e0dfecb250d4018579813d4c41eea41be21f1a63 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Thu, 16 Jul 2026 16:55:25 -0400 Subject: [PATCH 4/6] Align variable assignment for old_protocol --- tests/phpunit/tests/functions/statusHeader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/statusHeader.php b/tests/phpunit/tests/functions/statusHeader.php index 51dcc2ad3adea..e3ec9c9ff515f 100644 --- a/tests/phpunit/tests/functions/statusHeader.php +++ b/tests/phpunit/tests/functions/statusHeader.php @@ -113,7 +113,7 @@ public function test_status_header_unknown_code_with_description() { * @ticket 65650 */ public function test_status_header_respects_protocol() { - $old_protocol = $_SERVER['SERVER_PROTOCOL'] ?? null; + $old_protocol = $_SERVER['SERVER_PROTOCOL'] ?? null; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $filter = new MockAction(); From 1750bcf0d92771627c5e4219dfdc7b4399653240 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Fri, 18 Sep 2026 14:18:08 -0400 Subject: [PATCH 5/6] Rename and restructure `status_header` unit test class for consistency --- .../functions/StatusHeaderTest.php} | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) rename tests/phpunit/tests/{functions/statusHeader.php => wp-includes/functions/StatusHeaderTest.php} (95%) diff --git a/tests/phpunit/tests/functions/statusHeader.php b/tests/phpunit/tests/wp-includes/functions/StatusHeaderTest.php similarity index 95% rename from tests/phpunit/tests/functions/statusHeader.php rename to tests/phpunit/tests/wp-includes/functions/StatusHeaderTest.php index e3ec9c9ff515f..922ac71b91fa3 100644 --- a/tests/phpunit/tests/functions/statusHeader.php +++ b/tests/phpunit/tests/wp-includes/functions/StatusHeaderTest.php @@ -1,13 +1,18 @@ Date: Wed, 4 Nov 2026 18:24:46 -0500 Subject: [PATCH 6/6] Change HTTP protocol in StatusHeaderTest to HTTP/2 Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../phpunit/tests/wp-includes/functions/StatusHeaderTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/wp-includes/functions/StatusHeaderTest.php b/tests/phpunit/tests/wp-includes/functions/StatusHeaderTest.php index 922ac71b91fa3..7a8daff49b7d6 100644 --- a/tests/phpunit/tests/wp-includes/functions/StatusHeaderTest.php +++ b/tests/phpunit/tests/wp-includes/functions/StatusHeaderTest.php @@ -119,7 +119,7 @@ public function test_status_header_unknown_code_with_description() { */ public function test_status_header_respects_protocol() { $old_protocol = $_SERVER['SERVER_PROTOCOL'] ?? null; - $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; + $_SERVER['SERVER_PROTOCOL'] = 'HTTP/2'; $filter = new MockAction(); add_filter( 'status_header', array( $filter, 'filter' ), 10, 4 ); @@ -127,7 +127,8 @@ public function test_status_header_respects_protocol() { status_header( 200 ); $args = $filter->get_args(); - $this->assertStringStartsWith( 'HTTP/1.1 200 OK', $args[0][0] ); + $this->assertSame( 'HTTP/2 200 OK', $args[0][0] ); + $this->assertSame( 'HTTP/2', $args[0][3] ); // Reset protocol. if ( null === $old_protocol ) {