Make WordPress Core


Ignore:
Timestamp:
02/21/2018 04:24:30 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Tests: Replace use of $this->server with rest_get_server() for better memory recycling.

Props danielbachhuber.
Fixes #41641.

File:
1 edited

Legend:

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

    r42423 r42724  
    111111
    112112    public function test_register_routes() {
    113         $routes = $this->server->get_routes();
     113        $routes = rest_get_server()->get_routes();
    114114
    115115        $this->assertArrayHasKey( '/wp/v2/posts', $routes );
     
    122122        // Collection
    123123        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    124         $response = $this->server->dispatch( $request );
     124        $response = rest_get_server()->dispatch( $request );
    125125        $data     = $response->get_data();
    126126        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    128128        // Single
    129129        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id );
    130         $response = $this->server->dispatch( $request );
     130        $response = rest_get_server()->dispatch( $request );
    131131        $data     = $response->get_data();
    132132        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    136136    public function test_registered_query_params() {
    137137        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    138         $response = $this->server->dispatch( $request );
     138        $response = rest_get_server()->dispatch( $request );
    139139        $data     = $response->get_data();
    140140        $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    168168    public function test_registered_get_item_params() {
    169169        $request  = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    170         $response = $this->server->dispatch( $request );
     170        $response = rest_get_server()->dispatch( $request );
    171171        $data     = $response->get_data();
    172172        $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    177177    public function test_get_items() {
    178178        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    179         $response = $this->server->dispatch( $request );
     179        $response = rest_get_server()->dispatch( $request );
    180180
    181181        $this->check_get_posts_response( $response );
     
    194194            )
    195195        );
    196         $response = $this->server->dispatch( $request );
     196        $response = rest_get_server()->dispatch( $request );
    197197
    198198        $this->assertEmpty( $response->get_data() );
     
    205205        // All 3 posts
    206206        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    207         $response = $this->server->dispatch( $request );
     207        $response = rest_get_server()->dispatch( $request );
    208208        $this->assertEquals( 200, $response->get_status() );
    209209        $this->assertEquals( 3, count( $response->get_data() ) );
     
    211211        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    212212        $request->set_param( 'author', array( self::$editor_id, self::$author_id ) );
    213         $response = $this->server->dispatch( $request );
     213        $response = rest_get_server()->dispatch( $request );
    214214        $this->assertEquals( 200, $response->get_status() );
    215215        $data = $response->get_data();
     
    219219        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    220220        $request->set_param( 'author', self::$editor_id );
    221         $response = $this->server->dispatch( $request );
     221        $response = rest_get_server()->dispatch( $request );
    222222        $this->assertEquals( 200, $response->get_status() );
    223223        $data = $response->get_data();
     
    231231        // All 3 posts
    232232        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    233         $response = $this->server->dispatch( $request );
     233        $response = rest_get_server()->dispatch( $request );
    234234        $this->assertEquals( 200, $response->get_status() );
    235235        $this->assertEquals( 3, count( $response->get_data() ) );
     
    237237        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    238238        $request->set_param( 'author_exclude', array( self::$editor_id, self::$author_id ) );
    239         $response = $this->server->dispatch( $request );
     239        $response = rest_get_server()->dispatch( $request );
    240240        $this->assertEquals( 200, $response->get_status() );
    241241        $data = $response->get_data();
     
    246246        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    247247        $request->set_param( 'author_exclude', self::$editor_id );
    248         $response = $this->server->dispatch( $request );
     248        $response = rest_get_server()->dispatch( $request );
    249249        $this->assertEquals( 200, $response->get_status() );
    250250        $data = $response->get_data();
     
    255255        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    256256        $request->set_param( 'author_exclude', 'invalid' );
    257         $response = $this->server->dispatch( $request );
     257        $response = rest_get_server()->dispatch( $request );
    258258        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    259259    }
     
    266266        // Orderby=>desc
    267267        $request->set_param( 'include', array( $id1, $id3 ) );
    268         $response = $this->server->dispatch( $request );
     268        $response = rest_get_server()->dispatch( $request );
    269269        $data     = $response->get_data();
    270270        $this->assertEquals( 2, count( $data ) );
     
    273273        // Orderby=>include
    274274        $request->set_param( 'orderby', 'include' );
    275         $response = $this->server->dispatch( $request );
     275        $response = rest_get_server()->dispatch( $request );
    276276        $data     = $response->get_data();
    277277        $this->assertEquals( 2, count( $data ) );
     
    281281        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    282282        $request->set_param( 'include', 'invalid' );
    283         $response = $this->server->dispatch( $request );
     283        $response = rest_get_server()->dispatch( $request );
    284284        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    285285    }
     
    309309        $request->set_param( 'orderby', 'author' );
    310310
    311         $response = $this->server->dispatch( $request );
     311        $response = rest_get_server()->dispatch( $request );
    312312        $data     = $response->get_data();
    313313
     
    333333        $request->set_param( 'orderby', 'modified' );
    334334
    335         $response = $this->server->dispatch( $request );
     335        $response = rest_get_server()->dispatch( $request );
    336336        $data     = $response->get_data();
    337337
     
    369369        $request->set_param( 'orderby', 'parent' );
    370370
    371         $response = $this->server->dispatch( $request );
     371        $response = rest_get_server()->dispatch( $request );
    372372        $data     = $response->get_data();
    373373
     
    386386        $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    387387        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    388         $response = $this->server->dispatch( $request );
     388        $response = rest_get_server()->dispatch( $request );
    389389        $data     = $response->get_data();
    390390        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     
    392392
    393393        $request->set_param( 'exclude', array( $id2 ) );
    394         $response = $this->server->dispatch( $request );
     394        $response = rest_get_server()->dispatch( $request );
    395395        $data     = $response->get_data();
    396396        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     
    398398
    399399        $request->set_param( 'exclude', "$id2" );
    400         $response = $this->server->dispatch( $request );
     400        $response = rest_get_server()->dispatch( $request );
    401401        $data     = $response->get_data();
    402402        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     
    404404
    405405        $request->set_param( 'exclude', 'invalid' );
    406         $response = $this->server->dispatch( $request );
     406        $response = rest_get_server()->dispatch( $request );
    407407        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    408408    }
     
    419419        );
    420420        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    421         $response = $this->server->dispatch( $request );
     421        $response = rest_get_server()->dispatch( $request );
    422422        $this->assertEquals( 7, count( $response->get_data() ) );
    423423        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    424424        $request->set_param( 'search', 'Search Result' );
    425         $response = $this->server->dispatch( $request );
     425        $response = rest_get_server()->dispatch( $request );
    426426        $data     = $response->get_data();
    427427        $this->assertEquals( 1, count( $data ) );
     
    444444        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    445445        $request->set_param( 'slug', 'apple' );
    446         $response = $this->server->dispatch( $request );
     446        $response = rest_get_server()->dispatch( $request );
    447447        $this->assertEquals( 200, $response->get_status() );
    448448        $data = $response->get_data();
     
    472472        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    473473        $request->set_param( 'slug', array( 'banana', 'peach' ) );
    474         $response = $this->server->dispatch( $request );
     474        $response = rest_get_server()->dispatch( $request );
    475475        $this->assertEquals( 200, $response->get_status() );
    476476        $data = $response->get_data();
     
    505505        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    506506        $request->set_param( 'slug', 'apple,banana' );
    507         $response = $this->server->dispatch( $request );
     507        $response = rest_get_server()->dispatch( $request );
    508508        $this->assertEquals( 200, $response->get_status() );
    509509        $data = $response->get_data();
     
    522522        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    523523        $request->set_param( 'status', 'publish' );
    524         $response = $this->server->dispatch( $request );
     524        $response = rest_get_server()->dispatch( $request );
    525525        $this->assertEquals( 200, $response->get_status() );
    526526        $this->assertEquals( 1, count( $response->get_data() ) );
    527527        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    528528        $request->set_param( 'status', 'draft' );
    529         $response = $this->server->dispatch( $request );
     529        $response = rest_get_server()->dispatch( $request );
    530530        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    531531        wp_set_current_user( self::$editor_id );
    532532        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    533533        $request->set_param( 'status', 'draft' );
    534         $response = $this->server->dispatch( $request );
     534        $response = rest_get_server()->dispatch( $request );
    535535        $this->assertEquals( 200, $response->get_status() );
    536536        $this->assertEquals( 1, count( $response->get_data() ) );
     
    548548        $request->set_param( 'status', 'draft,private' );
    549549
    550         $response = $this->server->dispatch( $request );
     550        $response = rest_get_server()->dispatch( $request );
    551551        $this->assertEquals( 200, $response->get_status() );
    552552        $data = $response->get_data();
     
    571571        $request->set_param( 'status', array( 'draft', 'pending' ) );
    572572
    573         $response = $this->server->dispatch( $request );
     573        $response = rest_get_server()->dispatch( $request );
    574574        $this->assertEquals( 200, $response->get_status() );
    575575        $data = $response->get_data();
     
    587587        $request->set_param( 'context', 'edit' );
    588588        $request->set_param( 'status', array( 'draft', 'nonsense' ) );
    589         $response = $this->server->dispatch( $request );
     589        $response = rest_get_server()->dispatch( $request );
    590590        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    591591    }
     
    595595        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    596596        $request->set_param( 'status', 'invalid' );
    597         $response = $this->server->dispatch( $request );
     597        $response = rest_get_server()->dispatch( $request );
    598598        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    599599    }
     
    608608
    609609        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    610         $response = $this->server->dispatch( $request );
     610        $response = rest_get_server()->dispatch( $request );
    611611
    612612        $this->assertEquals( 200, $response->get_status() );
     
    647647        // order defaults to 'desc'
    648648        $request->set_param( 'orderby', 'title' );
    649         $response = $this->server->dispatch( $request );
     649        $response = rest_get_server()->dispatch( $request );
    650650        $data     = $response->get_data();
    651651        $this->assertEquals( 'Apple Sauce', $data[0]['title']['rendered'] );
     
    653653        // order=>asc
    654654        $request->set_param( 'order', 'asc' );
    655         $response = $this->server->dispatch( $request );
     655        $response = rest_get_server()->dispatch( $request );
    656656        $data     = $response->get_data();
    657657        $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] );
     
    659659        // order=>asc,id should fail
    660660        $request->set_param( 'order', 'asc,id' );
    661         $response = $this->server->dispatch( $request );
     661        $response = rest_get_server()->dispatch( $request );
    662662        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    663663        // orderby=>content should fail (invalid param test)
    664664        $request->set_param( 'order', 'asc' );
    665665        $request->set_param( 'orderby', 'content' );
    666         $response = $this->server->dispatch( $request );
     666        $response = rest_get_server()->dispatch( $request );
    667667        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    668668    }
     
    673673        $request->set_param( 'orderby', 'include' );
    674674
    675         $response = $this->server->dispatch( $request );
     675        $response = rest_get_server()->dispatch( $request );
    676676
    677677        $this->assertErrorResponse( 'rest_orderby_include_missing_include', $response, 400 );
     
    702702        $request->set_param( 'include', array( $id1, $id2, $id3 ) );
    703703
    704         $response = $this->server->dispatch( $request );
     704        $response = rest_get_server()->dispatch( $request );
    705705        $data     = $response->get_data();
    706706
     
    732732        $request->set_param( 'include', array( $id1, $id2 ) );
    733733
    734         $response = $this->server->dispatch( $request );
     734        $response = rest_get_server()->dispatch( $request );
    735735        $data     = $response->get_data();
    736736
     
    757757        $request->set_param( 'slug', array( 'taco', 'chalupa', 'burrito' ) );
    758758
    759         $response = $this->server->dispatch( $request );
     759        $response = rest_get_server()->dispatch( $request );
    760760        $data     = $response->get_data();
    761761
     
    783783        $request->set_param( 'orderby', 'relevance' );
    784784        $request->set_param( 'search', 'relevant' );
    785         $response = $this->server->dispatch( $request );
     785        $response = rest_get_server()->dispatch( $request );
    786786        $this->assertEquals( 200, $response->get_status() );
    787787        $data = $response->get_data();
     
    810810        $request->set_param( 'orderby', 'relevance' );
    811811        $request->set_param( 'search', 'relevant content' );
    812         $response = $this->server->dispatch( $request );
     812        $response = rest_get_server()->dispatch( $request );
    813813        $this->assertEquals( 200, $response->get_status() );
    814814        $data = $response->get_data();
     
    822822        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    823823        $request->set_param( 'orderby', 'relevance' );
    824         $response = $this->server->dispatch( $request );
     824        $response = rest_get_server()->dispatch( $request );
    825825        $this->assertErrorResponse( 'rest_no_search_term_defined', $response, 400 );
    826826    }
     
    833833        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    834834        $request->set_param( 'offset', 1 );
    835         $response = $this->server->dispatch( $request );
     835        $response = rest_get_server()->dispatch( $request );
    836836        $this->assertCount( 3, $response->get_data() );
    837837        // 'offset' works with 'per_page'
    838838        $request->set_param( 'per_page', 2 );
    839         $response = $this->server->dispatch( $request );
     839        $response = rest_get_server()->dispatch( $request );
    840840        $this->assertCount( 2, $response->get_data() );
    841841        // 'offset' takes priority over 'page'
    842842        $request->set_param( 'page', 2 );
    843         $response = $this->server->dispatch( $request );
     843        $response = rest_get_server()->dispatch( $request );
    844844        $this->assertCount( 2, $response->get_data() );
    845845        // Invalid 'offset' should error
    846846        $request->set_param( 'offset', 'moreplease' );
    847         $response = $this->server->dispatch( $request );
     847        $response = rest_get_server()->dispatch( $request );
    848848        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    849849    }
     
    860860        $request->set_param( 'tags', array( $tag['term_id'] ) );
    861861
    862         $response = $this->server->dispatch( $request );
     862        $response = rest_get_server()->dispatch( $request );
    863863        $data     = $response->get_data();
    864864        $this->assertCount( 1, $data );
     
    877877        $request->set_param( 'tags_exclude', array( $tag['term_id'] ) );
    878878
    879         $response = $this->server->dispatch( $request );
     879        $response = rest_get_server()->dispatch( $request );
    880880        $data     = $response->get_data();
    881881        $this->assertCount( 3, $data );
     
    901901        $request->set_param( 'categories', array( $category['term_id'] ) );
    902902
    903         $response = $this->server->dispatch( $request );
     903        $response = rest_get_server()->dispatch( $request );
    904904        $this->assertCount( 1, $response->get_data() );
    905905
    906906        $request->set_param( 'tags', array( 'my-tag' ) );
    907         $response = $this->server->dispatch( $request );
     907        $response = rest_get_server()->dispatch( $request );
    908908        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    909909    }
     
    925925        $request->set_param( 'categories_exclude', array( $category['term_id'] ) );
    926926
    927         $response = $this->server->dispatch( $request );
     927        $response = rest_get_server()->dispatch( $request );
    928928        $data     = $response->get_data();
    929929        $this->assertCount( 1, $data );
     
    931931
    932932        $request->set_param( 'tags_exclude', array( 'my-tag' ) );
    933         $response = $this->server->dispatch( $request );
     933        $response = rest_get_server()->dispatch( $request );
    934934        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    935935    }
     
    944944        $request->set_param( 'sticky', true );
    945945
    946         $response = $this->server->dispatch( $request );
     946        $response = rest_get_server()->dispatch( $request );
    947947        $this->assertCount( 1, $response->get_data() );
    948948
     
    952952
    953953        $request->set_param( 'sticky', 'nothanks' );
    954         $response = $this->server->dispatch( $request );
     954        $response = rest_get_server()->dispatch( $request );
    955955        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    956956    }
     
    967967        $request->set_param( 'include', array( $id1 ) );
    968968
    969         $response = $this->server->dispatch( $request );
     969        $response = rest_get_server()->dispatch( $request );
    970970        $this->assertCount( 0, $response->get_data() );
    971971
     
    982982        $request->set_param( 'include', array( $id1 ) );
    983983
    984         $response = $this->server->dispatch( $request );
     984        $response = rest_get_server()->dispatch( $request );
    985985
    986986        $this->assertCount( 1, $response->get_data() );
     
    10011001        $request->set_param( 'sticky', true );
    10021002
    1003         $response = $this->server->dispatch( $request );
     1003        $response = rest_get_server()->dispatch( $request );
    10041004        $this->assertCount( 0, $response->get_data() );
    10051005
     
    10201020        $request->set_param( 'include', array( $id1 ) );
    10211021
    1022         $response = $this->server->dispatch( $request );
     1022        $response = rest_get_server()->dispatch( $request );
    10231023        $this->assertCount( 0, $response->get_data() );
    10241024
     
    10391039        $request->set_param( 'sticky', false );
    10401040
    1041         $response = $this->server->dispatch( $request );
     1041        $response = rest_get_server()->dispatch( $request );
    10421042        $this->assertCount( 1, $response->get_data() );
    10431043
     
    10601060        $request->set_param( 'exclude', array( $id3 ) );
    10611061
    1062         $response = $this->server->dispatch( $request );
     1062        $response = rest_get_server()->dispatch( $request );
    10631063        $this->assertCount( 1, $response->get_data() );
    10641064
     
    10811081        $request->set_param( 'exclude', array( $id3 ) );
    10821082
    1083         $response = $this->server->dispatch( $request );
     1083        $response = rest_get_server()->dispatch( $request );
    10841084        $this->assertCount( 2, $response->get_data() );
    10851085
     
    11021102        }
    11031103        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    1104         $response = $this->server->dispatch( $request );
     1104        $response = rest_get_server()->dispatch( $request );
    11051105        $headers  = $response->get_headers();
    11061106        $this->assertEquals( 50, $headers['X-WP-Total'] );
     
    11211121        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    11221122        $request->set_param( 'page', 3 );
    1123         $response = $this->server->dispatch( $request );
     1123        $response = rest_get_server()->dispatch( $request );
    11241124        $headers  = $response->get_headers();
    11251125        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    11401140        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    11411141        $request->set_param( 'page', 6 );
    1142         $response = $this->server->dispatch( $request );
     1142        $response = rest_get_server()->dispatch( $request );
    11431143        $headers  = $response->get_headers();
    11441144        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    11551155        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    11561156        $request->set_param( 'page', 8 );
    1157         $response = $this->server->dispatch( $request );
     1157        $response = rest_get_server()->dispatch( $request );
    11581158        $headers  = $response->get_headers();
    11591159        $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 );
     
    11671167            )
    11681168        );
    1169         $response = $this->server->dispatch( $request );
     1169        $response = rest_get_server()->dispatch( $request );
    11701170        $headers  = $response->get_headers();
    11711171        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    11931193        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    11941194        $request->set_param( 'status', 'draft' );
    1195         $response = $this->server->dispatch( $request );
     1195        $response = rest_get_server()->dispatch( $request );
    11961196        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    11971197
    11981198        // But they are accessible to authorized users
    11991199        wp_set_current_user( self::$editor_id );
    1200         $response = $this->server->dispatch( $request );
     1200        $response = rest_get_server()->dispatch( $request );
    12011201        $data     = $response->get_data();
    12021202        $this->assertCount( 1, $data );
     
    12071207        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    12081208        $request->set_query_params( array( 'per_page' => -1 ) );
    1209         $response = $this->server->dispatch( $request );
     1209        $response = rest_get_server()->dispatch( $request );
    12101210        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    12111211    }
     
    12181218        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    12191219        $request->set_param( 'page', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    1220         $response = $this->server->dispatch( $request );
     1220        $response = rest_get_server()->dispatch( $request );
    12211221        $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 );
    12221222    }
     
    12251225        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    12261226        $request->set_param( 'context', 'banana' );
    1227         $response = $this->server->dispatch( $request );
     1227        $response = rest_get_server()->dispatch( $request );
    12281228        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    12291229    }
     
    12331233        $request->set_param( 'after', rand_str() );
    12341234        $request->set_param( 'before', rand_str() );
    1235         $response = $this->server->dispatch( $request );
     1235        $response = rest_get_server()->dispatch( $request );
    12361236        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    12371237    }
     
    12451245        $request->set_param( 'after', '2016-01-15T00:00:00Z' );
    12461246        $request->set_param( 'before', '2016-01-17T00:00:00Z' );
    1247         $response = $this->server->dispatch( $request );
     1247        $response = rest_get_server()->dispatch( $request );
    12481248        $data     = $response->get_data();
    12491249        $this->assertCount( 1, $data );
     
    12531253    public function test_get_items_all_post_formats() {
    12541254        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    1255         $response = $this->server->dispatch( $request );
     1255        $response = rest_get_server()->dispatch( $request );
    12561256        $data     = $response->get_data();
    12571257
     
    12631263    public function test_get_item() {
    12641264        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1265         $response = $this->server->dispatch( $request );
     1265        $response = rest_get_server()->dispatch( $request );
    12661266
    12671267        $this->check_get_post_response( $response, 'view' );
     
    12701270    public function test_get_item_links() {
    12711271        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1272         $response = $this->server->dispatch( $request );
     1272        $response = rest_get_server()->dispatch( $request );
    12731273
    12741274        $links = $response->get_links();
     
    13131313    public function test_get_item_links_no_author() {
    13141314        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1315         $response = $this->server->dispatch( $request );
     1315        $response = rest_get_server()->dispatch( $request );
    13161316        $links    = $response->get_links();
    13171317        $this->assertFalse( isset( $links['author'] ) );
     
    13231323        );
    13241324        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1325         $response = $this->server->dispatch( $request );
     1325        $response = rest_get_server()->dispatch( $request );
    13261326        $links    = $response->get_links();
    13271327        $this->assertEquals( rest_url( '/wp/v2/users/' . self::$author_id ), $links['author'][0]['href'] );
     
    13371337
    13381338        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $draft_id ) );
    1339         $response = $this->server->dispatch( $request );
     1339        $response = rest_get_server()->dispatch( $request );
    13401340
    13411341        $this->assertErrorResponse( 'rest_forbidden', $response, 401 );
     
    13441344    public function test_get_post_invalid_id() {
    13451345        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    1346         $response = $this->server->dispatch( $request );
     1346        $response = rest_get_server()->dispatch( $request );
    13471347
    13481348        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    13591359        wp_set_current_user( self::$editor_id );
    13601360
    1361         $response = $this->server->dispatch( $request );
     1361        $response = rest_get_server()->dispatch( $request );
    13621362
    13631363        $this->check_get_posts_response( $response, 'edit' );
     
    13721372            )
    13731373        );
    1374         $response = $this->server->dispatch( $request );
     1374        $response = rest_get_server()->dispatch( $request );
    13751375
    13761376        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
     
    13851385            )
    13861386        );
    1387         $response = $this->server->dispatch( $request );
     1387        $response = rest_get_server()->dispatch( $request );
    13881388
    13891389        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
     
    13981398
    13991399        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    1400         $response = $this->server->dispatch( $request );
     1400        $response = rest_get_server()->dispatch( $request );
    14011401
    14021402        $this->check_get_post_response( $response, 'view' );
     
    14211421        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    14221422        $request->set_param( 'password', '$inthebananastand' );
    1423         $response = $this->server->dispatch( $request );
     1423        $response = rest_get_server()->dispatch( $request );
    14241424
    14251425        $this->check_get_post_response( $response, 'view' );
     
    14421442        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    14431443        $request->set_param( 'password', 'wrongpassword' );
    1444         $response = $this->server->dispatch( $request );
     1444        $response = rest_get_server()->dispatch( $request );
    14451445
    14461446        $this->assertErrorResponse( 'rest_post_incorrect_password', $response, 403 );
     
    14561456        );
    14571457        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    1458         $response = $this->server->dispatch( $request );
     1458        $response = rest_get_server()->dispatch( $request );
    14591459        $data     = $response->get_data();
    14601460        $this->check_get_post_response( $response, 'view' );
     
    14761476        );
    14771477        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1478         $response = $this->server->dispatch( $request );
     1478        $response = rest_get_server()->dispatch( $request );
    14791479        $this->assertEquals( 200, $response->get_status() );
    14801480        // Private status
     
    14861486        );
    14871487        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1488         $response = $this->server->dispatch( $request );
     1488        $response = rest_get_server()->dispatch( $request );
    14891489        $this->assertEquals( 401, $response->get_status() );
    14901490    }
     
    14951495        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    14961496        $request->set_query_params( array( 'context' => 'edit' ) );
    1497         $response = $this->server->dispatch( $request );
     1497        $response = rest_get_server()->dispatch( $request );
    14981498
    14991499        $this->check_get_post_response( $response, 'edit' );
     
    15071507        $params = $this->set_post_data();
    15081508        $request->set_body_params( $params );
    1509         $response = $this->server->dispatch( $request );
     1509        $response = rest_get_server()->dispatch( $request );
    15101510
    15111511        $this->check_create_post_response( $response );
     
    15981598            $request->set_param( 'date_gmt', $params['date_gmt'] );
    15991599        }
    1600         $response = $this->server->dispatch( $request );
     1600        $response = rest_get_server()->dispatch( $request );
    16011601
    16021602        update_option( 'timezone_string', '' );
     
    16351635        );
    16361636        $request->set_body_params( $params );
    1637         $response = $this->server->dispatch( $request );
     1637        $response = rest_get_server()->dispatch( $request );
    16381638
    16391639        $data          = $response->get_data();
     
    16591659        );
    16601660        $request->set_body_params( $params );
    1661         $response = $this->server->dispatch( $request );
     1661        $response = rest_get_server()->dispatch( $request );
    16621662
    16631663        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    16791679        );
    16801680        $request->set_body_params( $params );
    1681         $response = $this->server->dispatch( $request );
     1681        $response = rest_get_server()->dispatch( $request );
    16821682
    16831683        $data          = $response->get_data();
     
    16951695        $params = $this->set_post_data();
    16961696        $request->set_body( wp_json_encode( $params ) );
    1697         $response = $this->server->dispatch( $request );
     1697        $response = rest_get_server()->dispatch( $request );
    16981698
    16991699        $this->check_create_post_response( $response );
     
    17101710        );
    17111711        $request->set_body_params( $params );
    1712         $response = $this->server->dispatch( $request );
     1712        $response = rest_get_server()->dispatch( $request );
    17131713
    17141714        $this->assertErrorResponse( 'rest_post_exists', $response, 400 );
     
    17291729
    17301730        $request->set_body_params( $params );
    1731         $response = $this->server->dispatch( $request );
     1731        $response = rest_get_server()->dispatch( $request );
    17321732        $this->assertEquals( 201, $response->get_status() );
    17331733
     
    17521752        );
    17531753        $request->set_body_params( $params );
    1754         $response = $this->server->dispatch( $request );
     1754        $response = rest_get_server()->dispatch( $request );
    17551755
    17561756        $new_data = $response->get_data();
     
    17711771        );
    17721772        $request->set_body_params( $params );
    1773         $response = $this->server->dispatch( $request );
     1773        $response = rest_get_server()->dispatch( $request );
    17741774
    17751775        $this->assertErrorResponse( 'rest_cannot_assign_sticky', $response, 403 );
     
    17861786        );
    17871787        $request->set_body_params( $params );
    1788         $response = $this->server->dispatch( $request );
     1788        $response = rest_get_server()->dispatch( $request );
    17891789
    17901790        $this->assertErrorResponse( 'rest_cannot_edit_others', $response, 403 );
     
    18011801        );
    18021802        $request->set_body_params( $params );
    1803         $response = $this->server->dispatch( $request );
     1803        $response = rest_get_server()->dispatch( $request );
    18041804
    18051805        $this->assertErrorResponse( 'rest_cannot_create', $response, 401 );
     
    18161816        );
    18171817        $request->set_body_params( $params );
    1818         $response = $this->server->dispatch( $request );
     1818        $response = rest_get_server()->dispatch( $request );
    18191819
    18201820        $data     = $response->get_data();
     
    18401840        );
    18411841        $request->set_body_params( $params );
    1842         $response = $this->server->dispatch( $request );
     1842        $response = rest_get_server()->dispatch( $request );
    18431843
    18441844        $data     = $response->get_data();
     
    18641864        );
    18651865        $request->set_body_params( $params );
    1866         $response = $this->server->dispatch( $request );
     1866        $response = rest_get_server()->dispatch( $request );
    18671867
    18681868        $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 );
     
    18841884        );
    18851885        $request->set_body_params( $params );
    1886         $response = $this->server->dispatch( $request );
     1886        $response = rest_get_server()->dispatch( $request );
    18871887
    18881888        $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 );
     
    18991899        );
    19001900        $request->set_body_params( $params );
    1901         $response = $this->server->dispatch( $request );
     1901        $response = rest_get_server()->dispatch( $request );
    19021902
    19031903        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    19141914        );
    19151915        $request->set_body_params( $params );
    1916         $response = $this->server->dispatch( $request );
     1916        $response = rest_get_server()->dispatch( $request );
    19171917
    19181918        $data     = $response->get_data();
     
    19321932        );
    19331933        $request->set_body_params( $params );
    1934         $response = $this->server->dispatch( $request );
     1934        $response = rest_get_server()->dispatch( $request );
    19351935
    19361936        $data     = $response->get_data();
     
    19501950        );
    19511951        $request->set_body_params( $params );
    1952         $response = $this->server->dispatch( $request );
     1952        $response = rest_get_server()->dispatch( $request );
    19531953
    19541954        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    19701970        );
    19711971        $request->set_body_params( $params );
    1972         $response = $this->server->dispatch( $request );
     1972        $response = rest_get_server()->dispatch( $request );
    19731973        $this->assertEquals( 201, $response->get_status() );
    19741974
     
    19961996        );
    19971997        $request->set_body_params( $params );
    1998         $response = $this->server->dispatch( $request );
     1998        $response = rest_get_server()->dispatch( $request );
    19991999        $data     = $response->get_data();
    20002000        $new_post = get_post( $data['id'] );
     
    20092009        );
    20102010        $request->set_body_params( $params );
    2011         $response = $this->server->dispatch( $request );
     2011        $response = rest_get_server()->dispatch( $request );
    20122012        $data     = $response->get_data();
    20132013        $this->assertEquals( 0, $data['featured_media'] );
     
    20252025        );
    20262026        $request->set_body_params( $params );
    2027         $response = $this->server->dispatch( $request );
     2027        $response = rest_get_server()->dispatch( $request );
    20282028
    20292029        $this->assertErrorResponse( 'rest_invalid_author', $response, 400 );
     
    20402040        );
    20412041        $request->set_body_params( $params );
    2042         $response = $this->server->dispatch( $request );
     2042        $response = rest_get_server()->dispatch( $request );
    20432043
    20442044        $this->assertErrorResponse( 'rest_cannot_edit_others', $response, 403 );
     
    20552055        );
    20562056        $request->set_body_params( $params );
    2057         $response = $this->server->dispatch( $request );
     2057        $response = rest_get_server()->dispatch( $request );
    20582058
    20592059        $data = $response->get_data();
     
    20712071        );
    20722072        $request->set_body_params( $params );
    2073         $response = $this->server->dispatch( $request );
     2073        $response = rest_get_server()->dispatch( $request );
    20742074
    20752075        $data = $response->get_data();
     
    20892089        );
    20902090        $request->set_body_params( $params );
    2091         $response = $this->server->dispatch( $request );
     2091        $response = rest_get_server()->dispatch( $request );
    20922092
    20932093        $this->assertEquals( 201, $response->get_status() );
     
    21072107        );
    21082108        $request->set_body_params( $params );
    2109         $response = $this->server->dispatch( $request );
     2109        $response = rest_get_server()->dispatch( $request );
    21102110
    21112111        $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    21222122        );
    21232123        $request->set_body_params( $params );
    2124         $response = $this->server->dispatch( $request );
     2124        $response = rest_get_server()->dispatch( $request );
    21252125
    21262126        $data     = $response->get_data();
     
    21412141        );
    21422142        $request->set_body_params( $params );
    2143         $response = $this->server->dispatch( $request );
     2143        $response = rest_get_server()->dispatch( $request );
    21442144
    21452145        $data     = $response->get_data();
     
    21692169        add_filter( 'query', array( $this, 'error_insert_query' ) );
    21702170
    2171         $response = $this->server->dispatch( $request );
     2171        $response = rest_get_server()->dispatch( $request );
    21722172        remove_filter( 'query', array( $this, 'error_insert_query' ) );
    21732173        $wpdb->show_errors = true;
     
    21862186        );
    21872187        $request->set_body_params( $params );
    2188         $response = $this->server->dispatch( $request );
     2188        $response = rest_get_server()->dispatch( $request );
    21892189
    21902190        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    22012201        );
    22022202        $request->set_body_params( $params );
    2203         $response = $this->server->dispatch( $request );
     2203        $response = rest_get_server()->dispatch( $request );
    22042204
    22052205        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    22162216        );
    22172217        $request->set_body_params( $params );
    2218         $response = $this->server->dispatch( $request );
     2218        $response = rest_get_server()->dispatch( $request );
    22192219        $new_data = $response->get_data();
    22202220        $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] );
     
    22342234        );
    22352235        $request->set_body_params( $params );
    2236         $response = $this->server->dispatch( $request );
     2236        $response = rest_get_server()->dispatch( $request );
    22372237
    22382238        $data = $response->get_data();
     
    22512251        );
    22522252        $request->set_body_params( $params );
    2253         $response = $this->server->dispatch( $request );
     2253        $response = rest_get_server()->dispatch( $request );
    22542254
    22552255        $data = $response->get_data();
     
    22692269        );
    22702270        $request->set_body_params( $params );
    2271         $response = $this->server->dispatch( $request );
     2271        $response = rest_get_server()->dispatch( $request );
    22722272
    22732273        $data = $response->get_data();
     
    22932293
    22942294        add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    2295         $response = $this->server->dispatch( $request );
     2295        $response = rest_get_server()->dispatch( $request );
    22962296        remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    22972297
     
    23132313        $params = $this->set_post_data();
    23142314        $request->set_body_params( $params );
    2315         $response = $this->server->dispatch( $request );
     2315        $response = rest_get_server()->dispatch( $request );
    23162316
    23172317        $this->check_update_post_response( $response );
     
    23362336        // Run twice to make sure that the update still succeeds even if no DB
    23372337        // rows are updated.
    2338         $response = $this->server->dispatch( $request );
     2338        $response = rest_get_server()->dispatch( $request );
    23392339        $this->check_update_post_response( $response );
    23402340
    2341         $response = $this->server->dispatch( $request );
     2341        $response = rest_get_server()->dispatch( $request );
    23422342        $this->check_update_post_response( $response );
    23432343    }
     
    23502350        $params = $this->set_post_data();
    23512351        $request->set_body( wp_json_encode( $params ) );
    2352         $response = $this->server->dispatch( $request );
     2352        $response = rest_get_server()->dispatch( $request );
    23532353
    23542354        $this->check_update_post_response( $response );
     
    23712371        $params = $this->set_raw_post_data();
    23722372        $request->set_body( wp_json_encode( $params ) );
    2373         $response = $this->server->dispatch( $request );
     2373        $response = rest_get_server()->dispatch( $request );
    23742374
    23752375        $this->check_update_post_response( $response );
     
    23952395        unset( $params['status'] );
    23962396        $request->set_body_params( $params );
    2397         $response = $this->server->dispatch( $request );
     2397        $response = rest_get_server()->dispatch( $request );
    23982398
    23992399        $this->check_update_post_response( $response );
     
    24112411        $params  = $this->set_post_data();
    24122412        $request->set_body_params( $params );
    2413         $response = $this->server->dispatch( $request );
     2413        $response = rest_get_server()->dispatch( $request );
    24142414
    24152415        $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
     
    24272427        );
    24282428        $request->set_body_params( $params );
    2429         $response = $this->server->dispatch( $request );
     2429        $response = rest_get_server()->dispatch( $request );
    24302430
    24312431        $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
     
    24362436
    24372437        $request  = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
    2438         $response = $this->server->dispatch( $request );
     2438        $response = rest_get_server()->dispatch( $request );
    24392439
    24402440        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    24452445
    24462446        $request  = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) );
    2447         $response = $this->server->dispatch( $request );
     2447        $response = rest_get_server()->dispatch( $request );
    24482448
    24492449        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    24602460        );
    24612461        $request->set_body_params( $params );
    2462         $response = $this->server->dispatch( $request );
     2462        $response = rest_get_server()->dispatch( $request );
    24632463
    24642464        $data     = $response->get_data();
     
    24782478        );
    24792479        $request->set_body_params( $params );
    2480         $response = $this->server->dispatch( $request );
     2480        $response = rest_get_server()->dispatch( $request );
    24812481
    24822482        $data     = $response->get_data();
     
    24962496        );
    24972497        $request->set_body_params( $params );
    2498         $response = $this->server->dispatch( $request );
     2498        $response = rest_get_server()->dispatch( $request );
    24992499
    25002500        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    25162516        );
    25172517        $request->set_body_params( $params );
    2518         $response = $this->server->dispatch( $request );
     2518        $response = rest_get_server()->dispatch( $request );
    25192519        $this->assertEquals( 200, $response->get_status() );
    25202520
     
    25372537        );
    25382538        $request->set_body_params( $params );
    2539         $response = $this->server->dispatch( $request );
     2539        $response = rest_get_server()->dispatch( $request );
    25402540
    25412541        // The readonly modified param should be ignored, request should be a success.
     
    25672567            $request->set_param( 'date_gmt', $params['date_gmt'] );
    25682568        }
    2569         $response = $this->server->dispatch( $request );
     2569        $response = rest_get_server()->dispatch( $request );
    25702570
    25712571        update_option( 'timezone_string', '' );
     
    25942594        );
    25952595        $request->set_body_params( $params );
    2596         $response = $this->server->dispatch( $request );
     2596        $response = rest_get_server()->dispatch( $request );
    25972597
    25982598        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    26092609        );
    26102610        $request->set_body_params( $params );
    2611         $response = $this->server->dispatch( $request );
     2611        $response = rest_get_server()->dispatch( $request );
    26122612
    26132613        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    26422642
    26432643        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    2644         $response = $this->server->dispatch( $request );
     2644        $response = rest_get_server()->dispatch( $request );
    26452645        $this->assertEquals( 200, $response->get_status() );
    26462646        $data = $response->get_data();
     
    26512651        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) );
    26522652        $request->set_param( 'date', '2016-02-23T13:00:00' );
    2653         $response = $this->server->dispatch( $request );
     2653        $response = rest_get_server()->dispatch( $request );
    26542654        $this->assertEquals( 200, $response->get_status() );
    26552655        $data = $response->get_data();
     
    26752675        );
    26762676        $request->set_body_params( $params );
    2677         $response = $this->server->dispatch( $request );
     2677        $response = rest_get_server()->dispatch( $request );
    26782678
    26792679        $new_data = $response->get_data();
     
    26932693        );
    26942694        $request->set_body_params( $params );
    2695         $response = $this->server->dispatch( $request );
     2695        $response = rest_get_server()->dispatch( $request );
    26962696
    26972697        $new_data = $response->get_data();
     
    27112711        );
    27122712        $request->set_body_params( $params );
    2713         $response = $this->server->dispatch( $request );
     2713        $response = rest_get_server()->dispatch( $request );
    27142714
    27152715        $new_data = $response->get_data();
     
    27262726        );
    27272727        $request->set_body_params( $params );
    2728         $response = $this->server->dispatch( $request );
     2728        $response = rest_get_server()->dispatch( $request );
    27292729
    27302730        $new_data = $response->get_data();
     
    27442744        );
    27452745
    2746         $response = $this->server->dispatch( $request );
     2746        $response = rest_get_server()->dispatch( $request );
    27472747        $new_data = $response->get_data();
    27482748        $this->assertEquals( 'An Excerpt', $new_data['excerpt']['raw'] );
     
    27592759        );
    27602760
    2761         $response = $this->server->dispatch( $request );
     2761        $response = rest_get_server()->dispatch( $request );
    27622762        $new_data = $response->get_data();
    27632763        $this->assertEquals( '', $new_data['excerpt']['raw'] );
     
    27742774        );
    27752775
    2776         $response = $this->server->dispatch( $request );
     2776        $response = rest_get_server()->dispatch( $request );
    27772777        $new_data = $response->get_data();
    27782778        $this->assertEquals( 'Some Content', $new_data['content']['raw'] );
     
    27892789        );
    27902790
    2791         $response = $this->server->dispatch( $request );
     2791        $response = rest_get_server()->dispatch( $request );
    27922792        $new_data = $response->get_data();
    27932793        $this->assertEquals( '', $new_data['content']['raw'] );
     
    28102810        );
    28112811        $request->set_body_params( $params );
    2812         $response = $this->server->dispatch( $request );
     2812        $response = rest_get_server()->dispatch( $request );
    28132813        $data     = $response->get_data();
    28142814        $this->assertEquals( '', $data['password'] );
     
    28262826        );
    28272827        $request->set_body_params( $params );
    2828         $response = $this->server->dispatch( $request );
     2828        $response = rest_get_server()->dispatch( $request );
    28292829
    28302830        $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    28432843        );
    28442844        $request->set_body_params( $params );
    2845         $response = $this->server->dispatch( $request );
     2845        $response = rest_get_server()->dispatch( $request );
    28462846
    28472847        $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    28652865        );
    28662866        $request->set_body_params( $params );
    2867         $response = $this->server->dispatch( $request );
     2867        $response = rest_get_server()->dispatch( $request );
    28682868
    28692869        $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    28802880        );
    28812881        $request->set_body_params( $params );
    2882         $response = $this->server->dispatch( $request );
     2882        $response = rest_get_server()->dispatch( $request );
    28832883        $new_data = $response->get_data();
    28842884        $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] );
     
    29002900        );
    29012901        $request->set_body_params( $params );
    2902         $response = $this->server->dispatch( $request );
     2902        $response = rest_get_server()->dispatch( $request );
    29032903        $new_data = $response->get_data();
    29042904        $this->assertEquals( array( $category['term_id'] ), $new_data['categories'] );
     
    29152915        unset( $args['rest_route'] );
    29162916        $request->set_query_params( $args );
    2917         $response = $this->server->dispatch( $request );
     2917        $response = rest_get_server()->dispatch( $request );
    29182918        $data     = $response->get_data();
    29192919        $this->assertCount( 1, $data );
     
    29352935        );
    29362936        $request->set_body_params( $params );
    2937         $response = $this->server->dispatch( $request );
     2937        $response = rest_get_server()->dispatch( $request );
    29382938        $new_data = $response->get_data();
    29392939        $this->assertEquals( array(), $new_data['categories'] );
     
    29582958
    29592959        add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    2960         $response = $this->server->dispatch( $request );
     2960        $response = rest_get_server()->dispatch( $request );
    29612961        remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    29622962
     
    29842984        );
    29852985        $request->set_body_params( $params );
    2986         $response = $this->server->dispatch( $request );
     2986        $response = rest_get_server()->dispatch( $request );
    29872987
    29882988        $data          = $response->get_data();
     
    30143014        );
    30153015        $request->set_body_params( $params );
    3016         $response = $this->server->dispatch( $request );
     3016        $response = rest_get_server()->dispatch( $request );
    30173017
    30183018        $data          = $response->get_data();
     
    30423042        );
    30433043        $request->set_body_params( $params );
    3044         $response = $this->server->dispatch( $request );
     3044        $response = rest_get_server()->dispatch( $request );
    30453045
    30463046        $this->assertEquals( 200, $response->get_status() );
     
    30593059            $request->set_param( $name, $value );
    30603060        }
    3061         $response = $this->server->dispatch( $request );
     3061        $response = rest_get_server()->dispatch( $request );
    30623062        $this->assertEquals( 201, $response->get_status() );
    30633063        $actual_output = $response->get_data();
     
    30823082            $request->set_param( $name, $value );
    30833083        }
    3084         $response = $this->server->dispatch( $request );
     3084        $response = rest_get_server()->dispatch( $request );
    30853085        $this->assertEquals( 200, $response->get_status() );
    30863086        $actual_output = $response->get_data();
     
    32873287        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    32883288        $request->set_param( 'force', 'false' );
    3289         $response = $this->server->dispatch( $request );
     3289        $response = rest_get_server()->dispatch( $request );
    32903290
    32913291        $this->assertEquals( 200, $response->get_status() );
     
    33013301        $request          = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    33023302        $request['force'] = true;
    3303         $response         = $this->server->dispatch( $request );
     3303        $response         = rest_get_server()->dispatch( $request );
    33043304
    33053305        $this->assertEquals( 200, $response->get_status() );
     
    33133313        wp_set_current_user( self::$editor_id );
    33143314        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    3315         $response = $this->server->dispatch( $request );
     3315        $response = rest_get_server()->dispatch( $request );
    33163316        $this->assertEquals( 200, $response->get_status() );
    3317         $response = $this->server->dispatch( $request );
     3317        $response = rest_get_server()->dispatch( $request );
    33183318        $this->assertErrorResponse( 'rest_already_trashed', $response, 410 );
    33193319    }
     
    33233323
    33243324        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    3325         $response = $this->server->dispatch( $request );
     3325        $response = rest_get_server()->dispatch( $request );
    33263326
    33273327        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    33333333
    33343334        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id );
    3335         $response = $this->server->dispatch( $request );
     3335        $response = rest_get_server()->dispatch( $request );
    33363336
    33373337        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    33423342
    33433343        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    3344         $response = $this->server->dispatch( $request );
     3344        $response = rest_get_server()->dispatch( $request );
    33453345
    33463346        $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
     
    33563356        );
    33573357        create_initial_rest_routes();
    3358         $routes = $this->server->get_routes();
     3358        $routes = rest_get_server()->get_routes();
    33593359        $this->assertFalse( isset( $routes['/wp/v2/invalid-controller'] ) );
    33603360        _unregister_post_type( 'invalid-controller' );
     
    33643364    public function test_get_item_schema() {
    33653365        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    3366         $response   = $this->server->dispatch( $request );
     3366        $response   = rest_get_server()->dispatch( $request );
    33673367        $data       = $response->get_data();
    33683368        $properties = $data['schema']['properties'];
     
    34003400        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    34013401        $request->set_param( 'context', 'view' );
    3402         $response = $this->server->dispatch( $request );
     3402        $response = rest_get_server()->dispatch( $request );
    34033403        $keys     = array_keys( $response->get_data() );
    34043404        sort( $keys );
     
    34383438        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    34393439        $request->set_param( 'context', 'edit' );
    3440         $response = $this->server->dispatch( $request );
     3440        $response = rest_get_server()->dispatch( $request );
    34413441        $keys     = array_keys( $response->get_data() );
    34423442        sort( $keys );
     
    34753475        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    34763476        $request->set_param( 'context', 'embed' );
    3477         $response = $this->server->dispatch( $request );
     3477        $response = rest_get_server()->dispatch( $request );
    34783478        $keys     = array_keys( $response->get_data() );
    34793479        sort( $keys );
     
    34963496    public function test_status_array_enum_args() {
    34973497        $request         = new WP_REST_Request( 'GET', '/wp/v2' );
    3498         $response        = $this->server->dispatch( $request );
     3498        $response        = rest_get_server()->dispatch( $request );
    34993499        $data            = $response->get_data();
    35003500        $list_posts_args = $data['routes']['/wp/v2/posts']['endpoints'][0]['args'];
     
    35283528        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    35293529
    3530         $response = $this->server->dispatch( $request );
     3530        $response = rest_get_server()->dispatch( $request );
    35313531        $data     = $response->get_data();
    35323532
     
    35403540        $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
    35413541
    3542         $response = $this->server->dispatch( $request );
     3542        $response = rest_get_server()->dispatch( $request );
    35433543        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    35443544
     
    35503550        );
    35513551
    3552         $response = $this->server->dispatch( $request );
     3552        $response = rest_get_server()->dispatch( $request );
    35533553        $this->assertEquals( 123, get_post_meta( $post_id, 'my_custom_int', true ) );
    35543554
     
    35613561        );
    35623562
    3563         $response = $this->server->dispatch( $request );
     3563        $response = rest_get_server()->dispatch( $request );
    35643564
    35653565        $this->assertEquals( 123, $response->data['my_custom_int'] );
     
    35943594        );
    35953595
    3596         $response = $this->server->dispatch( $request );
     3596        $response = rest_get_server()->dispatch( $request );
    35973597
    35983598        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
Note: See TracChangeset for help on using the changeset viewer.