Opened 8 hours ago
Last modified 113 minutes ago
#65650 new defect (bug)
Tests: Add PHPUnit tests for status_header()
| Reported by: | pbearne | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | tests |
Description
The status_header() function in wp-includes/functions.php is a core function responsible for sending HTTP status headers. While its logic is straightforward, it currently lacks dedicated test coverage in the suite.
This patch introduces a new test class Tests_Functions_StatusHeader to provide coverage for:
- Standard HTTP status codes (200, 404, 301).
- Custom status descriptions.
- Early return for unknown status codes without a description.
- Support for unknown status codes when a description is provided.
- Verification that the server protocol (e.g., HTTP/1.1) is respected.
The tests use the status_header filter to verify the generated header string, as the header() function itself is difficult to test in a CLI environment.
Change History (2)
This ticket was mentioned in PR #12565 on WordPress/wordpress-develop by @pbearne.
8 hours ago
#1
- Keywords has-patch has-unit-tests added
#2
@
113 minutes ago
- Milestone 7.1 → Awaiting Review
Since 7.1 Beta 1 has already been released and these functions were not newly introduced with the 7.1 release, I'd like to remove the milestone.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
This PR introduces a new test class Tests_Functions_StatusHeader to provide PHPUnit test coverage for the status_header() function in wp-includes/functions.php.
The tests cover:
•Standard HTTP status codes (200, 404, 301) and their default descriptions.
•Custom status descriptions provided as the second argument.
•Handling of unknown status codes (early return vs. using custom description).
•Verification that the server protocol (e.g., HTTP/1.1) is correctly respected in the generated header.
Since header() calls are difficult to test directly in a CLI environment, these tests rely on the status_header filter to intercept and verify the generated header string.
Trac ticket: https://core.trac.wordpress.org/ticket/65650
AI Disclosure:
•AI assistance: Yes
•Tool(s): Junie (JetBrains)
•Model(s): gemini-3-flash-preview
•Used for: Code analysis, test implementation, and workflow management.