testcase-rest-api.php 513 B

12345678910111213141516171819
  1. <?php
  2. abstract class WP_Test_REST_TestCase extends WP_UnitTestCase {
  3. protected function assertErrorResponse( $code, $response, $status = null ) {
  4. if ( is_a( $response, 'WP_REST_Response' ) ) {
  5. $response = $response->as_error();
  6. }
  7. $this->assertWPError( $response );
  8. $this->assertSame( $code, $response->get_error_code() );
  9. if ( null !== $status ) {
  10. $data = $response->get_error_data();
  11. $this->assertArrayHasKey( 'status', $data );
  12. $this->assertSame( $status, $data['status'] );
  13. }
  14. }
  15. }