Opened 4 weeks ago
Last modified 4 weeks ago
#65655 new enhancement
Tests: Add PHPUnit tests for wp_die() and its handlers
| 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 wp_die() function in wp-includes/functions.php is the standard way to terminate WordPress execution with an error message. It supports multiple handlers based on the request type (Ajax, JSON, XML-RPC, REST, etc.) and allows for custom handlers via filters.
Currently, while wp_die() is used extensively throughout the test suite, it lacks dedicated unit tests to verify its core logic and the behavior of its default handlers:
_default_wp_die_handler()_ajax_wp_die_handler()_json_wp_die_handler()_jsonp_wp_die_handler()_xml_wp_die_handler()_xmlrpc_wp_die_handler()
This patch introduces a new test class Tests_Functions_wpDie (and potentially separate files for handlers following the @covers rule) to verify:
- Correct handler selection based on request context.
- Argument parsing and sanitization via
_wp_die_process_input(). - Proper output formatting for different handlers (HTML, JSON, XML).
- Respecting the
exitargument to prevent process termination during testing. - Application of various
wp_die_{type}_handlerfilters.
Change History (2)
This ticket was mentioned in PR #12571 on WordPress/wordpress-develop by @pbearne.
4 weeks ago
#2
- Keywords has-patch has-unit-tests added
This PR introduces dedicated unit tests for the wp_die() function and its primary HTML handler _default_wp_die_handler() in wp-includes/functions.php.
Following the project's testing guidelines, the tests are split into two files:
•tests/phpunit/tests/functions/wpDie.php: Focuses on handler selection logic (Standard vs. Ajax), handling of WP_Error objects, and ensuring the correct callback is triggered via filters.
•tests/phpunit/tests/functions/_defaultWpDieHandler.php: Verifies the HTML output generated by the default handler, including the error message, title, additional error lists, and action links.
The tests use WPDieException to intercept execution termination and MockAction to verify filter interactions.
Trac ticket: https://core.trac.wordpress.org/ticket/65655
AI Disclosure:
•AI assistance: Yes
•Tool(s): Junie (JetBrains)
•Model(s): gemini-3-flash-preview
•Used for: Code analysis, test implementation, and workflow management.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.