Changeset 58039
- Timestamp:
- 04/23/2024 06:55:26 PM (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase-rest-api.php
r56352 r58039 2 2 3 3 abstract class WP_Test_REST_TestCase extends WP_UnitTestCase { 4 protected function assertErrorResponse( $code, $response, $status = null ) { 4 5 /** 6 * Asserts that the REST API response has the specified error. 7 * 8 * @since 4.4.0 9 * @since 6.6.0 Added the `$message` parameter. 10 * 11 * @param string|int $code Expected error code. 12 * @param WP_REST_Response|WP_Error $response REST API response. 13 * @param int $status Optional. Status code. 14 * @param string $message Optional. Message to display when the assertion fails. 15 */ 16 protected function assertErrorResponse( $code, $response, $status = null, $message = '' ) { 5 17 6 18 if ( $response instanceof WP_REST_Response ) { … … 8 20 } 9 21 10 $this->assertWPError( $response );11 $this->assertSame( $code, $response->get_error_code() );22 $this->assertWPError( $response, $message ); 23 $this->assertSame( $code, $response->get_error_code(), $message ); 12 24 13 25 if ( null !== $status ) { 14 26 $data = $response->get_error_data(); 15 $this->assertArrayHasKey( 'status', $data );16 $this->assertSame( $status, $data['status'] );27 $this->assertArrayHasKey( 'status', $data, $message ); 28 $this->assertSame( $status, $data['status'], $message ); 17 29 } 18 30 }
Note: See TracChangeset
for help on using the changeset viewer.