Make WordPress Core

source: trunk/tests/phpunit/includes/testcase-rest-api.php @ 37475

Last change on this file since 37475 was 34928, checked in by rmccue, 10 years ago

REST API: Introduce baby API to the world.

Baby API was born at 2.8KLOC on October 8th at 2:30 UTC. API has lots
of growing to do, so wish it the best of luck.

Thanks to everyone who helped along the way:

Props rmccue, rachelbaker, danielbachhuber, joehoyle, drewapicture,
adamsilverstein, netweb, tlovett1, shelob9, kadamwhite, pento,
westonruter, nikv, tobych, redsweater, alecuf, pollyplummer, hurtige,
bpetty, oso96_2000, ericlewis, wonderboymusic, joshkadis, mordauk,
jdgrimes, johnbillion, jeremyfelt, thiago-negri, jdolan, pkevan,
iseulde, thenbrent, maxcutler, kwight, markoheijnen, phh, natewr,
jjeaton, shprink, mattheu, quasel, jmusal, codebykat, hubdotcom,
tapsboy, QWp6t, pushred, jaredcobb, justinsainton, japh, matrixik,
jorbin, frozzare, codfish, michael-arestad, kellbot, ironpaperweight,
simonlampen, alisspers, eliorivero, davidbhayes, JohnDittmar, dimadin,
traversal, cmmarslender, Toddses, kokarn, welcher, and ericpedia.

Fixes #33982.

File size: 532 bytes
Line 
1<?php
2
3abstract class WP_Test_REST_TestCase extends WP_UnitTestCase {
4        protected function assertErrorResponse( $code, $response, $status = null ) {
5
6                if ( is_a( $response, 'WP_REST_Response' ) ) {
7                        $response = $response->as_error();
8                }
9
10                $this->assertInstanceOf( 'WP_Error', $response );
11                $this->assertEquals( $code, $response->get_error_code() );
12
13                if ( null !== $status ) {
14                        $data = $response->get_error_data();
15                        $this->assertArrayHasKey( 'status', $data );
16                        $this->assertEquals( $status, $data['status'] );
17                }
18        }
19}
Note: See TracBrowser for help on using the repository browser.