Make WordPress Core


Ignore:
Timestamp:
11/18/2015 06:28:55 PM (11 years ago)
Author:
johnbillion
Message:

Update WP_REST_Response::as_error() to handle the new format error responses introduced in [35653].

Props danielbachhuber
Fixes #34551

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r35659 r35671  
    283283        }
    284284
     285        public function test_error_to_response_to_error() {
     286                $code     = 'wp-api-test-error';
     287                $message  = 'Test error message for the API';
     288                $code2    = 'wp-api-test-error-2';
     289                $message2 = 'Another test message';
     290                $error   = new WP_Error( $code, $message, array( 'status' => 400 ) );
     291                $error->add( $code2, $message2, array( 'status' => 403 ) );
     292
     293                $response = $this->server->error_to_response( $error );
     294                $this->assertInstanceOf( 'WP_REST_Response', $response );
     295
     296                $this->assertEquals( 400, $response->get_status() );
     297
     298                $error = $response->as_error();
     299                $this->assertInstanceOf( 'WP_Error', $error );
     300                $this->assertEquals( $code, $error->get_error_code() );
     301                $this->assertEquals( $message, $error->get_error_message() );
     302                $this->assertEquals( $message2, $error->errors[ $code2 ][0] );
     303                $this->assertEquals( array( 'status' => 403 ), $error->error_data[ $code2 ] );
     304        }
     305
    285306        public function test_rest_error() {
    286307                $data = array(
Note: See TracChangeset for help on using the changeset viewer.