-
Notifications
You must be signed in to change notification settings - Fork 3.5k
65655 functions wp die #12571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pbearne
wants to merge
5
commits into
WordPress:trunk
Choose a base branch
from
pbearne:65655-functions-wp_die
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
65655 functions wp die #12571
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad5031e
Add unit tests for `status_header()` function
dd6b536
Revert "Add unit tests for `status_header()` function"
36340c6
Add unit tests for `_default_wp_die_handler()` and `wp_die()` functions
70917af
Improve formatting of wp_die_handler filter
pbearne b80fb6f
Merge branch 'trunk' into 65655-functions-wp_die
pbearne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests the _default_wp_die_handler() function. | ||
| * | ||
| * @group functions | ||
| * | ||
| * @covers ::_default_wp_die_handler | ||
| */ | ||
| class Tests_Functions_DefaultWpDieHandler extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests the default HTML output of the handler. | ||
| * | ||
| * @ticket 65655 | ||
| */ | ||
| public function test_default_wp_die_handler_output() { | ||
| ob_start(); | ||
| try { | ||
| _default_wp_die_handler( 'Error Message', 'Error Title', array( 'exit' => false ) ); | ||
| } catch ( WPDieException $e ) { | ||
| } | ||
| $output = ob_get_clean(); | ||
|
|
||
| $this->assertStringContainsString( '<div class="wp-die-message">Error Message</div>', $output ); | ||
| $this->assertStringContainsString( '<title>Error Title</title>', $output ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests handling of additional errors. | ||
| * | ||
| * @ticket 65655 | ||
| */ | ||
| public function test_default_wp_die_handler_additional_errors() { | ||
| $args = array( | ||
| 'exit' => false, | ||
| 'additional_errors' => array( | ||
| array( 'message' => 'Extra Error 1' ), | ||
| array( 'message' => 'Extra Error 2' ), | ||
| ), | ||
| ); | ||
|
|
||
| ob_start(); | ||
| try { | ||
| _default_wp_die_handler( 'Main Error', '', $args ); | ||
| } catch ( WPDieException $e ) { | ||
| } | ||
| $output = ob_get_clean(); | ||
|
|
||
| $this->assertStringContainsString( '<li>Main Error</li>', $output ); | ||
| $this->assertStringContainsString( '<li>Extra Error 1</li>', $output ); | ||
| $this->assertStringContainsString( '<li>Extra Error 2</li>', $output ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests handling of a link. | ||
| * | ||
| * @ticket 65655 | ||
| */ | ||
| public function test_default_wp_die_handler_link() { | ||
| $args = array( | ||
| 'exit' => false, | ||
| 'link_url' => 'https://example.com', | ||
| 'link_text' => 'Go to Example', | ||
| ); | ||
|
|
||
| ob_start(); | ||
| try { | ||
| _default_wp_die_handler( 'Error', '', $args ); | ||
| } catch ( WPDieException $e ) { | ||
| } | ||
| $output = ob_get_clean(); | ||
|
|
||
| // The default handler uses single quotes for attributes in some cases. | ||
| $this->assertStringContainsString( "href='https://example.com'", $output ); | ||
| $this->assertStringContainsString( '>Go to Example</a>', $output ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Tests the wp_die() function. | ||
| * | ||
| * @group functions | ||
| * | ||
| * @covers ::wp_die | ||
| */ | ||
| class Tests_Functions_WpDie extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests that wp_die() calls the expected handler. | ||
| * | ||
| * @ticket 65655 | ||
| */ | ||
| public function test_wp_die_handler_selection() { | ||
| $filter = new MockAction(); | ||
| add_filter( 'wp_die_handler', array( $filter, 'filter' ) ); | ||
|
|
||
| try { | ||
| wp_die( 'Message', 'Title', array( 'exit' => false ) ); | ||
| } catch ( WPDieException $e ) { | ||
| // The default test handler throws this. | ||
| } | ||
|
|
||
| $this->assertSame( 1, $filter->get_call_count(), 'The wp_die_handler filter should have been called once.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_die() respects the Ajax handler filter. | ||
| * | ||
| * @ticket 65655 | ||
| * | ||
| * @runInSeparateProcess | ||
| * @preserveGlobalState disabled | ||
| */ | ||
| public function test_wp_die_ajax_handler_selection() { | ||
| if ( ! defined( 'DOING_AJAX' ) ) { | ||
| define( 'DOING_AJAX', true ); | ||
| } | ||
|
|
||
| $filter = new MockAction(); | ||
| add_filter( 'wp_die_ajax_handler', array( $filter, 'filter' ) ); | ||
|
|
||
| ob_start(); | ||
| try { | ||
| wp_die( 'Ajax Message', 'Ajax Title', array( 'exit' => false ) ); | ||
| } catch ( WPDieException $e ) { | ||
| } | ||
| ob_end_clean(); | ||
|
|
||
| $this->assertSame( 1, $filter->get_call_count(), 'The wp_die_ajax_handler filter should have been called once.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_die() handles WP_Error objects. | ||
| * | ||
| * @ticket 65655 | ||
| */ | ||
| public function test_wp_die_with_wp_error() { | ||
| $error = new WP_Error( 'test_error', 'Test Error Message' ); | ||
|
|
||
| // Use a simple variable to capture the first argument. | ||
| $captured_message = null; | ||
| add_filter( | ||
| 'wp_die_handler', | ||
| function ( $callback ) use ( &$captured_message ) { | ||
| return function ( $message ) use ( &$captured_message ) { | ||
| $captured_message = $message; | ||
| throw new WPDieException( 'Intercepted' ); | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| try { | ||
| wp_die( $error, '', array( 'exit' => false ) ); | ||
| } catch ( WPDieException $e ) { | ||
| } | ||
|
|
||
| $this->assertSame( $error, $captured_message, 'The error object should be passed as the first argument to the handler.' ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.