Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks 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.


4 weeks ago
#1

  • Keywords has-patch has-unit-tests added

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.

#2 @wildworks
4 weeks ago

  • Milestone 7.1Awaiting 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.

Note: See TracTickets for help on using tickets.