Bootstrap/Load: Fix fatal error when passing a WP_Error to wp_die().

This was introduced in [44466]. Also, this changeset adds tests for `_wp_die_process_input()` so that this never happens again.

Props dd32.
See #45933.


git-svn-id: https://develop.svn.wordpress.org/trunk@44690 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz 2019-01-22 08:51:56 +00:00
parent 687590d898
commit fbe0605156
2 changed files with 104 additions and 1 deletions

View File

@ -3374,7 +3374,7 @@ function _wp_die_process_input( $message, $title = '', $args = array() ) {
$errors[] = array(
'code' => $error_code,
'message' => $error_message,
'data' => $error->get_error_data( $error_code ),
'data' => $message->get_error_data( $error_code ),
);
}
}

View File

@ -274,6 +274,109 @@ class Tests_TestHelpers extends WP_UnitTestCase {
wp_die( new WP_Error( 'test', 'test' ) );
}
/**
* @ticket 45933
* @dataProvider data_die_process_input
*/
public function test_die_process_input( $input, $expected ) {
$defaults = array(
'message' => '',
'title' => '',
'args' => array(),
);
$input = wp_parse_args(
$input,
$defaults
);
$expected = wp_parse_args(
$expected,
$defaults
);
list( $message, $title, $args ) = _wp_die_process_input( $input['message'], $input['title'], $input['args'] );
$this->assertSame( $expected['message'], $message );
$this->assertSame( $expected['title'], $title );
// Only check arguments that are explicitly asked for.
$this->assertEqualSets( $expected['args'], array_intersect_key( $args, $expected['args'] ) );
}
public function data_die_process_input() {
return array(
array(
array(
'message' => 'Broken.',
),
array(
'message' => 'Broken.',
'title' => 'WordPress › Error',
'args' => array(
'response' => 500,
'code' => 'wp_die',
'text_direction' => 'ltr',
),
),
),
array(
array(
'message' => 'Broken.',
'title' => 'Fatal Error',
'args' => array(
'response' => null,
),
),
array(
'message' => 'Broken.',
'title' => 'Fatal Error',
'args' => array(
'response' => 500,
),
),
),
array(
array(
'message' => 'More breakage.',
'args' => array(
'response' => 400,
'code' => 'custom_code',
'text_direction' => 'rtl',
),
),
array(
'message' => 'More breakage.',
'title' => 'WordPress › Error',
'args' => array(
'response' => 400,
'code' => 'custom_code',
'text_direction' => 'rtl',
),
),
),
array(
array(
'message' => new WP_Error(
'no_access',
'You do not have access.',
array(
'status' => 403,
'title' => 'Permission Error',
)
),
),
array(
'message' => 'You do not have access.',
'title' => 'Permission Error',
'args' => array(
'response' => 403,
'code' => 'no_access',
),
),
),
);
}
/**
* This test is just a setup for the one that follows.
*