From 6ad5ee978692b164156a7d9a3220300cfae8fba5 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Tue, 17 Nov 2015 05:26:30 +0000 Subject: [PATCH] REST API: Update tests for [35653] See #34551. git-svn-id: https://develop.svn.wordpress.org/trunk@35654 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/embed-functions.php | 4 --- tests/phpunit/tests/oembed/controller.php | 8 +++--- tests/phpunit/tests/rest-api/rest-server.php | 28 ++++++++------------ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/wp-includes/embed-functions.php b/src/wp-includes/embed-functions.php index 4bd142a42a..85dd095ca7 100644 --- a/src/wp-includes/embed-functions.php +++ b/src/wp-includes/embed-functions.php @@ -663,10 +663,6 @@ function _oembed_rest_pre_serve_request( $served, $result, $request, $server ) { // Embed links inside the request. $data = $server->response_to_data( $result, false ); - if ( 404 === $result->get_status() ) { - $data = $data[0]; - } - if ( ! class_exists( 'SimpleXMLElement' ) ) { status_header( 501 ); die( get_status_header_desc( 501 ) ); diff --git a/tests/phpunit/tests/oembed/controller.php b/tests/phpunit/tests/oembed/controller.php index 9410e00fa0..5cca6967ff 100644 --- a/tests/phpunit/tests/oembed/controller.php +++ b/tests/phpunit/tests/oembed/controller.php @@ -94,7 +94,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase { $response = $this->server->dispatch( $request ); $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() { @@ -103,8 +103,8 @@ class Test_oEmbed_Controller extends WP_UnitTestCase { $response = $this->server->dispatch( $request ); $data = $response->get_data(); - $this->assertEquals( 'rest_missing_callback_param', $data[0]['code'] ); - $this->assertEquals( 'url', $data[0]['data']['params'][0] ); + $this->assertEquals( 'rest_missing_callback_param', $data['code'] ); + $this->assertEquals( 'url', $data['data']['params'][0] ); } function test_request_with_bad_url() { @@ -114,7 +114,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase { $response = $this->server->dispatch( $request ); $data = $response->get_data(); - $this->assertEquals( 'oembed_invalid_url', $data[0]['code'] ); + $this->assertEquals( 'oembed_invalid_url', $data['code'] ); } function test_request_invalid_format() { diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 2ec561a032..54a81a91c0 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -246,10 +246,9 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertEquals( 500, $response->get_status() ); $data = $response->get_data(); - $this->assertCount( 1, $data ); - $this->assertEquals( $code, $data[0]['code'] ); - $this->assertEquals( $message, $data[0]['message'] ); + $this->assertEquals( $code, $data['code'] ); + $this->assertEquals( $message, $data['message'] ); } 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() ); $data = $response->get_data(); - $this->assertCount( 1, $data ); - $this->assertEquals( $code, $data[0]['code'] ); - $this->assertEquals( $message, $data[0]['message'] ); + $this->assertEquals( $code, $data['code'] ); + $this->assertEquals( $message, $data['message'] ); } public function test_rest_error() { $data = array( - array( - 'code' => 'wp-api-test-error', - 'message' => 'Message text', - ), + 'code' => 'wp-api-test-error', + 'message' => 'Message text', ); $expected = wp_json_encode( $data ); $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 ) ); $data = array( - array( - 'code' => 'wp-api-test-error', - 'message' => 'Message text', - ), + 'code' => 'wp-api-test-error', + 'message' => 'Message text', ); $expected = wp_json_encode( $data ); @@ -417,9 +411,9 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertCount( 1, $up ); $up_data = $up[0]; - $this->assertEquals( 'wp-api-test-error', $up_data[0]['code'] ); - $this->assertEquals( 'Test message', $up_data[0]['message'] ); - $this->assertEquals( 403, $up_data[0]['data']['status'] ); + $this->assertEquals( 'wp-api-test-error', $up_data['code'] ); + $this->assertEquals( 'Test message', $up_data['message'] ); + $this->assertEquals( 403, $up_data['data']['status'] ); } /**