REST API: Update tests for [35653]
See #34551. git-svn-id: https://develop.svn.wordpress.org/trunk@35654 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a6aa1a0754
commit
6ad5ee9786
@ -663,10 +663,6 @@ function _oembed_rest_pre_serve_request( $served, $result, $request, $server ) {
|
|||||||
// Embed links inside the request.
|
// Embed links inside the request.
|
||||||
$data = $server->response_to_data( $result, false );
|
$data = $server->response_to_data( $result, false );
|
||||||
|
|
||||||
if ( 404 === $result->get_status() ) {
|
|
||||||
$data = $data[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! class_exists( 'SimpleXMLElement' ) ) {
|
if ( ! class_exists( 'SimpleXMLElement' ) ) {
|
||||||
status_header( 501 );
|
status_header( 501 );
|
||||||
die( get_status_header_desc( 501 ) );
|
die( get_status_header_desc( 501 ) );
|
||||||
|
@ -94,7 +94,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
|
|||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'rest_no_route', $data[0]['code'] );
|
$this->assertEquals( 'rest_no_route', $data['code'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_request_without_url_param() {
|
function test_request_without_url_param() {
|
||||||
@ -103,8 +103,8 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
|
|||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'rest_missing_callback_param', $data[0]['code'] );
|
$this->assertEquals( 'rest_missing_callback_param', $data['code'] );
|
||||||
$this->assertEquals( 'url', $data[0]['data']['params'][0] );
|
$this->assertEquals( 'url', $data['data']['params'][0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_request_with_bad_url() {
|
function test_request_with_bad_url() {
|
||||||
@ -114,7 +114,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
|
|||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'oembed_invalid_url', $data[0]['code'] );
|
$this->assertEquals( 'oembed_invalid_url', $data['code'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_request_invalid_format() {
|
function test_request_invalid_format() {
|
||||||
|
@ -246,10 +246,9 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
|||||||
$this->assertEquals( 500, $response->get_status() );
|
$this->assertEquals( 500, $response->get_status() );
|
||||||
|
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertCount( 1, $data );
|
|
||||||
|
|
||||||
$this->assertEquals( $code, $data[0]['code'] );
|
$this->assertEquals( $code, $data['code'] );
|
||||||
$this->assertEquals( $message, $data[0]['message'] );
|
$this->assertEquals( $message, $data['message'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_error_to_response_with_status() {
|
public function test_error_to_response_with_status() {
|
||||||
@ -263,18 +262,15 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
|||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertCount( 1, $data );
|
|
||||||
|
|
||||||
$this->assertEquals( $code, $data[0]['code'] );
|
$this->assertEquals( $code, $data['code'] );
|
||||||
$this->assertEquals( $message, $data[0]['message'] );
|
$this->assertEquals( $message, $data['message'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_rest_error() {
|
public function test_rest_error() {
|
||||||
$data = array(
|
$data = array(
|
||||||
array(
|
'code' => 'wp-api-test-error',
|
||||||
'code' => 'wp-api-test-error',
|
'message' => 'Message text',
|
||||||
'message' => 'Message text',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
$expected = wp_json_encode( $data );
|
$expected = wp_json_encode( $data );
|
||||||
$response = $this->server->json_error( 'wp-api-test-error', 'Message text' );
|
$response = $this->server->json_error( 'wp-api-test-error', 'Message text' );
|
||||||
@ -292,10 +288,8 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
|||||||
->with( $this->equalTo( 400 ) );
|
->with( $this->equalTo( 400 ) );
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
array(
|
'code' => 'wp-api-test-error',
|
||||||
'code' => 'wp-api-test-error',
|
'message' => 'Message text',
|
||||||
'message' => 'Message text',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
$expected = wp_json_encode( $data );
|
$expected = wp_json_encode( $data );
|
||||||
|
|
||||||
@ -417,9 +411,9 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
|||||||
$this->assertCount( 1, $up );
|
$this->assertCount( 1, $up );
|
||||||
|
|
||||||
$up_data = $up[0];
|
$up_data = $up[0];
|
||||||
$this->assertEquals( 'wp-api-test-error', $up_data[0]['code'] );
|
$this->assertEquals( 'wp-api-test-error', $up_data['code'] );
|
||||||
$this->assertEquals( 'Test message', $up_data[0]['message'] );
|
$this->assertEquals( 'Test message', $up_data['message'] );
|
||||||
$this->assertEquals( 403, $up_data[0]['data']['status'] );
|
$this->assertEquals( 403, $up_data['data']['status'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user