diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 87a77b572e..214c134d01 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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 ), ); } } diff --git a/tests/phpunit/tests/includes/helpers.php b/tests/phpunit/tests/includes/helpers.php index 3f440947bf..6e488b72f2 100644 --- a/tests/phpunit/tests/includes/helpers.php +++ b/tests/phpunit/tests/includes/helpers.php @@ -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. *