Make WordPress Core

Changeset 42724


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

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

Props danielbachhuber.
Fixes #41641.

Location:
trunk/tests/phpunit
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/bootstrap.php

    r42343 r42724  
    8686// Allow tests to override wp_die
    8787tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter' );
     88// Use the Spy REST Server instead of default
     89tests_add_filter( 'wp_rest_server_class', '_wp_rest_server_class_filter' );
    8890
    8991// Preset WordPress options defined in bootstrap file.
  • trunk/tests/phpunit/includes/functions.php

    r42381 r42724  
    181181}
    182182
     183/**
     184 * Use the Spy_REST_Server class for the REST server.
     185 */
     186function _wp_rest_server_class_filter() {
     187    return 'Spy_REST_Server';
     188}
     189
    183190// Skip `setcookie` calls in auth_cookie functions due to warning:
    184191// Cannot modify header information - headers already sent by ...
  • trunk/tests/phpunit/includes/testcase-rest-controller.php

    r39177 r42724  
    1010        /** @var WP_REST_Server $wp_rest_server */
    1111        global $wp_rest_server;
    12         $this->server = $wp_rest_server = new Spy_REST_Server;
    13         do_action( 'rest_api_init' );
     12        $wp_rest_server = new Spy_REST_Server;
     13        do_action( 'rest_api_init', $wp_rest_server );
    1414    }
    1515
  • trunk/tests/phpunit/tests/oembed/controller.php

    r42343 r42724  
    4646        /** @var WP_REST_Server $wp_rest_server */
    4747        global $wp_rest_server;
    48         $this->server = $wp_rest_server = new Spy_REST_Server();
    49 
    50         do_action( 'rest_api_init', $this->server );
     48        $wp_rest_server = new Spy_REST_Server;
     49        do_action( 'rest_api_init', $wp_rest_server );
     50
    5151        add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
    5252        $this->request_count = 0;
     
    5555    public function tearDown() {
    5656        parent::tearDown();
     57        /** @var WP_REST_Server $wp_rest_server */
     58        global $wp_rest_server;
     59        $wp_rest_server = null;
    5760
    5861        remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 );
     
    180183    public function test_route_availability() {
    181184        // Check the route was registered correctly.
    182         $filtered_routes = $this->server->get_routes();
     185        $filtered_routes = rest_get_server()->get_routes();
    183186        $this->assertArrayHasKey( '/oembed/1.0/embed', $filtered_routes );
    184187        $route = $filtered_routes['/oembed/1.0/embed'];
     
    201204        $request = new WP_REST_Request( 'POST', '/oembed/1.0/embed' );
    202205
    203         $response = $this->server->dispatch( $request );
     206        $response = rest_get_server()->dispatch( $request );
    204207        $data     = $response->get_data();
    205208
     
    210213        $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' );
    211214
    212         $response = $this->server->dispatch( $request );
     215        $response = rest_get_server()->dispatch( $request );
    213216        $data     = $response->get_data();
    214217
     
    221224        $request->set_param( 'url', 'http://google.com/' );
    222225
    223         $response = $this->server->dispatch( $request );
     226        $response = rest_get_server()->dispatch( $request );
    224227        $data     = $response->get_data();
    225228
     
    234237        $request->set_param( 'format', 'random' );
    235238
    236         $response = $this->server->dispatch( $request );
     239        $response = rest_get_server()->dispatch( $request );
    237240        $data     = $response->get_data();
    238241
     
    258261        $request->set_param( 'maxwidth', 400 );
    259262
    260         $response = $this->server->dispatch( $request );
     263        $response = rest_get_server()->dispatch( $request );
    261264        $data     = $response->get_data();
    262265
     
    301304        $request->set_param( 'maxwidth', 400 );
    302305
    303         $response = $this->server->dispatch( $request );
     306        $response = rest_get_server()->dispatch( $request );
    304307        $data     = $response->get_data();
    305308
     
    346349        $request->set_param( 'maxwidth', 400 );
    347350
    348         $response = $this->server->dispatch( $request );
     351        $response = rest_get_server()->dispatch( $request );
    349352        $data     = $response->get_data();
    350353
     
    389392        $request->set_param( 'maxwidth', 400 );
    390393
    391         $response = $this->server->dispatch( $request );
     394        $response = rest_get_server()->dispatch( $request );
    392395        $data     = $response->get_data();
    393396
     
    415418        $request->set_param( 'format', 'xml' );
    416419
    417         $response = $this->server->dispatch( $request );
    418         $output   = get_echo( '_oembed_rest_pre_serve_request', array( true, $response, $request, $this->server ) );
     420        $response = rest_get_server()->dispatch( $request );
     421        $output   = get_echo( '_oembed_rest_pre_serve_request', array( true, $response, $request, rest_get_server() ) );
    419422
    420423        $xml = simplexml_load_string( $output );
     
    429432        $request->set_param( 'format', 'json' );
    430433
    431         $response = $this->server->dispatch( $request );
    432 
    433         $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, $this->server ) );
     434        $response = rest_get_server()->dispatch( $request );
     435
     436        $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) );
    434437    }
    435438
     
    441444        $request->set_param( 'format', 'xml' );
    442445
    443         $response = $this->server->dispatch( $request );
    444 
    445         $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, $this->server ) );
     446        $response = rest_get_server()->dispatch( $request );
     447
     448        $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) );
    446449    }
    447450
     
    478481        // Test without a login.
    479482        $request  = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    480         $response = $this->server->dispatch( $request );
     483        $response = rest_get_server()->dispatch( $request );
    481484
    482485        $this->assertEquals( 400, $response->get_status() );
     
    486489        $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    487490        $request->set_param( 'url', self::INVALID_OEMBED_URL );
    488         $response = $this->server->dispatch( $request );
     491        $response = rest_get_server()->dispatch( $request );
    489492
    490493        $this->assertEquals( 403, $response->get_status() );
     
    497500        $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    498501        $request->set_param( 'url', self::INVALID_OEMBED_URL );
    499         $response = $this->server->dispatch( $request );
     502        $response = rest_get_server()->dispatch( $request );
    500503        $this->assertEquals( 404, $response->get_status() );
    501504        $data = $response->get_data();
     
    507510        $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    508511        $request->set_param( 'type', 'xml' );
    509         $response = $this->server->dispatch( $request );
     512        $response = rest_get_server()->dispatch( $request );
    510513
    511514        $this->assertEquals( 400, $response->get_status() );
     
    519522        $request->set_param( 'maxheight', 789 );
    520523        $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) );
    521         $response = $this->server->dispatch( $request );
     524        $response = rest_get_server()->dispatch( $request );
    522525        $this->assertEquals( 200, $response->get_status() );
    523526        $this->assertEquals( 1, $this->request_count );
    524527
    525528        // Subsequent request is cached and so it should not cause a request.
    526         $this->server->dispatch( $request );
     529        rest_get_server()->dispatch( $request );
    527530        $this->assertEquals( 1, $this->request_count );
    528531
     
    534537        $request->set_param( 'maxwidth', 456 );
    535538        $request->set_param( 'maxheight', 789 );
    536         $response = $this->server->dispatch( $request );
     539        $response = rest_get_server()->dispatch( $request );
    537540        $this->assertEquals( 1, $this->request_count );
    538541
     
    555558        $request->set_param( 'url', self::INVALID_OEMBED_URL );
    556559        $request->set_param( 'discover', 0 );
    557         $response = $this->server->dispatch( $request );
     560        $response = rest_get_server()->dispatch( $request );
    558561        $this->assertEquals( 404, $response->get_status() );
    559562        $this->assertEquals( 0, $this->request_count );
     
    566569        $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    567570        $request->set_param( 'url', self::INVALID_OEMBED_URL );
    568         $response = $this->server->dispatch( $request );
     571        $response = rest_get_server()->dispatch( $request );
    569572        $this->assertEquals( 404, $response->get_status() );
    570573        $this->assertEquals( 1, $this->request_count );
     
    577580        $request->set_param( 'discover', 'notaboolean' );
    578581
    579         $response = $this->server->dispatch( $request );
     582        $response = rest_get_server()->dispatch( $request );
    580583
    581584        $this->assertEquals( 400, $response->get_status() );
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r42423 r42724  
    7777
    7878    public function test_register_routes() {
    79         $routes = $this->server->get_routes();
     79        $routes = rest_get_server()->get_routes();
    8080        $this->assertArrayHasKey( '/wp/v2/media', $routes );
    8181        $this->assertCount( 2, $routes['/wp/v2/media'] );
     
    128128        // Collection
    129129        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' );
    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'] );
     
    140140        );
    141141        $request       = new WP_REST_Request( 'OPTIONS', '/wp/v2/media/' . $attachment_id );
    142         $response      = $this->server->dispatch( $request );
     142        $response      = rest_get_server()->dispatch( $request );
    143143        $data          = $response->get_data();
    144144        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    148148    public function test_registered_query_params() {
    149149        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' );
    150         $response = $this->server->dispatch( $request );
     150        $response = rest_get_server()->dispatch( $request );
    151151        $data     = $response->get_data();
    152152        $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    195195        );
    196196        $request  = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/media/%d', $id1 ) );
    197         $response = $this->server->dispatch( $request );
     197        $response = rest_get_server()->dispatch( $request );
    198198        $data     = $response->get_data();
    199199        $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    225225        );
    226226        $request        = new WP_REST_Request( 'GET', '/wp/v2/media' );
    227         $response       = $this->server->dispatch( $request );
     227        $response       = rest_get_server()->dispatch( $request );
    228228        $data           = $response->get_data();
    229229        $this->assertCount( 2, $data );
     
    259259        );
    260260        $request        = new WP_REST_Request( 'GET', '/wp/v2/media' );
    261         $response       = $this->server->dispatch( $request );
     261        $response       = rest_get_server()->dispatch( $request );
    262262
    263263        $data = $response->get_data();
     
    276276        );
    277277        $request  = new WP_REST_Request( 'GET', '/wp/v2/media' );
    278         $response = $this->server->dispatch( $request );
     278        $response = rest_get_server()->dispatch( $request );
    279279        $data     = $response->get_data();
    280280        $this->assertEquals( $id1, $data[0]['id'] );
    281281        // media_type=video
    282282        $request->set_param( 'media_type', 'video' );
    283         $response = $this->server->dispatch( $request );
     283        $response = rest_get_server()->dispatch( $request );
    284284        $this->assertCount( 0, $response->get_data() );
    285285        // media_type=image
    286286        $request->set_param( 'media_type', 'image' );
    287         $response = $this->server->dispatch( $request );
     287        $response = rest_get_server()->dispatch( $request );
    288288        $data     = $response->get_data();
    289289        $this->assertEquals( $id1, $data[0]['id'] );
     
    297297        );
    298298        $request  = new WP_REST_Request( 'GET', '/wp/v2/media' );
    299         $response = $this->server->dispatch( $request );
     299        $response = rest_get_server()->dispatch( $request );
    300300        $data     = $response->get_data();
    301301        $this->assertEquals( $id1, $data[0]['id'] );
    302302        // mime_type=image/png
    303303        $request->set_param( 'mime_type', 'image/png' );
    304         $response = $this->server->dispatch( $request );
     304        $response = rest_get_server()->dispatch( $request );
    305305        $this->assertCount( 0, $response->get_data() );
    306306        // mime_type=image/jpeg
    307307        $request->set_param( 'mime_type', 'image/jpeg' );
    308         $response = $this->server->dispatch( $request );
     308        $response = rest_get_server()->dispatch( $request );
    309309        $data     = $response->get_data();
    310310        $this->assertEquals( $id1, $data[0]['id'] );
     
    327327        // all attachments
    328328        $request  = new WP_REST_Request( 'GET', '/wp/v2/media' );
    329         $response = $this->server->dispatch( $request );
     329        $response = rest_get_server()->dispatch( $request );
    330330        $this->assertEquals( 2, count( $response->get_data() ) );
    331331        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    332332        // attachments without a parent
    333333        $request->set_param( 'parent', 0 );
    334         $response = $this->server->dispatch( $request );
     334        $response = rest_get_server()->dispatch( $request );
    335335        $data     = $response->get_data();
    336336        $this->assertEquals( 1, count( $data ) );
     
    339339        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    340340        $request->set_param( 'parent', $post_id );
    341         $response = $this->server->dispatch( $request );
     341        $response = rest_get_server()->dispatch( $request );
    342342        $data     = $response->get_data();
    343343        $this->assertEquals( 1, count( $data ) );
     
    346346        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    347347        $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    348         $response = $this->server->dispatch( $request );
     348        $response = rest_get_server()->dispatch( $request );
    349349        $data     = $response->get_data();
    350350        $this->assertEquals( 0, count( $data ) );
     
    362362        $request->set_param( 'status', 'publish' );
    363363        $request->set_param( 'context', 'edit' );
    364         $response = $this->server->dispatch( $request );
     364        $response = rest_get_server()->dispatch( $request );
    365365        $data     = $response->get_data();
    366366        $this->assertCount( 3, $data );
     
    380380        $request        = new WP_REST_Request( 'GET', '/wp/v2/media' );
    381381        $request->set_param( 'status', 'private' );
    382         $response = $this->server->dispatch( $request );
     382        $response = rest_get_server()->dispatch( $request );
    383383        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    384384        // Properly authorized users can make the request
    385385        wp_set_current_user( self::$editor_id );
    386         $response = $this->server->dispatch( $request );
     386        $response = rest_get_server()->dispatch( $request );
    387387        $this->assertEquals( 200, $response->get_status() );
    388388        $data = $response->get_data();
     
    409409        $request        = new WP_REST_Request( 'GET', '/wp/v2/media' );
    410410        $request->set_param( 'status', array( 'private', 'trash' ) );
    411         $response = $this->server->dispatch( $request );
     411        $response = rest_get_server()->dispatch( $request );
    412412        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    413413        // Properly authorized users can make the request
    414414        wp_set_current_user( self::$editor_id );
    415         $response = $this->server->dispatch( $request );
     415        $response = rest_get_server()->dispatch( $request );
    416416        $this->assertEquals( 200, $response->get_status() );
    417417        $data = $response->get_data();
     
    429429        $request->set_param( 'after', rand_str() );
    430430        $request->set_param( 'before', rand_str() );
    431         $response = $this->server->dispatch( $request );
     431        $response = rest_get_server()->dispatch( $request );
    432432        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    433433    }
     
    458458        $request->set_param( 'after', '2016-01-15T00:00:00Z' );
    459459        $request->set_param( 'before', '2016-01-17T00:00:00Z' );
    460         $response = $this->server->dispatch( $request );
     460        $response = rest_get_server()->dispatch( $request );
    461461        $data     = $response->get_data();
    462462        $this->assertCount( 1, $data );
     
    473473        update_post_meta( $attachment_id, '_wp_attachment_image_alt', 'Sample alt text' );
    474474        $request  = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id );
    475         $response = $this->server->dispatch( $request );
     475        $response = rest_get_server()->dispatch( $request );
    476476        $this->check_get_post_response( $response );
    477477        $data = $response->get_data();
     
    491491
    492492        $request            = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id );
    493         $response           = $this->server->dispatch( $request );
     493        $response           = rest_get_server()->dispatch( $request );
    494494        $data               = $response->get_data();
    495495        $image_src          = wp_get_attachment_image_src( $attachment_id, 'rest-api-test' );
     
    517517
    518518        $request  = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id );
    519         $response = $this->server->dispatch( $request );
     519        $response = rest_get_server()->dispatch( $request );
    520520        $data     = $response->get_data();
    521521        remove_filter( 'wp_get_attachment_image_src', '__return_false' );
     
    535535        );
    536536        $request    = new WP_REST_Request( 'GET', '/wp/v2/media/' . $id1 );
    537         $response   = $this->server->dispatch( $request );
     537        $response   = rest_get_server()->dispatch( $request );
    538538        $this->assertEquals( 401, $response->get_status() );
    539539    }
     
    547547        );
    548548        $request       = new WP_REST_Request( 'GET', sprintf( '/wp/v2/media/%d', $attachment_id ) );
    549         $response      = $this->server->dispatch( $request );
     549        $response      = rest_get_server()->dispatch( $request );
    550550        $data          = $response->get_data();
    551551
     
    563563        );
    564564        $request       = new WP_REST_Request( 'GET', sprintf( '/wp/v2/media/%d', $attachment_id ) );
    565         $response      = $this->server->dispatch( $request );
     565        $response      = rest_get_server()->dispatch( $request );
    566566
    567567        $this->assertErrorResponse( 'rest_forbidden', $response, 401 );
     
    580580
    581581        $request->set_body( file_get_contents( $this->test_file ) );
    582         $response = $this->server->dispatch( $request );
     582        $response = rest_get_server()->dispatch( $request );
    583583        $data     = $response->get_data();
    584584
     
    611611        );
    612612        $request->set_header( 'Content-MD5', md5_file( $this->test_file2 ) );
    613         $response = $this->server->dispatch( $request );
     613        $response = rest_get_server()->dispatch( $request );
    614614        $this->assertEquals( 201, $response->get_status() );
    615615        $data = $response->get_data();
     
    631631        );
    632632        $request->set_header( 'Content-MD5', md5_file( $this->test_file ) );
    633         $response = $this->server->dispatch( $request );
     633        $response = rest_get_server()->dispatch( $request );
    634634        $this->assertEquals( 201, $response->get_status() );
    635635    }
     
    649649        );
    650650        $request->set_header( 'Content-MD5', md5_file( $this->test_file ) );
    651         $response = $this->server->dispatch( $request );
     651        $response = rest_get_server()->dispatch( $request );
    652652        $this->assertEquals( 201, $response->get_status() );
    653653    }
     
    656656        wp_set_current_user( self::$author_id );
    657657        $request  = new WP_REST_Request( 'POST', '/wp/v2/media' );
    658         $response = $this->server->dispatch( $request );
     658        $response = rest_get_server()->dispatch( $request );
    659659        $this->assertErrorResponse( 'rest_upload_no_data', $response, 400 );
    660660    }
     
    664664        $request = new WP_REST_Request( 'POST', '/wp/v2/media' );
    665665        $request->set_body( file_get_contents( $this->test_file ) );
    666         $response = $this->server->dispatch( $request );
     666        $response = rest_get_server()->dispatch( $request );
    667667        $this->assertErrorResponse( 'rest_upload_no_content_type', $response, 400 );
    668668    }
     
    673673        $request->set_header( 'Content-Type', 'image/jpeg' );
    674674        $request->set_body( file_get_contents( $this->test_file ) );
    675         $response = $this->server->dispatch( $request );
     675        $response = rest_get_server()->dispatch( $request );
    676676        $this->assertErrorResponse( 'rest_upload_no_content_disposition', $response, 400 );
    677677    }
     
    684684        $request->set_header( 'Content-MD5', 'abc123' );
    685685        $request->set_body( file_get_contents( $this->test_file ) );
    686         $response = $this->server->dispatch( $request );
     686        $response = rest_get_server()->dispatch( $request );
    687687        $this->assertErrorResponse( 'rest_upload_hash_mismatch', $response, 412 );
    688688    }
     
    702702        );
    703703        $request->set_header( 'Content-MD5', 'abc123' );
    704         $response = $this->server->dispatch( $request );
     704        $response = rest_get_server()->dispatch( $request );
    705705        $this->assertErrorResponse( 'rest_upload_hash_mismatch', $response, 412 );
    706706    }
     
    709709        wp_set_current_user( self::$contributor_id );
    710710        $request  = new WP_REST_Request( 'POST', '/wp/v2/media' );
    711         $response = $this->server->dispatch( $request );
     711        $response = rest_get_server()->dispatch( $request );
    712712        $this->assertErrorResponse( 'rest_cannot_create', $response, 403 );
    713713    }
     
    718718        $request = new WP_REST_Request( 'POST', '/wp/v2/media' );
    719719        $request->set_param( 'post', $post_id );
    720         $response = $this->server->dispatch( $request );
     720        $response = rest_get_server()->dispatch( $request );
    721721        $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
    722722    }
     
    727727        $request = new WP_REST_Request( 'POST', '/wp/v2/media' );
    728728        $request->set_param( 'post', $post_id );
    729         $response = $this->server->dispatch( $request );
     729        $response = rest_get_server()->dispatch( $request );
    730730        $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
    731731    }
     
    745745        $request->set_body( file_get_contents( $this->test_file ) );
    746746        $request->set_param( 'post', $attachment_id );
    747         $response = $this->server->dispatch( $request );
     747        $response = rest_get_server()->dispatch( $request );
    748748        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    749749    }
     
    757757        $request->set_body( file_get_contents( $this->test_file ) );
    758758        $request->set_param( 'alt_text', 'test alt text' );
    759         $response   = $this->server->dispatch( $request );
     759        $response   = rest_get_server()->dispatch( $request );
    760760        $attachment = $response->get_data();
    761761        $this->assertEquals( 'test alt text', $attachment['alt_text'] );
     
    769769        $request->set_body( file_get_contents( $this->test_file ) );
    770770        $request->set_param( 'alt_text', '<script>alert(document.cookie)</script>' );
    771         $response   = $this->server->dispatch( $request );
     771        $response   = rest_get_server()->dispatch( $request );
    772772        $attachment = $response->get_data();
    773773        $this->assertEquals( '', $attachment['alt_text'] );
     
    788788        $request->set_param( 'description', 'Without a description, my attachment is descriptionless.' );
    789789        $request->set_param( 'alt_text', 'Alt text is stored outside post schema.' );
    790         $response   = $this->server->dispatch( $request );
     790        $response   = rest_get_server()->dispatch( $request );
    791791        $data       = $response->get_data();
    792792        $attachment = get_post( $data['id'] );
     
    818818        $request    = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id );
    819819        $request->set_param( 'post', $new_parent );
    820         $this->server->dispatch( $request );
     820        rest_get_server()->dispatch( $request );
    821821
    822822        $attachment = get_post( $attachment_id );
     
    835835        $request       = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id );
    836836        $request->set_param( 'caption', 'This is a better caption.' );
    837         $response = $this->server->dispatch( $request );
     837        $response = rest_get_server()->dispatch( $request );
    838838        $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
    839839    }
     
    857857        $request       = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id );
    858858        $request->set_param( 'post', $attachment_id );
    859         $response = $this->server->dispatch( $request );
     859        $response = rest_get_server()->dispatch( $request );
    860860        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    861861    }
     
    871871            $request->set_param( $name, $value );
    872872        }
    873         $response = $this->server->dispatch( $request );
     873        $response = rest_get_server()->dispatch( $request );
    874874        $this->assertEquals( 201, $response->get_status() );
    875875        $actual_output = $response->get_data();
     
    903903            $request->set_param( $name, $value );
    904904        }
    905         $response = $this->server->dispatch( $request );
     905        $response = rest_get_server()->dispatch( $request );
    906906        $this->assertEquals( 200, $response->get_status() );
    907907        $actual_output = $response->get_data();
     
    11211121        $request          = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id );
    11221122        $request['force'] = true;
    1123         $response         = $this->server->dispatch( $request );
     1123        $response         = rest_get_server()->dispatch( $request );
    11241124        $this->assertEquals( 200, $response->get_status() );
    11251125    }
     
    11361136        // Attempt trashing
    11371137        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id );
    1138         $response = $this->server->dispatch( $request );
     1138        $response = rest_get_server()->dispatch( $request );
    11391139        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    11401140
    11411141        $request->set_param( 'force', 'false' );
    1142         $response = $this->server->dispatch( $request );
     1142        $response = rest_get_server()->dispatch( $request );
    11431143        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    11441144
     
    11581158        );
    11591159        $request       = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id );
    1160         $response      = $this->server->dispatch( $request );
     1160        $response      = rest_get_server()->dispatch( $request );
    11611161        $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
    11621162    }
     
    11731173        $attachment = get_post( $attachment_id );
    11741174        $request    = new WP_REST_Request( 'GET', sprintf( '/wp/v2/media/%d', $attachment_id ) );
    1175         $response   = $this->server->dispatch( $request );
     1175        $response   = rest_get_server()->dispatch( $request );
    11761176        $data       = $response->get_data();
    11771177        $this->check_post_data( $attachment, $data, 'view', $response->get_links() );
     
    11811181    public function test_get_item_schema() {
    11821182        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' );
    1183         $response   = $this->server->dispatch( $request );
     1183        $response   = rest_get_server()->dispatch( $request );
    11841184        $data       = $response->get_data();
    11851185        $properties = $data['schema']['properties'];
     
    12351235        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' );
    12361236
    1237         $response = $this->server->dispatch( $request );
     1237        $response = rest_get_server()->dispatch( $request );
    12381238        $data     = $response->get_data();
    12391239        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
     
    12491249        $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id );
    12501250
    1251         $response = $this->server->dispatch( $request );
     1251        $response = rest_get_server()->dispatch( $request );
    12521252        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    12531253
     
    12881288        );
    12891289
    1290         $response = $this->server->dispatch( $request );
     1290        $response = rest_get_server()->dispatch( $request );
    12911291
    12921292        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    13121312        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    13131313        $request->set_param( 'search', $filename );
    1314         $response = $this->server->dispatch( $request );
     1314        $response = rest_get_server()->dispatch( $request );
    13151315        $data     = $response->get_data();
    13161316
  • trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php

    r42354 r42724  
    3434
    3535    public function test_register_routes() {
    36         $routes = $this->server->get_routes();
     36        $routes = rest_get_server()->get_routes();
    3737        $this->assertArrayHasKey( '/wp/v2/categories', $routes );
    3838        $this->assertArrayHasKey( '/wp/v2/categories/(?P<id>[\d]+)', $routes );
     
    4242        // Collection
    4343        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    44         $response = $this->server->dispatch( $request );
     44        $response = rest_get_server()->dispatch( $request );
    4545        $data     = $response->get_data();
    4646        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    4949        $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) );
    5050        $request   = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 );
    51         $response  = $this->server->dispatch( $request );
     51        $response  = rest_get_server()->dispatch( $request );
    5252        $data      = $response->get_data();
    5353        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    5757    public function test_registered_query_params() {
    5858        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    59         $response = $this->server->dispatch( $request );
     59        $response = rest_get_server()->dispatch( $request );
    6060        $data     = $response->get_data();
    6161        $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    8181    public function test_get_items() {
    8282        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    83         $response = $this->server->dispatch( $request );
     83        $response = rest_get_server()->dispatch( $request );
    8484        $this->check_get_taxonomy_terms_response( $response );
    8585    }
     
    8989        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    9090        $request->set_param( 'context', 'edit' );
    91         $response = $this->server->dispatch( $request );
     91        $response = rest_get_server()->dispatch( $request );
    9292        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    9393    }
     
    100100        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    101101        $request->set_param( 'hide_empty', true );
    102         $response = $this->server->dispatch( $request );
     102        $response = rest_get_server()->dispatch( $request );
    103103        $data     = $response->get_data();
    104104        $this->assertEquals( 2, count( $data ) );
     
    108108        // Confirm the empty category "Uncategorized" category appears.
    109109        $request->set_param( 'hide_empty', 'false' );
    110         $response = $this->server->dispatch( $request );
     110        $response = rest_get_server()->dispatch( $request );
    111111        $data     = $response->get_data();
    112112        $this->assertEquals( 3, count( $data ) );
     
    130130        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    131131        $request->set_param( 'parent', 0 );
    132         $response = $this->server->dispatch( $request );
     132        $response = rest_get_server()->dispatch( $request );
    133133
    134134        $this->assertEquals( 200, $response->get_status() );
     
    160160        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    161161        $request->set_param( 'parent', '0' );
    162         $response = $this->server->dispatch( $request );
     162        $response = rest_get_server()->dispatch( $request );
    163163
    164164        $this->assertEquals( 200, $response->get_status() );
     
    178178        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    179179        $request->set_param( 'parent', $parent1 );
    180         $response = $this->server->dispatch( $request );
     180        $response = rest_get_server()->dispatch( $request );
    181181
    182182        $this->assertEquals( 200, $response->get_status() );
     
    189189        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    190190        $request->set_param( 'page', 0 );
    191         $response = $this->server->dispatch( $request );
     191        $response = rest_get_server()->dispatch( $request );
    192192        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    193193        $data        = $response->get_data();
     
    203203        // Orderby=>asc
    204204        $request->set_param( 'include', array( $id3, $id1 ) );
    205         $response = $this->server->dispatch( $request );
     205        $response = rest_get_server()->dispatch( $request );
    206206        $data     = $response->get_data();
    207207        $this->assertEquals( 2, count( $data ) );
     
    209209        // Orderby=>include
    210210        $request->set_param( 'orderby', 'include' );
    211         $response = $this->server->dispatch( $request );
     211        $response = rest_get_server()->dispatch( $request );
    212212        $data     = $response->get_data();
    213213        $this->assertEquals( 2, count( $data ) );
     
    219219        $id2      = $this->factory->category->create();
    220220        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    221         $response = $this->server->dispatch( $request );
     221        $response = rest_get_server()->dispatch( $request );
    222222        $data     = $response->get_data();
    223223        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    224224        $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
    225225        $request->set_param( 'exclude', array( $id2 ) );
    226         $response = $this->server->dispatch( $request );
     226        $response = rest_get_server()->dispatch( $request );
    227227        $data     = $response->get_data();
    228228        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     
    243243        $request->set_param( 'order', 'desc' );
    244244        $request->set_param( 'per_page', 1 );
    245         $response = $this->server->dispatch( $request );
     245        $response = rest_get_server()->dispatch( $request );
    246246        $this->assertEquals( 200, $response->get_status() );
    247247        $data = $response->get_data();
     
    252252        $request->set_param( 'order', 'asc' );
    253253        $request->set_param( 'per_page', 2 );
    254         $response = $this->server->dispatch( $request );
     254        $response = rest_get_server()->dispatch( $request );
    255255        $this->assertEquals( 200, $response->get_status() );
    256256        $data = $response->get_data();
     
    265265        // defaults to orderby=name, order=asc
    266266        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    267         $response = $this->server->dispatch( $request );
     267        $response = rest_get_server()->dispatch( $request );
    268268        $this->assertEquals( 200, $response->get_status() );
    269269        $data = $response->get_data();
     
    275275        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    276276        $request->set_param( 'orderby', 'id' );
    277         $response = $this->server->dispatch( $request );
     277        $response = rest_get_server()->dispatch( $request );
    278278        $this->assertEquals( 200, $response->get_status() );
    279279        $data = $response->get_data();
     
    286286        $request->set_param( 'orderby', 'id' );
    287287        $request->set_param( 'order', 'desc' );
    288         $response = $this->server->dispatch( $request );
     288        $response = rest_get_server()->dispatch( $request );
    289289        $data     = $response->get_data();
    290290        $this->assertEquals( 200, $response->get_status() );
     
    302302        $request->set_param( 'orderby', 'include_slugs' );
    303303        $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) );
    304         $response = $this->server->dispatch( $request );
     304        $response = rest_get_server()->dispatch( $request );
    305305        $data     = $response->get_data();
    306306        $this->assertEquals( 200, $response->get_status() );
     
    340340        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    341341        $request->set_param( 'post', $post_id );
    342         $response = $this->server->dispatch( $request );
     342        $response = rest_get_server()->dispatch( $request );
    343343        $this->assertEquals( 200, $response->get_status() );
    344344
     
    358358        $request->set_param( 'post', $post_id );
    359359        $request->set_param( 'orderby', 'description' );
    360         $response = $this->server->dispatch( $request );
     360        $response = rest_get_server()->dispatch( $request );
    361361        $this->assertEquals( 200, $response->get_status() );
    362362
     
    368368        // Flip the order
    369369        $request->set_param( 'order', 'desc' );
    370         $response = $this->server->dispatch( $request );
     370        $response = rest_get_server()->dispatch( $request );
    371371        $this->assertEquals( 200, $response->get_status() );
    372372
     
    383383        $request->set_param( 'post', $post_id );
    384384        $request->set_param( 'orderby', 'id' );
    385         $response = $this->server->dispatch( $request );
     385        $response = rest_get_server()->dispatch( $request );
    386386        $this->assertEquals( 200, $response->get_status() );
    387387
     
    419419        $request = new WP_REST_Request( 'GET', '/wp/v2/batman' );
    420420        $request->set_param( 'post', $post_id );
    421         $response = $this->server->dispatch( $request );
     421        $response = rest_get_server()->dispatch( $request );
    422422        $this->assertEquals( 200, $response->get_status() );
    423423
     
    436436        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    437437        $request->set_param( 'search', 'App' );
    438         $response = $this->server->dispatch( $request );
     438        $response = rest_get_server()->dispatch( $request );
    439439        $this->assertEquals( 200, $response->get_status() );
    440440        $data = $response->get_data();
     
    443443        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    444444        $request->set_param( 'search', 'Garbage' );
    445         $response = $this->server->dispatch( $request );
     445        $response = rest_get_server()->dispatch( $request );
    446446        $this->assertEquals( 200, $response->get_status() );
    447447        $data = $response->get_data();
     
    454454        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    455455        $request->set_param( 'slug', 'apple' );
    456         $response = $this->server->dispatch( $request );
     456        $response = rest_get_server()->dispatch( $request );
    457457        $this->assertEquals( 200, $response->get_status() );
    458458        $data = $response->get_data();
     
    471471        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    472472        $request->set_param( 'parent', $category1 );
    473         $response = $this->server->dispatch( $request );
     473        $response = rest_get_server()->dispatch( $request );
    474474        $data     = $response->get_data();
    475475        $this->assertEquals( 1, count( $data ) );
     
    487487        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    488488        $request->set_param( 'parent', 'invalid-parent' );
    489         $response = $this->server->dispatch( $request );
     489        $response = rest_get_server()->dispatch( $request );
    490490        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    491491    }
     
    507507
    508508        $request  = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' );
    509         $response = $this->server->dispatch( $request );
     509        $response = rest_get_server()->dispatch( $request );
    510510        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    511511    }
     
    513513    public function test_get_terms_invalid_taxonomy() {
    514514        $request  = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy' );
    515         $response = $this->server->dispatch( $request );
     515        $response = rest_get_server()->dispatch( $request );
    516516        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    517517    }
     
    527527        }
    528528        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    529         $response = $this->server->dispatch( $request );
     529        $response = rest_get_server()->dispatch( $request );
    530530        $headers  = $response->get_headers();
    531531        $this->assertEquals( 50, $headers['X-WP-Total'] );
     
    547547        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    548548        $request->set_param( 'page', 3 );
    549         $response = $this->server->dispatch( $request );
     549        $response = rest_get_server()->dispatch( $request );
    550550        $headers  = $response->get_headers();
    551551        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    567567        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    568568        $request->set_param( 'page', 6 );
    569         $response = $this->server->dispatch( $request );
     569        $response = rest_get_server()->dispatch( $request );
    570570        $headers  = $response->get_headers();
    571571        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    582582        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    583583        $request->set_param( 'page', 8 );
    584         $response = $this->server->dispatch( $request );
     584        $response = rest_get_server()->dispatch( $request );
    585585        $headers  = $response->get_headers();
    586586        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    608608        $request->set_param( 'page', 1 );
    609609        $request->set_param( 'per_page', 100 );
    610         $response = $this->server->dispatch( $request );
     610        $response = rest_get_server()->dispatch( $request );
    611611        $headers  = $response->get_headers();
    612612        $this->assertEquals( 18, $headers['X-WP-Total'] );
     
    616616        $request->set_param( 'page', 2 );
    617617        $request->set_param( 'per_page', 100 );
    618         $response = $this->server->dispatch( $request );
     618        $response = rest_get_server()->dispatch( $request );
    619619        $headers  = $response->get_headers();
    620620        $this->assertEquals( 18, $headers['X-WP-Total'] );
     
    625625    public function test_get_item() {
    626626        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/1' );
    627         $response = $this->server->dispatch( $request );
     627        $response = rest_get_server()->dispatch( $request );
    628628        $this->check_get_taxonomy_term_response( $response );
    629629    }
     
    631631    public function test_get_term_invalid_taxonomy() {
    632632        $request  = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' );
    633         $response = $this->server->dispatch( $request );
     633        $response = rest_get_server()->dispatch( $request );
    634634        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    635635    }
     
    637637    public function test_get_term_invalid_term() {
    638638        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    639         $response = $this->server->dispatch( $request );
     639        $response = rest_get_server()->dispatch( $request );
    640640        $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    641641    }
     
    645645        $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' );
    646646        $request->set_param( 'context', 'edit' );
    647         $response = $this->server->dispatch( $request );
     647        $response = rest_get_server()->dispatch( $request );
    648648        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    649649    }
     
    659659
    660660        $request  = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 );
    661         $response = $this->server->dispatch( $request );
     661        $response = rest_get_server()->dispatch( $request );
    662662        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    663663    }
     
    672672        );
    673673        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $term1 );
    674         $response = $this->server->dispatch( $request );
     674        $response = rest_get_server()->dispatch( $request );
    675675        $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    676676    }
     
    682682        $request->set_param( 'description', 'This term is so awesome.' );
    683683        $request->set_param( 'slug', 'so-awesome' );
    684         $response = $this->server->dispatch( $request );
     684        $response = rest_get_server()->dispatch( $request );
    685685        $this->assertEquals( 201, $response->get_status() );
    686686        $headers = $response->get_headers();
     
    702702        $request->set_param( 'name', 'Existing' );
    703703
    704         $response = $this->server->dispatch( $request );
     704        $response = rest_get_server()->dispatch( $request );
    705705        $this->assertEquals( 400, $response->get_status() );
    706706        $data = $response->get_data();
     
    715715        $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy' );
    716716        $request->set_param( 'name', 'Invalid Taxonomy' );
    717         $response = $this->server->dispatch( $request );
     717        $response = rest_get_server()->dispatch( $request );
    718718        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    719719    }
     
    723723        $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
    724724        $request->set_param( 'name', 'Incorrect permissions' );
    725         $response = $this->server->dispatch( $request );
     725        $response = rest_get_server()->dispatch( $request );
    726726        $this->assertErrorResponse( 'rest_cannot_create', $response, 403 );
    727727    }
     
    730730        wp_set_current_user( self::$administrator );
    731731        $request  = new WP_REST_Request( 'POST', '/wp/v2/categories' );
    732         $response = $this->server->dispatch( $request );
     732        $response = rest_get_server()->dispatch( $request );
    733733        $this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 );
    734734    }
     
    740740        $request->set_param( 'name', 'My Awesome Term' );
    741741        $request->set_param( 'parent', $parent['term_id'] );
    742         $response = $this->server->dispatch( $request );
     742        $response = rest_get_server()->dispatch( $request );
    743743        $this->assertEquals( 201, $response->get_status() );
    744744        $data = $response->get_data();
     
    753753        $request->set_param( 'name', 'My Awesome Term' );
    754754        $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    755         $response = $this->server->dispatch( $request );
     755        $response = rest_get_server()->dispatch( $request );
    756756        $this->assertErrorResponse( 'rest_term_invalid', $response, 400 );
    757757    }
     
    769769        $request->set_param( 'description', 'New Description' );
    770770        $request->set_param( 'slug', 'new-slug' );
    771         $response = $this->server->dispatch( $request );
     771        $response = rest_get_server()->dispatch( $request );
    772772        $this->assertEquals( 200, $response->get_status() );
    773773        $data = $response->get_data();
     
    781781        $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    782782        $request->set_param( 'name', 'Invalid Taxonomy' );
    783         $response = $this->server->dispatch( $request );
     783        $response = rest_get_server()->dispatch( $request );
    784784        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    785785    }
     
    789789        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    790790        $request->set_param( 'name', 'Invalid Term' );
    791         $response = $this->server->dispatch( $request );
     791        $response = rest_get_server()->dispatch( $request );
    792792        $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    793793    }
     
    798798        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
    799799        $request->set_param( 'name', 'Incorrect permissions' );
    800         $response = $this->server->dispatch( $request );
     800        $response = rest_get_server()->dispatch( $request );
    801801        $this->assertErrorResponse( 'rest_cannot_update', $response, 403 );
    802802    }
     
    809809        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
    810810        $request->set_param( 'parent', $parent->term_id );
    811         $response = $this->server->dispatch( $request );
     811        $response = rest_get_server()->dispatch( $request );
    812812        $this->assertEquals( 200, $response->get_status() );
    813813
     
    822822        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
    823823        $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    824         $response = $this->server->dispatch( $request );
     824        $response = rest_get_server()->dispatch( $request );
    825825        $this->assertErrorResponse( 'rest_term_invalid', $response, 400 );
    826826    }
     
    831831        $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    832832        $request->set_param( 'force', true );
    833         $response = $this->server->dispatch( $request );
     833        $response = rest_get_server()->dispatch( $request );
    834834        $this->assertEquals( 200, $response->get_status() );
    835835        $data = $response->get_data();
     
    843843
    844844        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    845         $response = $this->server->dispatch( $request );
     845        $response = rest_get_server()->dispatch( $request );
    846846        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    847847
    848848        $request->set_param( 'force', 'false' );
    849         $response = $this->server->dispatch( $request );
     849        $response = rest_get_server()->dispatch( $request );
    850850        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    851851    }
     
    854854        wp_set_current_user( self::$administrator );
    855855        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    856         $response = $this->server->dispatch( $request );
     856        $response = rest_get_server()->dispatch( $request );
    857857        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    858858    }
     
    861861        wp_set_current_user( self::$administrator );
    862862        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    863         $response = $this->server->dispatch( $request );
     863        $response = rest_get_server()->dispatch( $request );
    864864        $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    865865    }
     
    869869        $term     = get_term_by( 'id', $this->factory->category->create(), 'category' );
    870870        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    871         $response = $this->server->dispatch( $request );
     871        $response = rest_get_server()->dispatch( $request );
    872872        $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
    873873    }
     
    877877
    878878        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/1' );
    879         $response = $this->server->dispatch( $request );
     879        $response = rest_get_server()->dispatch( $request );
    880880        $data     = $response->get_data();
    881881
     
    892892
    893893        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $child );
    894         $response = $this->server->dispatch( $request );
     894        $response = rest_get_server()->dispatch( $request );
    895895        $data     = $response->get_data();
    896896
     
    905905    public function test_get_item_schema() {
    906906        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    907         $response   = $this->server->dispatch( $request );
     907        $response   = rest_get_server()->dispatch( $request );
    908908        $data       = $response->get_data();
    909909        $properties = $data['schema']['properties'];
     
    939939        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    940940
    941         $response = $this->server->dispatch( $request );
     941        $response = rest_get_server()->dispatch( $request );
    942942        $data     = $response->get_data();
    943943        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
     
    947947        $request     = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id );
    948948
    949         $response = $this->server->dispatch( $request );
     949        $response = rest_get_server()->dispatch( $request );
    950950        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    951951
  • trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r42343 r42724  
    123123
    124124    public function test_register_routes() {
    125         $routes = $this->server->get_routes();
     125        $routes = rest_get_server()->get_routes();
    126126
    127127        $this->assertArrayHasKey( '/wp/v2/comments', $routes );
     
    134134        // Collection
    135135        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' );
    136         $response = $this->server->dispatch( $request );
     136        $response = rest_get_server()->dispatch( $request );
    137137        $data     = $response->get_data();
    138138        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    140140        // Single
    141141        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . self::$approved_id );
    142         $response = $this->server->dispatch( $request );
     142        $response = rest_get_server()->dispatch( $request );
    143143        $data     = $response->get_data();
    144144        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    148148    public function test_registered_query_params() {
    149149        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' );
    150         $response = $this->server->dispatch( $request );
     150        $response = rest_get_server()->dispatch( $request );
    151151        $data     = $response->get_data();
    152152        $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    183183        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    184184
    185         $response = $this->server->dispatch( $request );
     185        $response = rest_get_server()->dispatch( $request );
    186186        $this->assertEquals( 200, $response->get_status() );
    187187
     
    207207        $request->set_param( 'post', self::$password_id );
    208208
    209         $response = $this->server->dispatch( $request );
     209        $response = rest_get_server()->dispatch( $request );
    210210        $this->assertEquals( 200, $response->get_status() );
    211211
     
    228228        $request->set_param( 'password', 'toomanysecrets' );
    229229
    230         $response = $this->server->dispatch( $request );
     230        $response = rest_get_server()->dispatch( $request );
    231231        $this->assertEquals( 200, $response->get_status() );
    232232
     
    250250        $request->set_param( 'post', array( self::$password_id, self::$post_id ) );
    251251
    252         $response = $this->server->dispatch( $request );
     252        $response = rest_get_server()->dispatch( $request );
    253253        $this->assertErrorResponse( 'rest_cannot_read_post', $response, 401 );
    254254    }
     
    265265        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    266266
    267         $response = $this->server->dispatch( $request );
     267        $response = rest_get_server()->dispatch( $request );
    268268        $this->assertEquals( 200, $response->get_status() );
    269269
     
    283283        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    284284
    285         $response = $this->server->dispatch( $request );
     285        $response = rest_get_server()->dispatch( $request );
    286286        $this->assertEquals( 200, $response->get_status() );
    287287
     
    301301        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    302302
    303         $response = $this->server->dispatch( $request );
     303        $response = rest_get_server()->dispatch( $request );
    304304        $this->assertEquals( 200, $response->get_status() );
    305305
     
    319319        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    320320
    321         $response = $this->server->dispatch( $request );
     321        $response = rest_get_server()->dispatch( $request );
    322322        $this->assertEquals( 200, $response->get_status() );
    323323
     
    338338        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    339339
    340         $response = $this->server->dispatch( $request );
     340        $response = rest_get_server()->dispatch( $request );
    341341        $this->assertEquals( 200, $response->get_status() );
    342342
     
    359359        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    360360
    361         $response = $this->server->dispatch( $request );
     361        $response = rest_get_server()->dispatch( $request );
    362362        $this->assertEquals( 200, $response->get_status() );
    363363
     
    372372        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    373373        $request->set_param( 'context', 'edit' );
    374         $response = $this->server->dispatch( $request );
     374        $response = rest_get_server()->dispatch( $request );
    375375        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    376376    }
     
    381381        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    382382        $request->set_param( 'post', 0 );
    383         $response = $this->server->dispatch( $request );
     383        $response = rest_get_server()->dispatch( $request );
    384384        $this->assertEquals( 200, $response->get_status() );
    385385        $comments = $response->get_data();
     
    391391        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    392392        $request->set_param( 'post', 0 );
    393         $response = $this->server->dispatch( $request );
     393        $response = rest_get_server()->dispatch( $request );
    394394        $this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
    395395    }
     
    399399        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    400400        $request->set_param( 'context', 'edit' );
    401         $response = $this->server->dispatch( $request );
     401        $response = rest_get_server()->dispatch( $request );
    402402        $this->assertEquals( 200, $response->get_status() );
    403403    }
     
    414414        );
    415415
    416         $response = $this->server->dispatch( $request );
     416        $response = rest_get_server()->dispatch( $request );
    417417        $this->assertEquals( 200, $response->get_status() );
    418418
     
    434434        $request->set_param( 'order', 'asc' );
    435435        $request->set_param( 'include', array( $id3, $id1 ) );
    436         $response = $this->server->dispatch( $request );
     436        $response = rest_get_server()->dispatch( $request );
    437437        $data     = $response->get_data();
    438438        $this->assertEquals( 2, count( $data ) );
     
    440440        // Orderby=>include
    441441        $request->set_param( 'orderby', 'include' );
    442         $response = $this->server->dispatch( $request );
     442        $response = rest_get_server()->dispatch( $request );
    443443        $data     = $response->get_data();
    444444        $this->assertEquals( 2, count( $data ) );
     
    446446        // Orderby=>invalid should fail.
    447447        $request->set_param( 'orderby', 'invalid' );
    448         $response = $this->server->dispatch( $request );
     448        $response = rest_get_server()->dispatch( $request );
    449449        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    450450        // fails on invalid id.
    451451        $request->set_param( 'orderby', array( 'include' ) );
    452452        $request->set_param( 'include', array( 'invalid' ) );
    453         $response = $this->server->dispatch( $request );
     453        $response = rest_get_server()->dispatch( $request );
    454454        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    455455    }
     
    464464        $id2      = $this->factory->comment->create( $args );
    465465        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    466         $response = $this->server->dispatch( $request );
     466        $response = rest_get_server()->dispatch( $request );
    467467        $data     = $response->get_data();
    468468        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    469469        $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
    470470        $request->set_param( 'exclude', array( $id2 ) );
    471         $response = $this->server->dispatch( $request );
     471        $response = rest_get_server()->dispatch( $request );
    472472        $data     = $response->get_data();
    473473        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     
    476476        // fails on invalid id.
    477477        $request->set_param( 'exclude', array( 'invalid' ) );
    478         $response = $this->server->dispatch( $request );
     478        $response = rest_get_server()->dispatch( $request );
    479479        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    480480    }
     
    491491        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    492492        $request->set_param( 'offset', 1 );
    493         $response = $this->server->dispatch( $request );
     493        $response = rest_get_server()->dispatch( $request );
    494494        $this->assertCount( 3, $response->get_data() );
    495495        // 'offset' works with 'per_page'
    496496        $request->set_param( 'per_page', 2 );
    497         $response = $this->server->dispatch( $request );
     497        $response = rest_get_server()->dispatch( $request );
    498498        $this->assertCount( 2, $response->get_data() );
    499499        // 'offset' takes priority over 'page'
    500500        $request->set_param( 'page', 3 );
    501         $response = $this->server->dispatch( $request );
     501        $response = rest_get_server()->dispatch( $request );
    502502        $this->assertCount( 2, $response->get_data() );
    503503        // 'offset' with invalid value errors.
    504504        $request->set_param( 'offset', 'moreplease' );
    505         $response = $this->server->dispatch( $request );
     505        $response = rest_get_server()->dispatch( $request );
    506506        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    507507    }
     
    518518        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    519519        // order defaults to 'desc'
    520         $response = $this->server->dispatch( $request );
     520        $response = rest_get_server()->dispatch( $request );
    521521        $data     = $response->get_data();
    522522        $this->assertEquals( $id3, $data[0]['id'] );
    523523        // order=>asc
    524524        $request->set_param( 'order', 'asc' );
    525         $response = $this->server->dispatch( $request );
     525        $response = rest_get_server()->dispatch( $request );
    526526        $data     = $response->get_data();
    527527        $this->assertEquals( self::$approved_id, $data[0]['id'] );
    528528        // order=>asc,id should fail
    529529        $request->set_param( 'order', 'asc,id' );
    530         $response = $this->server->dispatch( $request );
     530        $response = rest_get_server()->dispatch( $request );
    531531        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    532532    }
     
    537537        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    538538        $request->set_param( 'post', $post_id );
    539         $response = $this->server->dispatch( $request );
     539        $response = rest_get_server()->dispatch( $request );
    540540        $this->assertErrorResponse( 'rest_cannot_read_post', $response, 401 );
    541541    }
     
    558558        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    559559        $request->set_param( 'author', self::$author_id );
    560         $response = $this->server->dispatch( $request );
     560        $response = rest_get_server()->dispatch( $request );
    561561        $this->assertEquals( 200, $response->get_status() );
    562562        $comments = $response->get_data();
     
    564564        // Multiple authors are supported
    565565        $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) );
    566         $response = $this->server->dispatch( $request );
     566        $response = rest_get_server()->dispatch( $request );
    567567        $this->assertEquals( 200, $response->get_status() );
    568568        $comments = $response->get_data();
     
    570570        // Invalid author param errors
    571571        $request->set_param( 'author', 'skippy' );
    572         $response = $this->server->dispatch( $request );
     572        $response = rest_get_server()->dispatch( $request );
    573573        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    574574        // Unavailable to unauthenticated; defaults to error
    575575        wp_set_current_user( 0 );
    576576        $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) );
    577         $response = $this->server->dispatch( $request );
     577        $response = rest_get_server()->dispatch( $request );
    578578        $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 );
    579579    }
     
    594594
    595595        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    596         $response = $this->server->dispatch( $request );
     596        $response = rest_get_server()->dispatch( $request );
    597597        $comments = $response->get_data();
    598598        $this->assertCount( 4, $comments );
     
    601601        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    602602        $request->set_param( 'author_exclude', self::$author_id );
    603         $response = $this->server->dispatch( $request );
     603        $response = rest_get_server()->dispatch( $request );
    604604        $this->assertEquals( 200, $response->get_status() );
    605605        $comments = $response->get_data();
     
    608608        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    609609        $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) );
    610         $response = $this->server->dispatch( $request );
     610        $response = rest_get_server()->dispatch( $request );
    611611        $this->assertEquals( 200, $response->get_status() );
    612612        $comments = $response->get_data();
     
    615615        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    616616        $request->set_param( 'author_exclude', 'skippy' );
    617         $response = $this->server->dispatch( $request );
     617        $response = rest_get_server()->dispatch( $request );
    618618        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    619619        // Unavailable to unauthenticated; defaults to error
    620620        wp_set_current_user( 0 );
    621621        $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) );
    622         $response = $this->server->dispatch( $request );
     622        $response = rest_get_server()->dispatch( $request );
    623623        $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 );
    624624    }
     
    637637        // All comments in the database
    638638        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    639         $response = $this->server->dispatch( $request );
     639        $response = rest_get_server()->dispatch( $request );
    640640        $this->assertCount( 5, $response->get_data() );
    641641        // Limit to the parent
    642642        $request->set_param( 'parent', $parent_id );
    643         $response = $this->server->dispatch( $request );
     643        $response = rest_get_server()->dispatch( $request );
    644644        $this->assertCount( 1, $response->get_data() );
    645645        // Limit to two parents
    646646        $request->set_param( 'parent', array( $parent_id, $parent_id2 ) );
    647         $response = $this->server->dispatch( $request );
     647        $response = rest_get_server()->dispatch( $request );
    648648        $this->assertCount( 2, $response->get_data() );
    649649        // Invalid parent should error
    650650        $request->set_param( 'parent', 'invalid' );
    651         $response = $this->server->dispatch( $request );
     651        $response = rest_get_server()->dispatch( $request );
    652652        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    653653    }
     
    666666        // All comments in the database
    667667        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    668         $response = $this->server->dispatch( $request );
     668        $response = rest_get_server()->dispatch( $request );
    669669        $this->assertCount( 5, $response->get_data() );
    670670        // Exclude this particular parent
    671671        $request->set_param( 'parent_exclude', $parent_id );
    672         $response = $this->server->dispatch( $request );
     672        $response = rest_get_server()->dispatch( $request );
    673673        $this->assertCount( 4, $response->get_data() );
    674674        // Exclude both comment parents
    675675        $request->set_param( 'parent_exclude', array( $parent_id, $parent_id2 ) );
    676         $response = $this->server->dispatch( $request );
     676        $response = rest_get_server()->dispatch( $request );
    677677        $this->assertCount( 3, $response->get_data() );
    678678        // Invalid parent id should error
    679679        $request->set_param( 'parent_exclude', 'invalid' );
    680         $response = $this->server->dispatch( $request );
     680        $response = rest_get_server()->dispatch( $request );
    681681        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    682682    }
     
    697697        // 3 comments, plus 1 created in construct
    698698        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    699         $response = $this->server->dispatch( $request );
     699        $response = rest_get_server()->dispatch( $request );
    700700        $this->assertCount( 4, $response->get_data() );
    701701        // One matching comments
    702702        $request->set_param( 'search', 'foo' );
    703         $response = $this->server->dispatch( $request );
     703        $response = rest_get_server()->dispatch( $request );
    704704        $data     = $response->get_data();
    705705        $this->assertCount( 1, $data );
     
    719719        }
    720720        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    721         $response = $this->server->dispatch( $request );
     721        $response = rest_get_server()->dispatch( $request );
    722722        $headers  = $response->get_headers();
    723723        $this->assertEquals( 50, $headers['X-WP-Total'] );
     
    739739        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    740740        $request->set_param( 'page', 3 );
    741         $response = $this->server->dispatch( $request );
     741        $response = rest_get_server()->dispatch( $request );
    742742        $headers  = $response->get_headers();
    743743        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    758758        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    759759        $request->set_param( 'page', 6 );
    760         $response = $this->server->dispatch( $request );
     760        $response = rest_get_server()->dispatch( $request );
    761761        $headers  = $response->get_headers();
    762762        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    772772        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    773773        $request->set_param( 'page', 8 );
    774         $response = $this->server->dispatch( $request );
     774        $response = rest_get_server()->dispatch( $request );
    775775        $headers  = $response->get_headers();
    776776        $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    789789        $request->set_param( 'after', rand_str() );
    790790        $request->set_param( 'before', rand_str() );
    791         $response = $this->server->dispatch( $request );
     791        $response = rest_get_server()->dispatch( $request );
    792792        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    793793    }
     
    816816        $request->set_param( 'after', '2016-01-15T00:00:00Z' );
    817817        $request->set_param( 'before', '2016-01-17T00:00:00Z' );
    818         $response = $this->server->dispatch( $request );
     818        $response = rest_get_server()->dispatch( $request );
    819819        $data     = $response->get_data();
    820820        $this->assertCount( 1, $data );
     
    825825        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    826826
    827         $response = $this->server->dispatch( $request );
     827        $response = rest_get_server()->dispatch( $request );
    828828        $this->assertEquals( 200, $response->get_status() );
    829829
     
    841841        );
    842842
    843         $response = $this->server->dispatch( $request );
     843        $response = rest_get_server()->dispatch( $request );
    844844        $this->assertEquals( 200, $response->get_status() );
    845845
     
    851851        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    852852
    853         $response = $this->server->dispatch( $request );
     853        $response = rest_get_server()->dispatch( $request );
    854854
    855855        $data = $response->get_data();
     
    869869        $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    870870
    871         $response = $this->server->dispatch( $request );
     871        $response = rest_get_server()->dispatch( $request );
    872872        $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 );
    873873    }
     
    877877        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', self::$approved_id ) );
    878878        $request->set_param( 'context', 'edit' );
    879         $response = $this->server->dispatch( $request );
     879        $response = rest_get_server()->dispatch( $request );
    880880        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    881881    }
     
    891891        $request    = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
    892892
    893         $response = $this->server->dispatch( $request );
     893        $response = rest_get_server()->dispatch( $request );
    894894        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
    895895    }
     
    905905        $request    = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
    906906
    907         $response = $this->server->dispatch( $request );
     907        $response = rest_get_server()->dispatch( $request );
    908908        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
    909909    }
     
    914914        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    915915
    916         $response = $this->server->dispatch( $request );
     916        $response = rest_get_server()->dispatch( $request );
    917917        $this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
    918918    }
     
    923923        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    924924
    925         $response = $this->server->dispatch( $request );
     925        $response = rest_get_server()->dispatch( $request );
    926926        $this->assertEquals( 200, $response->get_status() );
    927927    }
     
    946946
    947947        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    948         $response = $this->server->dispatch( $request );
     948        $response = rest_get_server()->dispatch( $request );
    949949        $this->assertEquals( 200, $response->get_status() );
    950950        $this->assertArrayHasKey( 'children', $response->get_links() );
     
    961961
    962962        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    963         $response = $this->server->dispatch( $request );
     963        $response = rest_get_server()->dispatch( $request );
    964964        $this->assertEquals( 200, $response->get_status() );
    965965        $this->assertArrayNotHasKey( 'children', $response->get_links() );
     
    974974        $password_comment = $this->factory->comment->create( $args );
    975975        $request          = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) );
    976         $response         = $this->server->dispatch( $request );
     976        $response         = rest_get_server()->dispatch( $request );
    977977        $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
    978978    }
     
    993993        $request->set_param( 'password', 'toomanysecrets' );
    994994
    995         $response = $this->server->dispatch( $request );
     995        $response = rest_get_server()->dispatch( $request );
    996996        $this->assertEquals( 200, $response->get_status() );
    997997    }
     
    10131013        $request->set_body( wp_json_encode( $params ) );
    10141014
    1015         $response = $this->server->dispatch( $request );
     1015        $response = rest_get_server()->dispatch( $request );
    10161016        $this->assertEquals( 201, $response->get_status() );
    10171017
     
    10841084            $request->set_param( 'date_gmt', $params['date_gmt'] );
    10851085        }
    1086         $response = $this->server->dispatch( $request );
     1086        $response = rest_get_server()->dispatch( $request );
    10871087
    10881088        update_option( 'timezone_string', '' );
     
    11181118        $request->set_body( wp_json_encode( $params ) );
    11191119
    1120         $response = $this->server->dispatch( $request );
     1120        $response = rest_get_server()->dispatch( $request );
    11211121        $this->assertEquals( 201, $response->get_status() );
    11221122
     
    11431143        $request->set_body( wp_json_encode( $params ) );
    11441144
    1145         $response = $this->server->dispatch( $request );
     1145        $response = rest_get_server()->dispatch( $request );
    11461146
    11471147        $this->assertErrorResponse( 'test_rest_premade_error', $response, 418 );
     
    11661166        $request->set_body( wp_json_encode( $params ) );
    11671167
    1168         $response = $this->server->dispatch( $request );
     1168        $response = rest_get_server()->dispatch( $request );
    11691169
    11701170        $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 );
     
    11861186        $request->set_body( wp_json_encode( $params ) );
    11871187
    1188         $response = $this->server->dispatch( $request );
     1188        $response = rest_get_server()->dispatch( $request );
    11891189
    11901190        $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 );
     
    12051205        $request->set_body( wp_json_encode( $params ) );
    12061206
    1207         $response = $this->server->dispatch( $request );
     1207        $response = rest_get_server()->dispatch( $request );
    12081208        $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 );
    12091209    }
     
    12241224        $request->set_body( wp_json_encode( $params ) );
    12251225
    1226         $response = $this->server->dispatch( $request );
     1226        $response = rest_get_server()->dispatch( $request );
    12271227        $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 );
    12281228    }
     
    12411241        $request->add_header( 'content-type', 'application/json' );
    12421242        $request->set_body( wp_json_encode( $params ) );
    1243         $response = $this->server->dispatch( $request );
     1243        $response = rest_get_server()->dispatch( $request );
    12441244
    12451245        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    12631263        $request->set_body( wp_json_encode( $params ) );
    12641264
    1265         $response = $this->server->dispatch( $request );
     1265        $response = rest_get_server()->dispatch( $request );
    12661266        $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 );
    12671267
    12681268        $params['content'] = '';
    12691269        $request->set_body( wp_json_encode( $params ) );
    1270         $response = $this->server->dispatch( $request );
     1270        $response = rest_get_server()->dispatch( $request );
    12711271        $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 );
    12721272    }
     
    12881288        $request->set_body( wp_json_encode( $params ) );
    12891289
    1290         $response = $this->server->dispatch( $request );
     1290        $response = rest_get_server()->dispatch( $request );
    12911291        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    12921292    }
     
    13141314        $request->add_header( 'content-type', 'application/json' );
    13151315        $request->set_body( wp_json_encode( $params ) );
    1316         $response = $this->server->dispatch( $request );
     1316        $response = rest_get_server()->dispatch( $request );
    13171317        $this->assertEquals( 201, $response->get_status() );
    13181318
     
    13401340        $request->set_body( wp_json_encode( $params ) );
    13411341
    1342         $response = $this->server->dispatch( $request );
     1342        $response = rest_get_server()->dispatch( $request );
    13431343        $this->assertEquals( 201, $response->get_status() );
    13441344
     
    13511351        $collection = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    13521352        $collection->set_param( 'post', $post_id );
    1353         $collection_response = $this->server->dispatch( $collection );
     1353        $collection_response = rest_get_server()->dispatch( $collection );
    13541354        $collection_data     = $collection_response->get_data();
    13551355        $this->assertEquals( $comment_id, $collection_data[0]['id'] );
     
    13781378        $request->set_body( wp_json_encode( $params ) );
    13791379
    1380         $response = $this->server->dispatch( $request );
     1380        $response = rest_get_server()->dispatch( $request );
    13811381        $this->assertErrorResponse( 'rest_invalid_comment_type', $response, 400 );
    13821382    }
     
    14001400        $request->set_body( wp_json_encode( $params ) );
    14011401
    1402         $response = $this->server->dispatch( $request );
     1402        $response = rest_get_server()->dispatch( $request );
    14031403        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    14041404    }
     
    14261426        $request->add_header( 'content-type', 'application/json' );
    14271427        $request->set_body( wp_json_encode( $params ) );
    1428         $response = $this->server->dispatch( $request );
     1428        $response = rest_get_server()->dispatch( $request );
    14291429
    14301430        $this->assertEquals( 201, $response->get_status() );
     
    14551455        $request->add_header( 'content-type', 'application/json' );
    14561456        $request->set_body( wp_json_encode( $params ) );
    1457         $response = $this->server->dispatch( $request );
     1457        $response = rest_get_server()->dispatch( $request );
    14581458
    14591459        $this->assertEquals( 201, $response->get_status() );
     
    14801480        $request->add_header( 'content-type', 'application/json' );
    14811481        $request->set_body( wp_json_encode( $params ) );
    1482         $response = $this->server->dispatch( $request );
     1482        $response = rest_get_server()->dispatch( $request );
    14831483
    14841484        $this->assertErrorResponse( 'rest_comment_invalid_author', $response, 403 );
     
    15001500        $request->add_header( 'content-type', 'application/json' );
    15011501        $request->set_body( wp_json_encode( $params ) );
    1502         $response = $this->server->dispatch( $request );
     1502        $response = rest_get_server()->dispatch( $request );
    15031503
    15041504        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    15211521        $request->add_header( 'content-type', 'application/json' );
    15221522        $request->set_body( wp_json_encode( $params ) );
    1523         $response = $this->server->dispatch( $request );
     1523        $response = rest_get_server()->dispatch( $request );
    15241524
    15251525        $this->assertErrorResponse( 'rest_comment_invalid_status', $response, 403 );
     
    15451545        $request->set_body( wp_json_encode( $params ) );
    15461546
    1547         $response = $this->server->dispatch( $request );
     1547        $response = rest_get_server()->dispatch( $request );
    15481548        $this->assertEquals( 201, $response->get_status() );
    15491549
     
    15701570        $request->set_body( wp_json_encode( $params ) );
    15711571
    1572         $response = $this->server->dispatch( $request );
     1572        $response = rest_get_server()->dispatch( $request );
    15731573        $this->assertEquals( 201, $response->get_status() );
    15741574
     
    15941594        $request->add_header( 'content-type', 'application/json' );
    15951595        $request->set_body( wp_json_encode( $params ) );
    1596         $response    = $this->server->dispatch( $request );
     1596        $response    = rest_get_server()->dispatch( $request );
    15971597        $data        = $response->get_data();
    15981598        $new_comment = get_comment( $data['id'] );
     
    16161616        $request->set_body( wp_json_encode( $params ) );
    16171617
    1618         $response = $this->server->dispatch( $request );
     1618        $response = rest_get_server()->dispatch( $request );
    16191619        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    16201620    }
     
    16331633        $request->add_header( 'content-type', 'application/json' );
    16341634        $request->set_body( wp_json_encode( $params ) );
    1635         $response = $this->server->dispatch( $request );
     1635        $response = rest_get_server()->dispatch( $request );
    16361636        $this->assertErrorResponse( 'rest_comment_invalid_author_ip', $response, 403 );
    16371637    }
     
    16501650        $request->add_header( 'content-type', 'application/json' );
    16511651        $request->set_body( wp_json_encode( $params ) );
    1652         $response    = $this->server->dispatch( $request );
     1652        $response    = rest_get_server()->dispatch( $request );
    16531653        $data        = $response->get_data();
    16541654        $new_comment = get_comment( $data['id'] );
     
    16701670        $request->set_body( wp_json_encode( $params ) );
    16711671
    1672         $response = $this->server->dispatch( $request );
     1672        $response = rest_get_server()->dispatch( $request );
    16731673
    16741674        $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
     
    16891689        $request->set_body( wp_json_encode( $params ) );
    16901690
    1691         $response = $this->server->dispatch( $request );
     1691        $response = rest_get_server()->dispatch( $request );
    16921692        $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
    16931693    }
     
    17091709        $request->set_body( wp_json_encode( $params ) );
    17101710
    1711         $response = $this->server->dispatch( $request );
     1711        $response = rest_get_server()->dispatch( $request );
    17121712        $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
    17131713    }
     
    17281728        $request->set_body( wp_json_encode( $params ) );
    17291729
    1730         $response = $this->server->dispatch( $request );
     1730        $response = rest_get_server()->dispatch( $request );
    17311731
    17321732        $this->assertErrorResponse( 'rest_comment_draft_post', $response, 403 );
     
    17481748        $request->set_body( wp_json_encode( $params ) );
    17491749
    1750         $response = $this->server->dispatch( $request );
     1750        $response = rest_get_server()->dispatch( $request );
    17511751
    17521752        $this->assertErrorResponse( 'rest_comment_trash_post', $response, 403 );
     
    17681768        $request->set_body( wp_json_encode( $params ) );
    17691769
    1770         $response = $this->server->dispatch( $request );
     1770        $response = rest_get_server()->dispatch( $request );
    17711771
    17721772        $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 );
     
    17881788        $request->set_body( wp_json_encode( $params ) );
    17891789
    1790         $response = $this->server->dispatch( $request );
     1790        $response = rest_get_server()->dispatch( $request );
    17911791        $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 );
    17921792    }
     
    18131813        $request->add_header( 'content-type', 'application/json' );
    18141814        $request->set_body( wp_json_encode( $params ) );
    1815         $response = $this->server->dispatch( $request );
     1815        $response = rest_get_server()->dispatch( $request );
    18161816
    18171817        $this->assertEquals( 409, $response->get_status() );
     
    18331833        $request->add_header( 'content-type', 'application/json' );
    18341834        $request->set_body( wp_json_encode( $params ) );
    1835         $response = $this->server->dispatch( $request );
     1835        $response = rest_get_server()->dispatch( $request );
    18361836
    18371837        $this->assertEquals( 403, $response->get_status() );
     
    18441844        $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    18451845        $request->set_param( 'post', self::$post_id );
    1846         $response = $this->server->dispatch( $request );
     1846        $response = rest_get_server()->dispatch( $request );
    18471847        $this->assertEquals( 401, $response->get_status() );
    18481848        $data = $response->get_data();
     
    18631863        $request->set_body( wp_json_encode( $params ) );
    18641864
    1865         $response = $this->server->dispatch( $request );
     1865        $response = rest_get_server()->dispatch( $request );
    18661866        $this->assertErrorResponse( 'rest_comment_author_invalid', $response, 400 );
    18671867    }
     
    18811881        $request->set_body( wp_json_encode( $params ) );
    18821882
    1883         $response = $this->server->dispatch( $request );
     1883        $response = rest_get_server()->dispatch( $request );
    18841884
    18851885        $result = $response->get_data();
     
    19051905        $request->set_body( wp_json_encode( $params ) );
    19061906
    1907         $response = $this->server->dispatch( $request );
     1907        $response = rest_get_server()->dispatch( $request );
    19081908        $this->assertEquals( 201, $response->get_status() );
    19091909
     
    19201920        $request->set_body( wp_json_encode( $params ) );
    19211921
    1922         $response = $this->server->dispatch( $request );
     1922        $response = rest_get_server()->dispatch( $request );
    19231923        $this->assertEquals( 400, $response->get_status() );
    19241924    }
     
    19441944        $request->set_body( wp_json_encode( $params ) );
    19451945
    1946         $response = $this->server->dispatch( $request );
     1946        $response = rest_get_server()->dispatch( $request );
    19471947
    19481948        remove_filter( 'rest_allow_anonymous_comments', array( $this, 'anonymous_comments_callback_null' ), 10, 2 );
     
    19691969        $request->add_header( 'content-type', 'application/json' );
    19701970        $request->set_body( wp_json_encode( $params ) );
    1971         $response = $this->server->dispatch( $request );
     1971        $response = rest_get_server()->dispatch( $request );
    19721972
    19731973        $this->assertErrorResponse( 'comment_author_column_length', $response, 400 );
     
    19921992        $request->add_header( 'content-type', 'application/json' );
    19931993        $request->set_body( wp_json_encode( $params ) );
    1994         $response = $this->server->dispatch( $request );
     1994        $response = rest_get_server()->dispatch( $request );
    19951995
    19961996        $this->assertErrorResponse( 'comment_author_email_column_length', $response, 400 );
     
    20152015        $request->add_header( 'content-type', 'application/json' );
    20162016        $request->set_body( wp_json_encode( $params ) );
    2017         $response = $this->server->dispatch( $request );
     2017        $response = rest_get_server()->dispatch( $request );
    20182018
    20192019        $this->assertErrorResponse( 'comment_author_url_column_length', $response, 400 );
     
    20382038        $request->add_header( 'content-type', 'application/json' );
    20392039        $request->set_body( wp_json_encode( $params ) );
    2040         $response = $this->server->dispatch( $request );
     2040        $response = rest_get_server()->dispatch( $request );
    20412041
    20422042        $this->assertErrorResponse( 'comment_content_column_length', $response, 400 );
     
    20572057        $request->add_header( 'content-type', 'application/json' );
    20582058        $request->set_body( wp_json_encode( $params ) );
    2059         $response = $this->server->dispatch( $request );
     2059        $response = rest_get_server()->dispatch( $request );
    20602060
    20612061        $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 );
     
    20772077        $request->add_header( 'content-type', 'application/json' );
    20782078        $request->set_body( wp_json_encode( $params ) );
    2079         $response = $this->server->dispatch( $request );
     2079        $response = rest_get_server()->dispatch( $request );
    20802080        $this->assertEquals( 201, $response->get_status() );
    20812081    }
     
    21002100        $request->set_body( wp_json_encode( $params ) );
    21012101
    2102         $response = $this->server->dispatch( $request );
     2102        $response = rest_get_server()->dispatch( $request );
    21032103        $this->assertEquals( 200, $response->get_status() );
    21042104
     
    21332133            $request->set_param( 'date_gmt', $params['date_gmt'] );
    21342134        }
    2135         $response = $this->server->dispatch( $request );
     2135        $response = rest_get_server()->dispatch( $request );
    21362136
    21372137        update_option( 'timezone_string', '' );
     
    21592159
    21602160        // Sending a request without content is fine.
    2161         $response = $this->server->dispatch( $request );
     2161        $response = rest_get_server()->dispatch( $request );
    21622162        $this->assertEquals( 200, $response->get_status() );
    21632163
     
    21652165        $request->set_param( 'author_email', 'yetanother@email.com' );
    21662166        $request->set_param( 'content', '' );
    2167         $response = $this->server->dispatch( $request );
     2167        $response = rest_get_server()->dispatch( $request );
    21682168        $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 );
    21692169    }
     
    21782178        // Run twice to make sure that the update still succeeds even if no DB
    21792179        // rows are updated.
    2180         $response = $this->server->dispatch( $request );
    2181         $this->assertEquals( 200, $response->get_status() );
    2182 
    2183         $response = $this->server->dispatch( $request );
     2180        $response = rest_get_server()->dispatch( $request );
     2181        $this->assertEquals( 200, $response->get_status() );
     2182
     2183        $response = rest_get_server()->dispatch( $request );
    21842184        $this->assertEquals( 200, $response->get_status() );
    21852185    }
     
    22022202        $request->set_body( wp_json_encode( $params ) );
    22032203
    2204         $response = $this->server->dispatch( $request );
     2204        $response = rest_get_server()->dispatch( $request );
    22052205        $this->assertEquals( 200, $response->get_status() );
    22062206
     
    22292229        $request->set_body( wp_json_encode( $params ) );
    22302230
    2231         $response = $this->server->dispatch( $request );
     2231        $response = rest_get_server()->dispatch( $request );
    22322232        $this->assertEquals( 200, $response->get_status() );
    22332233
     
    22502250        $request->set_body( wp_json_encode( $params ) );
    22512251
    2252         $response = $this->server->dispatch( $request );
     2252        $response = rest_get_server()->dispatch( $request );
    22532253        $this->assertEquals( 200, $response->get_status() );
    22542254
     
    22732273        $request->set_body( wp_json_encode( $params ) );
    22742274
    2275         $response = $this->server->dispatch( $request );
     2275        $response = rest_get_server()->dispatch( $request );
    22762276        $this->assertEquals( 200, $response->get_status() );
    22772277    }
     
    22922292        $request->set_body( wp_json_encode( $params ) );
    22932293
    2294         $response = $this->server->dispatch( $request );
     2294        $response = rest_get_server()->dispatch( $request );
    22952295        $this->assertEquals( 200, $response->get_status() );
    22962296    }
     
    23102310        $request->set_body( wp_json_encode( $params ) );
    23112311
    2312         $response = $this->server->dispatch( $request );
     2312        $response = rest_get_server()->dispatch( $request );
    23132313        $this->assertEquals( 200, $response->get_status() );
    23142314    }
     
    23292329        $request->set_body( wp_json_encode( $params ) );
    23302330
    2331         $response = $this->server->dispatch( $request );
     2331        $response = rest_get_server()->dispatch( $request );
    23322332        $this->assertEquals( 200, $response->get_status() );
    23332333    }
     
    23462346        $request->add_header( 'content-type', 'application/json' );
    23472347        $request->set_body( wp_json_encode( $params ) );
    2348         $response = $this->server->dispatch( $request );
     2348        $response = rest_get_server()->dispatch( $request );
    23492349
    23502350        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    23632363        $request->set_body( wp_json_encode( $params ) );
    23642364
    2365         $response = $this->server->dispatch( $request );
     2365        $response = rest_get_server()->dispatch( $request );
    23662366        $this->assertErrorResponse( 'rest_comment_invalid_type', $response, 404 );
    23672367    }
     
    23792379        $request->set_body( wp_json_encode( $params ) );
    23802380
    2381         $response = $this->server->dispatch( $request );
     2381        $response = rest_get_server()->dispatch( $request );
    23822382
    23832383        $this->assertEquals( 200, $response->get_status() );
     
    24002400        $request->set_body( wp_json_encode( $params ) );
    24012401
    2402         $response = $this->server->dispatch( $request );
     2402        $response = rest_get_server()->dispatch( $request );
    24032403        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    24042404    }
     
    24162416        $request->set_body( wp_json_encode( $params ) );
    24172417
    2418         $response = $this->server->dispatch( $request );
     2418        $response = rest_get_server()->dispatch( $request );
    24192419        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    24202420    }
     
    24302430        $request->set_body( wp_json_encode( $params ) );
    24312431
    2432         $response = $this->server->dispatch( $request );
     2432        $response = rest_get_server()->dispatch( $request );
    24332433        $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 );
    24342434    }
     
    24402440        $request->set_param( 'post', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    24412441
    2442         $response = $this->server->dispatch( $request );
     2442        $response = rest_get_server()->dispatch( $request );
    24432443        $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
    24442444    }
     
    24542454        $request->set_body( wp_json_encode( $params ) );
    24552455
    2456         $response = $this->server->dispatch( $request );
     2456        $response = rest_get_server()->dispatch( $request );
    24572457        $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 );
    24582458    }
     
    24762476        $request->set_body( wp_json_encode( $params ) );
    24772477
    2478         $response = $this->server->dispatch( $request );
     2478        $response = rest_get_server()->dispatch( $request );
    24792479        $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
    24802480    }
     
    25002500        // Check if comment 1 does not have the child link.
    25012501        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    2502         $response = $this->server->dispatch( $request );
     2502        $response = rest_get_server()->dispatch( $request );
    25032503        $this->assertEquals( 200, $response->get_status() );
    25042504        $this->assertArrayNotHasKey( 'children', $response->get_links() );
     
    25082508        $request->set_param( 'parent', $comment_id_1 );
    25092509        $request->set_param( 'content', rand_str() );
    2510         $response = $this->server->dispatch( $request );
     2510        $response = rest_get_server()->dispatch( $request );
    25112511        $this->assertEquals( 200, $response->get_status() );
    25122512
    25132513        // Check if comment 1 now has the child link.
    25142514        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    2515         $response = $this->server->dispatch( $request );
     2515        $response = rest_get_server()->dispatch( $request );
    25162516        $this->assertEquals( 200, $response->get_status() );
    25172517        $this->assertArrayHasKey( 'children', $response->get_links() );
     
    25322532        $request->add_header( 'content-type', 'application/json' );
    25332533        $request->set_body( wp_json_encode( $params ) );
    2534         $response = $this->server->dispatch( $request );
     2534        $response = rest_get_server()->dispatch( $request );
    25352535
    25362536        $this->assertErrorResponse( 'comment_author_column_length', $response, 400 );
     
    25512551        $request->add_header( 'content-type', 'application/json' );
    25522552        $request->set_body( wp_json_encode( $params ) );
    2553         $response = $this->server->dispatch( $request );
     2553        $response = rest_get_server()->dispatch( $request );
    25542554
    25552555        $this->assertErrorResponse( 'comment_author_email_column_length', $response, 400 );
     
    25702570        $request->add_header( 'content-type', 'application/json' );
    25712571        $request->set_body( wp_json_encode( $params ) );
    2572         $response = $this->server->dispatch( $request );
     2572        $response = rest_get_server()->dispatch( $request );
    25732573
    25742574        $this->assertErrorResponse( 'comment_author_url_column_length', $response, 400 );
     
    25882588        $request->add_header( 'content-type', 'application/json' );
    25892589        $request->set_body( wp_json_encode( $params ) );
    2590         $response = $this->server->dispatch( $request );
     2590        $response = rest_get_server()->dispatch( $request );
    25912591
    25922592        $this->assertErrorResponse( 'comment_content_column_length', $response, 400 );
     
    26012601            $request->set_param( $name, $value );
    26022602        }
    2603         $response = $this->server->dispatch( $request );
     2603        $response = rest_get_server()->dispatch( $request );
    26042604        $this->assertEquals( 201, $response->get_status() );
    26052605        $actual_output = $response->get_data();
     
    26272627        // See https://core.trac.wordpress.org/ticket/38700
    26282628        $request->set_param( 'author_ip', '127.0.0.2' );
    2629         $response = $this->server->dispatch( $request );
     2629        $response = rest_get_server()->dispatch( $request );
    26302630        $this->assertEquals( 200, $response->get_status() );
    26312631        $actual_output = $response->get_data();
     
    27512751        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    27522752        $request->set_param( 'force', 'false' );
    2753         $response = $this->server->dispatch( $request );
     2753        $response = rest_get_server()->dispatch( $request );
    27542754        $this->assertEquals( 200, $response->get_status() );
    27552755
     
    27712771        $request['force'] = true;
    27722772
    2773         $response = $this->server->dispatch( $request );
     2773        $response = rest_get_server()->dispatch( $request );
    27742774        $this->assertEquals( 200, $response->get_status() );
    27752775        $data = $response->get_data();
     
    27892789        );
    27902790        $request    = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    2791         $response   = $this->server->dispatch( $request );
     2791        $response   = rest_get_server()->dispatch( $request );
    27922792        $this->assertEquals( 200, $response->get_status() );
    27932793        $data     = $response->get_data();
    2794         $response = $this->server->dispatch( $request );
     2794        $response = rest_get_server()->dispatch( $request );
    27952795        $this->assertErrorResponse( 'rest_already_trashed', $response, 410 );
    27962796    }
     
    28012801        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
    28022802
    2803         $response = $this->server->dispatch( $request );
     2803        $response = rest_get_server()->dispatch( $request );
    28042804        $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 );
    28052805    }
     
    28102810        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    28112811
    2812         $response = $this->server->dispatch( $request );
     2812        $response = rest_get_server()->dispatch( $request );
    28132813        $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
    28142814    }
     
    28342834
    28352835        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%s', $child_comment ) );
    2836         $response = $this->server->dispatch( $request );
     2836        $response = rest_get_server()->dispatch( $request );
    28372837        $this->assertEquals( 200, $response->get_status() );
    28382838
    28392839        // Verify children link is gone.
    28402840        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) );
    2841         $response = $this->server->dispatch( $request );
     2841        $response = rest_get_server()->dispatch( $request );
    28422842        $this->assertEquals( 200, $response->get_status() );
    28432843        $this->assertArrayNotHasKey( 'children', $response->get_links() );
     
    28462846    public function test_get_item_schema() {
    28472847        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' );
    2848         $response   = $this->server->dispatch( $request );
     2848        $response   = rest_get_server()->dispatch( $request );
    28492849        $data       = $response->get_data();
    28502850        $properties = $data['schema']['properties'];
     
    28782878        update_option( 'show_avatars', false );
    28792879        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    2880         $response   = $this->server->dispatch( $request );
     2880        $response   = rest_get_server()->dispatch( $request );
    28812881        $data       = $response->get_data();
    28822882        $properties = $data['schema']['properties'];
     
    29042904        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' );
    29052905
    2906         $response = $this->server->dispatch( $request );
     2906        $response = rest_get_server()->dispatch( $request );
    29072907        $data     = $response->get_data();
    29082908
     
    29122912        $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id );
    29132913
    2914         $response = $this->server->dispatch( $request );
     2914        $response = rest_get_server()->dispatch( $request );
    29152915        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    29162916
     
    29242924
    29252925        wp_set_current_user( 1 );
    2926         $this->server->dispatch( $request );
     2926        rest_get_server()->dispatch( $request );
    29272927        $this->assertEquals( 123, get_comment_meta( self::$approved_id, 'my_custom_int', true ) );
    29282928
     
    29372937        );
    29382938
    2939         $response = $this->server->dispatch( $request );
     2939        $response = rest_get_server()->dispatch( $request );
    29402940
    29412941        $this->assertEquals( 123, $response->data['my_custom_int'] );
     
    29722972        );
    29732973
    2974         $response = $this->server->dispatch( $request );
     2974        $response = rest_get_server()->dispatch( $request );
    29752975
    29762976        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
  • trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php

    r42343 r42724  
    3838
    3939    public function test_register_routes() {
    40         $routes = $this->server->get_routes();
     40        $routes = rest_get_server()->get_routes();
    4141        $this->assertArrayHasKey( '/wp/v2/pages', $routes );
    4242        $this->assertCount( 2, $routes['/wp/v2/pages'] );
     
    4848        // Collection
    4949        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' );
    50         $response = $this->server->dispatch( $request );
     50        $response = rest_get_server()->dispatch( $request );
    5151        $data     = $response->get_data();
    5252        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    5555        $page_id  = $this->factory->post->create( array( 'post_type' => 'page' ) );
    5656        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages/' . $page_id );
    57         $response = $this->server->dispatch( $request );
     57        $response = rest_get_server()->dispatch( $request );
    5858        $data     = $response->get_data();
    5959        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    6363    public function test_registered_query_params() {
    6464        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' );
    65         $response = $this->server->dispatch( $request );
     65        $response = rest_get_server()->dispatch( $request );
    6666        $data     = $response->get_data();
    6767        $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    105105        );
    106106        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    107         $response = $this->server->dispatch( $request );
     107        $response = rest_get_server()->dispatch( $request );
    108108        $data     = $response->get_data();
    109109        $this->assertEquals( 1, count( $data ) );
     
    127127        // No parent
    128128        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    129         $response = $this->server->dispatch( $request );
     129        $response = rest_get_server()->dispatch( $request );
    130130        $data     = $response->get_data();
    131131        $this->assertEquals( 2, count( $data ) );
    132132        // Filter to parent
    133133        $request->set_param( 'parent', $id1 );
    134         $response = $this->server->dispatch( $request );
     134        $response = rest_get_server()->dispatch( $request );
    135135        $data     = $response->get_data();
    136136        $this->assertEquals( 1, count( $data ) );
     
    138138        // Invalid parent should fail
    139139        $request->set_param( 'parent', 'some-slug' );
    140         $response = $this->server->dispatch( $request );
     140        $response = rest_get_server()->dispatch( $request );
    141141        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    142142    }
     
    171171        // No parent
    172172        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    173         $response = $this->server->dispatch( $request );
     173        $response = rest_get_server()->dispatch( $request );
    174174        $data     = $response->get_data();
    175175        $this->assertEquals( 4, count( $data ) );
    176176        // Filter to parents
    177177        $request->set_param( 'parent', array( $id1, $id3 ) );
    178         $response = $this->server->dispatch( $request );
     178        $response = rest_get_server()->dispatch( $request );
    179179        $data     = $response->get_data();
    180180        $this->assertEquals( 2, count( $data ) );
     
    198198        // No parent
    199199        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    200         $response = $this->server->dispatch( $request );
     200        $response = rest_get_server()->dispatch( $request );
    201201        $data     = $response->get_data();
    202202        $this->assertEquals( 2, count( $data ) );
    203203        // Filter to parent
    204204        $request->set_param( 'parent_exclude', $id1 );
    205         $response = $this->server->dispatch( $request );
     205        $response = rest_get_server()->dispatch( $request );
    206206        $data     = $response->get_data();
    207207        $this->assertEquals( 1, count( $data ) );
     
    209209        // Invalid parent_exclude should error
    210210        $request->set_param( 'parent_exclude', 'some-slug' );
    211         $response = $this->server->dispatch( $request );
     211        $response = rest_get_server()->dispatch( $request );
    212212        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    213213    }
     
    243243        // No parent
    244244        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    245         $response = $this->server->dispatch( $request );
     245        $response = rest_get_server()->dispatch( $request );
    246246        $data     = $response->get_data();
    247247        $this->assertEqualSets( array( $id1, $id2, $id3, $id4 ), wp_list_pluck( $data, 'id' ) );
    248248        // Filter to menu_order
    249249        $request->set_param( 'menu_order', 1 );
    250         $response = $this->server->dispatch( $request );
     250        $response = rest_get_server()->dispatch( $request );
    251251        $data     = $response->get_data();
    252252        $this->assertEqualSets( array( $id4 ), wp_list_pluck( $data, 'id' ) );
     
    255255        $request->set_param( 'order', 'asc' );
    256256        $request->set_param( 'orderby', 'menu_order' );
    257         $response = $this->server->dispatch( $request );
     257        $response = rest_get_server()->dispatch( $request );
    258258        $data     = $response->get_data();
    259259        $this->assertEquals( $id1, $data[0]['id'] );
     
    264264        $request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    265265        $request->set_param( 'menu_order', 'top-first' );
    266         $response = $this->server->dispatch( $request );
     266        $response = rest_get_server()->dispatch( $request );
    267267        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    268268    }
     
    271271        $request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    272272        $request->set_param( 'per_page', 0 );
    273         $response = $this->server->dispatch( $request );
     273        $response = rest_get_server()->dispatch( $request );
    274274        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    275275        $data = $response->get_data();
     
    278278        $this->assertContains( 'per_page must be between 1 (inclusive) and 100 (inclusive)', $first_error );
    279279        $request->set_param( 'per_page', 101 );
    280         $response = $this->server->dispatch( $request );
     280        $response = rest_get_server()->dispatch( $request );
    281281        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    282282        $data        = $response->get_data();
     
    302302        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages' );
    303303        $request->set_param( 'status', 'draft' );
    304         $response = $this->server->dispatch( $request );
     304        $response = rest_get_server()->dispatch( $request );
    305305        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    306306
    307307        // But they are accessible to authorized users
    308308        wp_set_current_user( self::$editor_id );
    309         $response = $this->server->dispatch( $request );
     309        $response = rest_get_server()->dispatch( $request );
    310310        $data     = $response->get_data();
    311311        $this->assertCount( 1, $data );
     
    317317        $request->set_param( 'after', rand_str() );
    318318        $request->set_param( 'before', rand_str() );
    319         $response = $this->server->dispatch( $request );
     319        $response = rest_get_server()->dispatch( $request );
    320320        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    321321    }
     
    343343        $request->set_param( 'after', '2016-01-15T00:00:00Z' );
    344344        $request->set_param( 'before', '2016-01-17T00:00:00Z' );
    345         $response = $this->server->dispatch( $request );
     345        $response = rest_get_server()->dispatch( $request );
    346346        $data     = $response->get_data();
    347347        $this->assertCount( 1, $data );
     
    356356        $post_id  = $this->factory->post->create();
    357357        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages/' . $post_id );
    358         $response = $this->server->dispatch( $request );
     358        $response = rest_get_server()->dispatch( $request );
    359359        $this->assertEquals( 404, $response->get_status() );
    360360    }
     
    374374        );
    375375        $request->set_body_params( $params );
    376         $response = $this->server->dispatch( $request );
     376        $response = rest_get_server()->dispatch( $request );
    377377
    378378        $data     = $response->get_data();
     
    397397        );
    398398        $request->set_body_params( $params );
    399         $response = $this->server->dispatch( $request );
     399        $response = rest_get_server()->dispatch( $request );
    400400
    401401        $this->assertEquals( 201, $response->get_status() );
     
    420420        );
    421421        $request->set_body_params( $params );
    422         $response = $this->server->dispatch( $request );
     422        $response = rest_get_server()->dispatch( $request );
    423423
    424424        $this->assertErrorResponse( 'rest_post_invalid_id', $response, 400 );
     
    440440        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/pages/%d', $page_id ) );
    441441        $request->set_param( 'force', 'false' );
    442         $response = $this->server->dispatch( $request );
     442        $response = rest_get_server()->dispatch( $request );
    443443
    444444        $this->assertEquals( 200, $response->get_status() );
     
    466466            )
    467467        );
    468         $response = $this->server->dispatch( $request );
     468        $response = rest_get_server()->dispatch( $request );
    469469
    470470        $this->assertEquals( 200, $response->get_status() );
     
    498498            )
    499499        );
    500         $response = $this->server->dispatch( $request );
     500        $response = rest_get_server()->dispatch( $request );
    501501
    502502        $new_data = $response->get_data();
     
    522522            )
    523523        );
    524         $response = $this->server->dispatch( $request );
     524        $response = rest_get_server()->dispatch( $request );
    525525
    526526        $new_data = $response->get_data();
     
    546546            )
    547547        );
    548         $response = $this->server->dispatch( $request );
     548        $response = rest_get_server()->dispatch( $request );
    549549        $new_data = $response->get_data();
    550550        $this->assertEquals( $page_id1, $new_data['parent'] );
     
    570570            )
    571571        );
    572         $response = $this->server->dispatch( $request );
     572        $response = rest_get_server()->dispatch( $request );
    573573        $new_data = $response->get_data();
    574574        $this->assertEquals( 0, $new_data['parent'] );
     
    584584
    585585        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
    586         $response = $this->server->dispatch( $request );
     586        $response = rest_get_server()->dispatch( $request );
    587587
    588588        $data = $response->get_data();
     
    606606        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
    607607        $request->set_param( 'password', '$inthebananastand' );
    608         $response = $this->server->dispatch( $request );
     608        $response = rest_get_server()->dispatch( $request );
    609609
    610610        $data = $response->get_data();
     
    626626        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
    627627        $request->set_param( 'password', 'wrongpassword' );
    628         $response = $this->server->dispatch( $request );
     628        $response = rest_get_server()->dispatch( $request );
    629629
    630630        $this->assertErrorResponse( 'rest_post_incorrect_password', $response, 403 );
     
    641641        );
    642642        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
    643         $response = $this->server->dispatch( $request );
     643        $response = rest_get_server()->dispatch( $request );
    644644        $data     = $response->get_data();
    645645        $this->assertEquals( '', $data['content']['rendered'] );
     
    651651    public function test_get_item_schema() {
    652652        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' );
    653         $response   = $this->server->dispatch( $request );
     653        $response   = rest_get_server()->dispatch( $request );
    654654        $data       = $response->get_data();
    655655        $properties = $data['schema']['properties'];
  • trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php

    r42343 r42724  
    123123        /** @var WP_REST_Server $wp_rest_server */
    124124        global $wp_rest_server;
    125         $this->server = $wp_rest_server = new Spy_REST_Server;
    126         do_action( 'rest_api_init' );
     125        $wp_rest_server = new Spy_REST_Server;
     126        do_action( 'rest_api_init', $wp_rest_server );
    127127    }
    128128
     
    141141
    142142        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    143         $response = $this->server->dispatch( $request );
     143        $response = rest_get_server()->dispatch( $request );
    144144
    145145        $this->assertEquals( 200, $response->get_status() );
     
    160160        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    161161
    162         $response = $this->server->dispatch( $request );
     162        $response = rest_get_server()->dispatch( $request );
    163163        $this->assertEquals( 200, $response->get_status() );
    164164
     
    172172        add_post_meta( self::$post_id, 'test_multi', 'value2' );
    173173
    174         $response = $this->server->dispatch( $request );
     174        $response = rest_get_server()->dispatch( $request );
    175175        $this->assertEquals( 200, $response->get_status() );
    176176        $data = $response->get_data();
     
    187187        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    188188
    189         $response = $this->server->dispatch( $request );
     189        $response = rest_get_server()->dispatch( $request );
    190190        $this->assertEquals( 200, $response->get_status() );
    191191
     
    202202        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    203203
    204         $response = $this->server->dispatch( $request );
     204        $response = rest_get_server()->dispatch( $request );
    205205        $this->assertEquals( 200, $response->get_status() );
    206206
     
    217217        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    218218
    219         $response = $this->server->dispatch( $request );
     219        $response = rest_get_server()->dispatch( $request );
    220220        $this->assertEquals( 200, $response->get_status() );
    221221
     
    250250        /** @var WP_REST_Server $wp_rest_server */
    251251        global $wp_rest_server;
    252         $this->server = $wp_rest_server = new Spy_REST_Server;
    253         do_action( 'rest_api_init' );
     252        $wp_rest_server = new Spy_REST_Server;
     253        do_action( 'rest_api_init', $wp_rest_server );
    254254
    255255        add_post_meta( self::$post_id, 'test_string', 42 );
     
    258258
    259259        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    260         $response = $this->server->dispatch( $request );
     260        $response = rest_get_server()->dispatch( $request );
    261261        $this->assertEquals( 200, $response->get_status() );
    262262
     
    281281
    282282        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    283         $response = $this->server->dispatch( $request );
     283        $response = rest_get_server()->dispatch( $request );
    284284
    285285        $this->assertEquals( 200, $response->get_status() );
     
    311311        $request->set_body_params( $data );
    312312
    313         $response = $this->server->dispatch( $request );
     313        $response = rest_get_server()->dispatch( $request );
    314314        $this->assertEquals( 200, $response->get_status() );
    315315
     
    343343        $request->set_body_params( $data );
    344344
    345         $response = $this->server->dispatch( $request );
     345        $response = rest_get_server()->dispatch( $request );
    346346        $this->assertEquals( 200, $response->get_status() );
    347347
     
    371371        $request->set_body_params( $data );
    372372
    373         $response = $this->server->dispatch( $request );
     373        $response = rest_get_server()->dispatch( $request );
    374374        $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 );
    375375
     
    393393        $request->set_body_params( $data );
    394394
    395         $response = $this->server->dispatch( $request );
     395        $response = rest_get_server()->dispatch( $request );
    396396        $this->assertErrorResponse( 'rest_cannot_update', $response, 403 );
    397397        $this->assertEmpty( get_post_meta( self::$post_id, 'test_bad_auth', false ) );
     
    421421        add_filter( 'query', array( $this, 'error_insert_query' ) );
    422422
    423         $response = $this->server->dispatch( $request );
     423        $response = rest_get_server()->dispatch( $request );
    424424        remove_filter( 'query', array( $this, 'error_insert_query' ) );
    425425        $wpdb->show_errors = true;
     
    442442        $request->set_body_params( $data );
    443443
    444         $response = $this->server->dispatch( $request );
     444        $response = rest_get_server()->dispatch( $request );
    445445        $this->assertEmpty( get_post_meta( self::$post_id, 'test_invalid_type', false ) );
    446446    }
     
    461461        $request->set_body_params( $data );
    462462
    463         $response = $this->server->dispatch( $request );
     463        $response = rest_get_server()->dispatch( $request );
    464464        $this->assertEquals( 200, $response->get_status() );
    465465
     
    477477        $request->set_body_params( $data );
    478478
    479         $response = $this->server->dispatch( $request );
     479        $response = rest_get_server()->dispatch( $request );
    480480        $this->assertEquals( 200, $response->get_status() );
    481481
     
    505505        $request->set_body_params( $data );
    506506
    507         $response = $this->server->dispatch( $request );
     507        $response = rest_get_server()->dispatch( $request );
    508508        $this->assertEquals( 200, $response->get_status() );
    509509
     
    533533        $request->set_body_params( $data );
    534534
    535         $response = $this->server->dispatch( $request );
     535        $response = rest_get_server()->dispatch( $request );
    536536        $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 );
    537537
     
    559559        $request->set_body_params( $data );
    560560
    561         $response = $this->server->dispatch( $request );
     561        $response = rest_get_server()->dispatch( $request );
    562562        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    563563    }
     
    582582        $request->set_body_params( $data );
    583583
    584         $response = $this->server->dispatch( $request );
     584        $response = rest_get_server()->dispatch( $request );
    585585        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    586586    }
     
    605605        $request->set_body_params( $data );
    606606
    607         $response = $this->server->dispatch( $request );
     607        $response = rest_get_server()->dispatch( $request );
    608608        $data     = $response->get_data();
    609609        $this->assertEquals( 1, $data['meta']['my_meta_key'] );
     
    629629        $request->set_body_params( $data );
    630630
    631         $response = $this->server->dispatch( $request );
     631        $response = rest_get_server()->dispatch( $request );
    632632        $data     = $response->get_data();
    633633        $this->assertEquals( array( 1, 2, 3 ), $data['meta']['my_meta_key'] );
     
    649649        $request->set_body_params( $data );
    650650
    651         $response = $this->server->dispatch( $request );
     651        $response = rest_get_server()->dispatch( $request );
    652652        $this->assertErrorResponse( 'rest_cannot_update', $response, 403 );
    653653        $this->assertEmpty( get_post_meta( self::$post_id, 'test_bad_auth_multi', false ) );
     
    677677        add_filter( 'query', array( $this, 'error_insert_query' ) );
    678678
    679         $response = $this->server->dispatch( $request );
     679        $response = rest_get_server()->dispatch( $request );
    680680        remove_filter( 'query', array( $this, 'error_insert_query' ) );
    681681        $wpdb->show_errors = true;
     
    702702        $request->set_body_params( $data );
    703703
    704         $response = $this->server->dispatch( $request );
     704        $response = rest_get_server()->dispatch( $request );
    705705        $this->assertEquals( 200, $response->get_status() );
    706706
     
    731731        $request->set_body_params( $data );
    732732
    733         $response = $this->server->dispatch( $request );
     733        $response = rest_get_server()->dispatch( $request );
    734734        $this->assertEquals( 200, $response->get_status() );
    735735
     
    747747        $request->set_body_params( $data );
    748748
    749         $response = $this->server->dispatch( $request );
     749        $response = rest_get_server()->dispatch( $request );
    750750        $this->assertEquals( 200, $response->get_status() );
    751751
     
    775775        $request->set_body_params( $data );
    776776
    777         $response = $this->server->dispatch( $request );
     777        $response = rest_get_server()->dispatch( $request );
    778778        $this->assertEquals( 200, $response->get_status() );
    779779
     
    804804        $request->set_body_params( $data );
    805805
    806         $response = $this->server->dispatch( $request );
     806        $response = rest_get_server()->dispatch( $request );
    807807        $this->assertEquals( 200, $response->get_status() );
    808808
     
    820820        $request->set_body_params( $data );
    821821
    822         $response = $this->server->dispatch( $request );
     822        $response = rest_get_server()->dispatch( $request );
    823823        $this->assertEquals( 200, $response->get_status() );
    824824
     
    847847        $request->set_body_params( $data );
    848848
    849         $response = $this->server->dispatch( $request );
     849        $response = rest_get_server()->dispatch( $request );
    850850
    851851        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    877877        $request->set_body_params( $data );
    878878
    879         $response = $this->server->dispatch( $request );
     879        $response = rest_get_server()->dispatch( $request );
    880880        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    881881
     
    912912        add_filter( 'query', array( $this, 'error_delete_query' ) );
    913913
    914         $response = $this->server->dispatch( $request );
     914        $response = rest_get_server()->dispatch( $request );
    915915        remove_filter( 'query', array( $this, 'error_delete_query' ) );
    916916        $wpdb->show_errors = true;
     
    935935        $request->set_body_params( $data );
    936936
    937         $response = $this->server->dispatch( $request );
     937        $response = rest_get_server()->dispatch( $request );
    938938        $this->assertEquals( 200, $response->get_status() );
    939939
     
    960960        $request->set_body_params( $data );
    961961
    962         $response = $this->server->dispatch( $request );
     962        $response = rest_get_server()->dispatch( $request );
    963963        $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
    964964
     
    992992        add_filter( 'query', array( $this, 'error_delete_query' ) );
    993993
    994         $response = $this->server->dispatch( $request );
     994        $response = rest_get_server()->dispatch( $request );
    995995        remove_filter( 'query', array( $this, 'error_delete_query' ) );
    996996        $wpdb->show_errors = true;
     
    10141014        $request->set_body_params( $data );
    10151015
    1016         $response = $this->server->dispatch( $request );
     1016        $response = rest_get_server()->dispatch( $request );
    10171017        $this->assertEquals( 200, $response->get_status() );
    10181018
     
    10231023    public function test_get_schema() {
    10241024        $request  = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1025         $response = $this->server->dispatch( $request );
     1025        $response = rest_get_server()->dispatch( $request );
    10261026
    10271027        $data   = $response->get_data();
  • trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php

    r42343 r42724  
    1313
    1414    public function test_register_routes() {
    15         $routes = $this->server->get_routes();
     15        $routes = rest_get_server()->get_routes();
    1616        $this->assertArrayHasKey( '/wp/v2/statuses', $routes );
    1717        $this->assertArrayHasKey( '/wp/v2/statuses/(?P<status>[\w-]+)', $routes );
     
    2121        // Collection
    2222        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
    23         $response = $this->server->dispatch( $request );
     23        $response = rest_get_server()->dispatch( $request );
    2424        $data     = $response->get_data();
    2525        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    2727        // Single
    2828        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses/publish' );
    29         $response = $this->server->dispatch( $request );
     29        $response = rest_get_server()->dispatch( $request );
    3030        $data     = $response->get_data();
    3131        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    3535    public function test_get_items() {
    3636        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses' );
    37         $response = $this->server->dispatch( $request );
     37        $response = rest_get_server()->dispatch( $request );
    3838
    3939        $data     = $response->get_data();
     
    4848
    4949        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses' );
    50         $response = $this->server->dispatch( $request );
     50        $response = rest_get_server()->dispatch( $request );
    5151
    5252        $data = $response->get_data();
     
    6767        $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' );
    6868        $request->set_param( 'context', 'edit' );
    69         $response = $this->server->dispatch( $request );
     69        $response = rest_get_server()->dispatch( $request );
    7070        $this->assertErrorResponse( 'rest_cannot_view', $response, 401 );
    7171    }
     
    7676        $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/publish' );
    7777        $request->set_param( 'context', 'edit' );
    78         $response = $this->server->dispatch( $request );
     78        $response = rest_get_server()->dispatch( $request );
    7979        $this->check_post_status_object_response( $response );
    8080    }
     
    8282    public function test_get_item_invalid_status() {
    8383        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses/invalid' );
    84         $response = $this->server->dispatch( $request );
     84        $response = rest_get_server()->dispatch( $request );
    8585        $this->assertErrorResponse( 'rest_status_invalid', $response, 404 );
    8686    }
     
    8989        wp_set_current_user( 0 );
    9090        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses/draft' );
    91         $response = $this->server->dispatch( $request );
     91        $response = rest_get_server()->dispatch( $request );
    9292        $this->assertErrorResponse( 'rest_cannot_read_status', $response, 401 );
    9393    }
     
    9898
    9999        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses/inherit' );
    100         $response = $this->server->dispatch( $request );
     100        $response = rest_get_server()->dispatch( $request );
    101101        $this->assertErrorResponse( 'rest_cannot_read_status', $response, 403 );
    102102    }
     
    105105        /** Post statuses can't be created */
    106106        $request  = new WP_REST_Request( 'POST', '/wp/v2/statuses' );
    107         $response = $this->server->dispatch( $request );
     107        $response = rest_get_server()->dispatch( $request );
    108108        $this->assertEquals( 404, $response->get_status() );
    109109    }
     
    112112        /** Post statuses can't be updated */
    113113        $request  = new WP_REST_Request( 'POST', '/wp/v2/statuses/draft' );
    114         $response = $this->server->dispatch( $request );
     114        $response = rest_get_server()->dispatch( $request );
    115115        $this->assertEquals( 404, $response->get_status() );
    116116    }
     
    119119        /** Post statuses can't be deleted */
    120120        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/statuses/draft' );
    121         $response = $this->server->dispatch( $request );
     121        $response = rest_get_server()->dispatch( $request );
    122122        $this->assertEquals( 404, $response->get_status() );
    123123    }
     
    134134    public function test_get_item_schema() {
    135135        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
    136         $response   = $this->server->dispatch( $request );
     136        $response   = rest_get_server()->dispatch( $request );
    137137        $data       = $response->get_data();
    138138        $properties = $data['schema']['properties'];
     
    166166        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
    167167
    168         $response = $this->server->dispatch( $request );
     168        $response = rest_get_server()->dispatch( $request );
    169169        $data     = $response->get_data();
    170170
     
    174174        $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/publish' );
    175175
    176         $response = $this->server->dispatch( $request );
     176        $response = rest_get_server()->dispatch( $request );
    177177        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    178178
  • trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php

    r42343 r42724  
    1313
    1414    public function test_register_routes() {
    15         $routes = $this->server->get_routes();
     15        $routes = rest_get_server()->get_routes();
    1616        $this->assertArrayHasKey( '/wp/v2/types', $routes );
    1717        $this->assertArrayHasKey( '/wp/v2/types/(?P<type>[\w-]+)', $routes );
     
    2121        // Collection
    2222        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' );
    23         $response = $this->server->dispatch( $request );
     23        $response = rest_get_server()->dispatch( $request );
    2424        $data     = $response->get_data();
    2525        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    2727        // Single
    2828        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/post' );
    29         $response = $this->server->dispatch( $request );
     29        $response = rest_get_server()->dispatch( $request );
    3030        $data     = $response->get_data();
    3131        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    3535    public function test_get_items() {
    3636        $request  = new WP_REST_Request( 'GET', '/wp/v2/types' );
    37         $response = $this->server->dispatch( $request );
     37        $response = rest_get_server()->dispatch( $request );
    3838
    3939        $data       = $response->get_data();
     
    5151        $request = new WP_REST_Request( 'GET', '/wp/v2/types' );
    5252        $request->set_param( 'context', 'edit' );
    53         $response = $this->server->dispatch( $request );
     53        $response = rest_get_server()->dispatch( $request );
    5454        $this->assertErrorResponse( 'rest_cannot_view', $response, 401 );
    5555    }
     
    5757    public function test_get_item() {
    5858        $request  = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    59         $response = $this->server->dispatch( $request );
     59        $response = rest_get_server()->dispatch( $request );
    6060        $this->check_post_type_object_response( 'view', $response );
    6161        $data = $response->get_data();
     
    6565    public function test_get_item_page() {
    6666        $request  = new WP_REST_Request( 'GET', '/wp/v2/types/page' );
    67         $response = $this->server->dispatch( $request );
     67        $response = rest_get_server()->dispatch( $request );
    6868        $this->check_post_type_object_response( 'view', $response, 'page' );
    6969        $data = $response->get_data();
     
    7373    public function test_get_item_invalid_type() {
    7474        $request  = new WP_REST_Request( 'GET', '/wp/v2/types/invalid' );
    75         $response = $this->server->dispatch( $request );
     75        $response = rest_get_server()->dispatch( $request );
    7676        $this->assertErrorResponse( 'rest_type_invalid', $response, 404 );
    7777    }
     
    8282        $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    8383        $request->set_param( 'context', 'edit' );
    84         $response = $this->server->dispatch( $request );
     84        $response = rest_get_server()->dispatch( $request );
    8585        $this->check_post_type_object_response( 'edit', $response );
    8686    }
     
    9090        $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    9191        $request->set_param( 'context', 'edit' );
    92         $response = $this->server->dispatch( $request );
     92        $response = rest_get_server()->dispatch( $request );
    9393        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    9494    }
     
    9797        /** Post types can't be created */
    9898        $request  = new WP_REST_Request( 'POST', '/wp/v2/types' );
    99         $response = $this->server->dispatch( $request );
     99        $response = rest_get_server()->dispatch( $request );
    100100        $this->assertEquals( 404, $response->get_status() );
    101101    }
     
    104104        /** Post types can't be updated */
    105105        $request  = new WP_REST_Request( 'POST', '/wp/v2/types/post' );
    106         $response = $this->server->dispatch( $request );
     106        $response = rest_get_server()->dispatch( $request );
    107107        $this->assertEquals( 404, $response->get_status() );
    108108    }
     
    111111        /** Post types can't be deleted */
    112112        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/types/post' );
    113         $response = $this->server->dispatch( $request );
     113        $response = rest_get_server()->dispatch( $request );
    114114        $this->assertEquals( 404, $response->get_status() );
    115115    }
     
    126126    public function test_get_item_schema() {
    127127        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' );
    128         $response   = $this->server->dispatch( $request );
     128        $response   = rest_get_server()->dispatch( $request );
    129129        $data       = $response->get_data();
    130130        $properties = $data['schema']['properties'];
     
    160160        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/schema' );
    161161
    162         $response = $this->server->dispatch( $request );
     162        $response = rest_get_server()->dispatch( $request );
    163163        $data     = $response->get_data();
    164164
     
    168168        $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    169169
    170         $response = $this->server->dispatch( $request );
     170        $response = rest_get_server()->dispatch( $request );
    171171        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    172172
  • 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