Make WordPress Core

Changeset 42724


Ignore:
Timestamp:
02/21/2018 04:24:30 PM (8 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                 $response = $this->server->dispatch( $request );
     1818                $response = rest_get_server()->dispatch( $request );
    18191819
    18201820                $data     = $response->get_data();
     
    18401840                );
    18411841                $request->set_body_params( $params );
    1842                 $response = $this->server->dispatch( $request );
     1842                $response = rest_get_server()->dispatch( $request );
    18431843
    18441844                $data     = $response->get_data();
     
    18641864                );
    18651865                $request->set_body_params( $params );
    1866                 $response = $this->server->dispatch( $request );
     1866                $response = rest_get_server()->dispatch( $request );
    18671867
    18681868                $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 );
     
    18841884                );
    18851885                $request->set_body_params( $params );
    1886                 $response = $this->server->dispatch( $request );
     1886                $response = rest_get_server()->dispatch( $request );
    18871887
    18881888                $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 );
     
    18991899                );
    19001900                $request->set_body_params( $params );
    1901                 $response = $this->server->dispatch( $request );
     1901                $response = rest_get_server()->dispatch( $request );
    19021902
    19031903                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    19141914                );
    19151915                $request->set_body_params( $params );
    1916                 $response = $this->server->dispatch( $request );
     1916                $response = rest_get_server()->dispatch( $request );
    19171917
    19181918                $data     = $response->get_data();
     
    19321932                );
    19331933                $request->set_body_params( $params );
    1934                 $response = $this->server->dispatch( $request );
     1934                $response = rest_get_server()->dispatch( $request );
    19351935
    19361936                $data     = $response->get_data();
     
    19501950                );
    19511951                $request->set_body_params( $params );
    1952                 $response = $this->server->dispatch( $request );
     1952                $response = rest_get_server()->dispatch( $request );
    19531953
    19541954                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    19701970                );
    19711971                $request->set_body_params( $params );
    1972                 $response = $this->server->dispatch( $request );
     1972                $response = rest_get_server()->dispatch( $request );
    19731973                $this->assertEquals( 201, $response->get_status() );
    19741974
     
    19961996                );
    19971997                $request->set_body_params( $params );
    1998                 $response = $this->server->dispatch( $request );
     1998                $response = rest_get_server()->dispatch( $request );
    19991999                $data     = $response->get_data();
    20002000                $new_post = get_post( $data['id'] );
     
    20092009                );
    20102010                $request->set_body_params( $params );
    2011                 $response = $this->server->dispatch( $request );
     2011                $response = rest_get_server()->dispatch( $request );
    20122012                $data     = $response->get_data();
    20132013                $this->assertEquals( 0, $data['featured_media'] );
     
    20252025                );
    20262026                $request->set_body_params( $params );
    2027                 $response = $this->server->dispatch( $request );
     2027                $response = rest_get_server()->dispatch( $request );
    20282028
    20292029                $this->assertErrorResponse( 'rest_invalid_author', $response, 400 );
     
    20402040                );
    20412041                $request->set_body_params( $params );
    2042                 $response = $this->server->dispatch( $request );
     2042                $response = rest_get_server()->dispatch( $request );
    20432043
    20442044                $this->assertErrorResponse( 'rest_cannot_edit_others', $response, 403 );
     
    20552055                );
    20562056                $request->set_body_params( $params );
    2057                 $response = $this->server->dispatch( $request );
     2057                $response = rest_get_server()->dispatch( $request );
    20582058
    20592059                $data = $response->get_data();
     
    20712071                );
    20722072                $request->set_body_params( $params );
    2073                 $response = $this->server->dispatch( $request );
     2073                $response = rest_get_server()->dispatch( $request );
    20742074
    20752075                $data = $response->get_data();
     
    20892089                );
    20902090                $request->set_body_params( $params );
    2091                 $response = $this->server->dispatch( $request );
     2091                $response = rest_get_server()->dispatch( $request );
    20922092
    20932093                $this->assertEquals( 201, $response->get_status() );
     
    21072107                );
    21082108                $request->set_body_params( $params );
    2109                 $response = $this->server->dispatch( $request );
     2109                $response = rest_get_server()->dispatch( $request );
    21102110
    21112111                $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    21222122                );
    21232123                $request->set_body_params( $params );
    2124                 $response = $this->server->dispatch( $request );
     2124                $response = rest_get_server()->dispatch( $request );
    21252125
    21262126                $data     = $response->get_data();
     
    21412141                );
    21422142                $request->set_body_params( $params );
    2143                 $response = $this->server->dispatch( $request );
     2143                $response = rest_get_server()->dispatch( $request );
    21442144
    21452145                $data     = $response->get_data();
     
    21692169                add_filter( 'query', array( $this, 'error_insert_query' ) );
    21702170
    2171                 $response = $this->server->dispatch( $request );
     2171                $response = rest_get_server()->dispatch( $request );
    21722172                remove_filter( 'query', array( $this, 'error_insert_query' ) );
    21732173                $wpdb->show_errors = true;
     
    21862186                );
    21872187                $request->set_body_params( $params );
    2188                 $response = $this->server->dispatch( $request );
     2188                $response = rest_get_server()->dispatch( $request );
    21892189
    21902190                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    22012201                );
    22022202                $request->set_body_params( $params );
    2203                 $response = $this->server->dispatch( $request );
     2203                $response = rest_get_server()->dispatch( $request );
    22042204
    22052205                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    22162216                );
    22172217                $request->set_body_params( $params );
    2218                 $response = $this->server->dispatch( $request );
     2218                $response = rest_get_server()->dispatch( $request );
    22192219                $new_data = $response->get_data();
    22202220                $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] );
     
    22342234                );
    22352235                $request->set_body_params( $params );
    2236                 $response = $this->server->dispatch( $request );
     2236                $response = rest_get_server()->dispatch( $request );
    22372237
    22382238                $data = $response->get_data();
     
    22512251                );
    22522252                $request->set_body_params( $params );
    2253                 $response = $this->server->dispatch( $request );
     2253                $response = rest_get_server()->dispatch( $request );
    22542254
    22552255                $data = $response->get_data();
     
    22692269                );
    22702270                $request->set_body_params( $params );
    2271                 $response = $this->server->dispatch( $request );
     2271                $response = rest_get_server()->dispatch( $request );
    22722272
    22732273                $data = $response->get_data();
     
    22932293
    22942294                add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    2295                 $response = $this->server->dispatch( $request );
     2295                $response = rest_get_server()->dispatch( $request );
    22962296                remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    22972297
     
    23132313                $params = $this->set_post_data();
    23142314                $request->set_body_params( $params );
    2315                 $response = $this->server->dispatch( $request );
     2315                $response = rest_get_server()->dispatch( $request );
    23162316
    23172317                $this->check_update_post_response( $response );
     
    23362336                // Run twice to make sure that the update still succeeds even if no DB
    23372337                // rows are updated.
    2338                 $response = $this->server->dispatch( $request );
     2338                $response = rest_get_server()->dispatch( $request );
    23392339                $this->check_update_post_response( $response );
    23402340
    2341                 $response = $this->server->dispatch( $request );
     2341                $response = rest_get_server()->dispatch( $request );
    23422342                $this->check_update_post_response( $response );
    23432343        }
     
    23502350                $params = $this->set_post_data();
    23512351                $request->set_body( wp_json_encode( $params ) );
    2352                 $response = $this->server->dispatch( $request );
     2352                $response = rest_get_server()->dispatch( $request );
    23532353
    23542354                $this->check_update_post_response( $response );
     
    23712371                $params = $this->set_raw_post_data();
    23722372                $request->set_body( wp_json_encode( $params ) );
    2373                 $response = $this->server->dispatch( $request );
     2373                $response = rest_get_server()->dispatch( $request );
    23742374
    23752375                $this->check_update_post_response( $response );
     
    23952395                unset( $params['status'] );
    23962396                $request->set_body_params( $params );
    2397                 $response = $this->server->dispatch( $request );
     2397                $response = rest_get_server()->dispatch( $request );
    23982398
    23992399                $this->check_update_post_response( $response );
     
    24112411                $params  = $this->set_post_data();
    24122412                $request->set_body_params( $params );
    2413                 $response = $this->server->dispatch( $request );
     2413                $response = rest_get_server()->dispatch( $request );
    24142414
    24152415                $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
     
    24272427                );
    24282428                $request->set_body_params( $params );
    2429                 $response = $this->server->dispatch( $request );
     2429                $response = rest_get_server()->dispatch( $request );
    24302430
    24312431                $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
     
    24362436
    24372437                $request  = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
    2438                 $response = $this->server->dispatch( $request );
     2438                $response = rest_get_server()->dispatch( $request );
    24392439
    24402440                $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    24452445
    24462446                $request  = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) );
    2447                 $response = $this->server->dispatch( $request );
     2447                $response = rest_get_server()->dispatch( $request );
    24482448
    24492449                $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    24602460                );
    24612461                $request->set_body_params( $params );
    2462                 $response = $this->server->dispatch( $request );
     2462                $response = rest_get_server()->dispatch( $request );
    24632463
    24642464                $data     = $response->get_data();
     
    24782478                );
    24792479                $request->set_body_params( $params );
    2480                 $response = $this->server->dispatch( $request );
     2480                $response = rest_get_server()->dispatch( $request );
    24812481
    24822482                $data     = $response->get_data();
     
    24962496                );
    24972497                $request->set_body_params( $params );
    2498                 $response = $this->server->dispatch( $request );
     2498                $response = rest_get_server()->dispatch( $request );
    24992499
    25002500                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    25162516                );
    25172517                $request->set_body_params( $params );
    2518                 $response = $this->server->dispatch( $request );
     2518                $response = rest_get_server()->dispatch( $request );
    25192519                $this->assertEquals( 200, $response->get_status() );
    25202520
     
    25372537                );
    25382538                $request->set_body_params( $params );
    2539                 $response = $this->server->dispatch( $request );
     2539                $response = rest_get_server()->dispatch( $request );
    25402540
    25412541                // The readonly modified param should be ignored, request should be a success.
     
    25672567                        $request->set_param( 'date_gmt', $params['date_gmt'] );
    25682568                }
    2569                 $response = $this->server->dispatch( $request );
     2569                $response = rest_get_server()->dispatch( $request );
    25702570
    25712571                update_option( 'timezone_string', '' );
     
    25942594                );
    25952595                $request->set_body_params( $params );
    2596                 $response = $this->server->dispatch( $request );
     2596                $response = rest_get_server()->dispatch( $request );
    25972597
    25982598                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    26092609                );
    26102610                $request->set_body_params( $params );
    2611                 $response = $this->server->dispatch( $request );
     2611                $response = rest_get_server()->dispatch( $request );
    26122612
    26132613                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    26422642
    26432643                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    2644                 $response = $this->server->dispatch( $request );
     2644                $response = rest_get_server()->dispatch( $request );
    26452645                $this->assertEquals( 200, $response->get_status() );
    26462646                $data = $response->get_data();
     
    26512651                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) );
    26522652                $request->set_param( 'date', '2016-02-23T13:00:00' );
    2653                 $response = $this->server->dispatch( $request );
     2653                $response = rest_get_server()->dispatch( $request );
    26542654                $this->assertEquals( 200, $response->get_status() );
    26552655                $data = $response->get_data();
     
    26752675                );
    26762676                $request->set_body_params( $params );
    2677                 $response = $this->server->dispatch( $request );
     2677                $response = rest_get_server()->dispatch( $request );
    26782678
    26792679                $new_data = $response->get_data();
     
    26932693                );
    26942694                $request->set_body_params( $params );
    2695                 $response = $this->server->dispatch( $request );
     2695                $response = rest_get_server()->dispatch( $request );
    26962696
    26972697                $new_data = $response->get_data();
     
    27112711                );
    27122712                $request->set_body_params( $params );
    2713                 $response = $this->server->dispatch( $request );
     2713                $response = rest_get_server()->dispatch( $request );
    27142714
    27152715                $new_data = $response->get_data();
     
    27262726                );
    27272727                $request->set_body_params( $params );
    2728                 $response = $this->server->dispatch( $request );
     2728                $response = rest_get_server()->dispatch( $request );
    27292729
    27302730                $new_data = $response->get_data();
     
    27442744                );
    27452745
    2746                 $response = $this->server->dispatch( $request );
     2746                $response = rest_get_server()->dispatch( $request );
    27472747                $new_data = $response->get_data();
    27482748                $this->assertEquals( 'An Excerpt', $new_data['excerpt']['raw'] );
     
    27592759                );
    27602760
    2761                 $response = $this->server->dispatch( $request );
     2761                $response = rest_get_server()->dispatch( $request );
    27622762                $new_data = $response->get_data();
    27632763                $this->assertEquals( '', $new_data['excerpt']['raw'] );
     
    27742774                );
    27752775
    2776                 $response = $this->server->dispatch( $request );
     2776                $response = rest_get_server()->dispatch( $request );
    27772777                $new_data = $response->get_data();
    27782778                $this->assertEquals( 'Some Content', $new_data['content']['raw'] );
     
    27892789                );
    27902790
    2791                 $response = $this->server->dispatch( $request );
     2791                $response = rest_get_server()->dispatch( $request );
    27922792                $new_data = $response->get_data();
    27932793                $this->assertEquals( '', $new_data['content']['raw'] );
     
    28102810                );
    28112811                $request->set_body_params( $params );
    2812                 $response = $this->server->dispatch( $request );
     2812                $response = rest_get_server()->dispatch( $request );
    28132813                $data     = $response->get_data();
    28142814                $this->assertEquals( '', $data['password'] );
     
    28262826                );
    28272827                $request->set_body_params( $params );
    2828                 $response = $this->server->dispatch( $request );
     2828                $response = rest_get_server()->dispatch( $request );
    28292829
    28302830                $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    28432843                );
    28442844                $request->set_body_params( $params );
    2845                 $response = $this->server->dispatch( $request );
     2845                $response = rest_get_server()->dispatch( $request );
    28462846
    28472847                $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    28652865                );
    28662866                $request->set_body_params( $params );
    2867                 $response = $this->server->dispatch( $request );
     2867                $response = rest_get_server()->dispatch( $request );
    28682868
    28692869                $this->assertErrorResponse( 'rest_invalid_field', $response, 400 );
     
    28802880                );
    28812881                $request->set_body_params( $params );
    2882                 $response = $this->server->dispatch( $request );
     2882                $response = rest_get_server()->dispatch( $request );
    28832883                $new_data = $response->get_data();
    28842884                $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] );
     
    29002900                );
    29012901                $request->set_body_params( $params );
    2902                 $response = $this->server->dispatch( $request );
     2902                $response = rest_get_server()->dispatch( $request );
    29032903                $new_data = $response->get_data();
    29042904                $this->assertEquals( array( $category['term_id'] ), $new_data['categories'] );
     
    29152915                unset( $args['rest_route'] );
    29162916                $request->set_query_params( $args );
    2917                 $response = $this->server->dispatch( $request );
     2917                $response = rest_get_server()->dispatch( $request );
    29182918                $data     = $response->get_data();
    29192919                $this->assertCount( 1, $data );
     
    29352935                );
    29362936                $request->set_body_params( $params );
    2937                 $response = $this->server->dispatch( $request );
     2937                $response = rest_get_server()->dispatch( $request );
    29382938                $new_data = $response->get_data();
    29392939                $this->assertEquals( array(), $new_data['categories'] );
     
    29582958
    29592959                add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    2960                 $response = $this->server->dispatch( $request );
     2960                $response = rest_get_server()->dispatch( $request );
    29612961                remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 );
    29622962
     
    29842984                );
    29852985                $request->set_body_params( $params );
    2986                 $response = $this->server->dispatch( $request );
     2986                $response = rest_get_server()->dispatch( $request );
    29872987
    29882988                $data          = $response->get_data();
     
    30143014                );
    30153015                $request->set_body_params( $params );
    3016                 $response = $this->server->dispatch( $request );
     3016                $response = rest_get_server()->dispatch( $request );
    30173017
    30183018                $data          = $response->get_data();
     
    30423042                );
    30433043                $request->set_body_params( $params );
    3044                 $response = $this->server->dispatch( $request );
     3044                $response = rest_get_server()->dispatch( $request );
    30453045
    30463046                $this->assertEquals( 200, $response->get_status() );
     
    30593059                        $request->set_param( $name, $value );
    30603060                }
    3061                 $response = $this->server->dispatch( $request );
     3061                $response = rest_get_server()->dispatch( $request );
    30623062                $this->assertEquals( 201, $response->get_status() );
    30633063                $actual_output = $response->get_data();
     
    30823082                        $request->set_param( $name, $value );
    30833083                }
    3084                 $response = $this->server->dispatch( $request );
     3084                $response = rest_get_server()->dispatch( $request );
    30853085                $this->assertEquals( 200, $response->get_status() );
    30863086                $actual_output = $response->get_data();
     
    32873287                $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    32883288                $request->set_param( 'force', 'false' );
    3289                 $response = $this->server->dispatch( $request );
     3289                $response = rest_get_server()->dispatch( $request );
    32903290
    32913291                $this->assertEquals( 200, $response->get_status() );
     
    33013301                $request          = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    33023302                $request['force'] = true;
    3303                 $response         = $this->server->dispatch( $request );
     3303                $response         = rest_get_server()->dispatch( $request );
    33043304
    33053305                $this->assertEquals( 200, $response->get_status() );
     
    33133313                wp_set_current_user( self::$editor_id );
    33143314                $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    3315                 $response = $this->server->dispatch( $request );
     3315                $response = rest_get_server()->dispatch( $request );
    33163316                $this->assertEquals( 200, $response->get_status() );
    3317                 $response = $this->server->dispatch( $request );
     3317                $response = rest_get_server()->dispatch( $request );
    33183318                $this->assertErrorResponse( 'rest_already_trashed', $response, 410 );
    33193319        }
     
    33233323
    33243324                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    3325                 $response = $this->server->dispatch( $request );
     3325                $response = rest_get_server()->dispatch( $request );
    33263326
    33273327                $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    33333333
    33343334                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id );
    3335                 $response = $this->server->dispatch( $request );
     3335                $response = rest_get_server()->dispatch( $request );
    33363336
    33373337                $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    33423342
    33433343                $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    3344                 $response = $this->server->dispatch( $request );
     3344                $response = rest_get_server()->dispatch( $request );
    33453345
    33463346                $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
     
    33563356                );
    33573357                create_initial_rest_routes();
    3358                 $routes = $this->server->get_routes();
     3358                $routes = rest_get_server()->get_routes();
    33593359                $this->assertFalse( isset( $routes['/wp/v2/invalid-controller'] ) );
    33603360                _unregister_post_type( 'invalid-controller' );
     
    33643364        public function test_get_item_schema() {
    33653365                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    3366                 $response   = $this->server->dispatch( $request );
     3366                $response   = rest_get_server()->dispatch( $request );
    33673367                $data       = $response->get_data();
    33683368                $properties = $data['schema']['properties'];
     
    34003400                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    34013401                $request->set_param( 'context', 'view' );
    3402                 $response = $this->server->dispatch( $request );
     3402                $response = rest_get_server()->dispatch( $request );
    34033403                $keys     = array_keys( $response->get_data() );
    34043404                sort( $keys );
     
    34383438                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    34393439                $request->set_param( 'context', 'edit' );
    3440                 $response = $this->server->dispatch( $request );
     3440                $response = rest_get_server()->dispatch( $request );
    34413441                $keys     = array_keys( $response->get_data() );
    34423442                sort( $keys );
     
    34753475                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    34763476                $request->set_param( 'context', 'embed' );
    3477                 $response = $this->server->dispatch( $request );
     3477                $response = rest_get_server()->dispatch( $request );
    34783478                $keys     = array_keys( $response->get_data() );
    34793479                sort( $keys );
     
    34963496        public function test_status_array_enum_args() {
    34973497                $request         = new WP_REST_Request( 'GET', '/wp/v2' );
    3498                 $response        = $this->server->dispatch( $request );
     3498                $response        = rest_get_server()->dispatch( $request );
    34993499                $data            = $response->get_data();
    35003500                $list_posts_args = $data['routes']['/wp/v2/posts']['endpoints'][0]['args'];
     
    35283528                $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    35293529
    3530                 $response = $this->server->dispatch( $request );
     3530                $response = rest_get_server()->dispatch( $request );
    35313531                $data     = $response->get_data();
    35323532
     
    35403540                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
    35413541
    3542                 $response = $this->server->dispatch( $request );
     3542                $response = rest_get_server()->dispatch( $request );
    35433543                $this->assertArrayHasKey( 'my_custom_int', $response->data );
    35443544
     
    35503550                );
    35513551
    3552                 $response = $this->server->dispatch( $request );
     3552                $response = rest_get_server()->dispatch( $request );
    35533553                $this->assertEquals( 123, get_post_meta( $post_id, 'my_custom_int', true ) );
    35543554
     
    35613561                );
    35623562
    3563                 $response = $this->server->dispatch( $request );
     3563                $response = rest_get_server()->dispatch( $request );
    35643564
    35653565                $this->assertEquals( 123, $response->data['my_custom_int'] );
     
    35943594                );
    35953595
    3596                 $response = $this->server->dispatch( $request );
     3596                $response = rest_get_server()->dispatch( $request );
    35973597
    35983598                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
  • trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php

    r42343 r42724  
    6868
    6969        public function test_register_routes() {
    70                 $routes = $this->server->get_routes();
     70                $routes = rest_get_server()->get_routes();
    7171                $this->assertArrayHasKey( '/wp/v2/posts/(?P<parent>[\d]+)/revisions', $routes );
    7272                $this->assertArrayHasKey( '/wp/v2/posts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)', $routes );
     
    7878                // Collection
    7979                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    80                 $response = $this->server->dispatch( $request );
     80                $response = rest_get_server()->dispatch( $request );
    8181                $data     = $response->get_data();
    8282                $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    8484                // Single
    8585                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_1->ID );
    86                 $response = $this->server->dispatch( $request );
     86                $response = rest_get_server()->dispatch( $request );
    8787                $data     = $response->get_data();
    8888                $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    9393                wp_set_current_user( self::$editor_id );
    9494                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    95                 $response = $this->server->dispatch( $request );
     95                $response = rest_get_server()->dispatch( $request );
    9696                $data     = $response->get_data();
    9797                $this->assertEquals( 200, $response->get_status() );
     
    109109                wp_set_current_user( 0 );
    110110                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    111                 $response = $this->server->dispatch( $request );
     111                $response = rest_get_server()->dispatch( $request );
    112112
    113113                $this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
    114114                wp_set_current_user( self::$contributor_id );
    115                 $response = $this->server->dispatch( $request );
     115                $response = rest_get_server()->dispatch( $request );
    116116                $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
    117117        }
     
    120120                wp_set_current_user( self::$editor_id );
    121121                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' );
    122                 $response = $this->server->dispatch( $request );
     122                $response = rest_get_server()->dispatch( $request );
    123123                $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
    124124        }
     
    127127                wp_set_current_user( self::$editor_id );
    128128                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions' );
    129                 $response = $this->server->dispatch( $request );
     129                $response = rest_get_server()->dispatch( $request );
    130130                $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
    131131        }
     
    134134                wp_set_current_user( self::$editor_id );
    135135                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    136                 $response = $this->server->dispatch( $request );
     136                $response = rest_get_server()->dispatch( $request );
    137137                $this->assertEquals( 200, $response->get_status() );
    138138                $this->check_get_revision_response( $response, $this->revision_1 );
     
    160160                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    161161                $request->set_param( 'context', 'embed' );
    162                 $response = $this->server->dispatch( $request );
     162                $response = rest_get_server()->dispatch( $request );
    163163                $fields   = array(
    164164                        'author',
     
    178178                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    179179
    180                 $response = $this->server->dispatch( $request );
     180                $response = rest_get_server()->dispatch( $request );
    181181                $this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
    182182                wp_set_current_user( self::$contributor_id );
    183                 $response = $this->server->dispatch( $request );
     183                $response = rest_get_server()->dispatch( $request );
    184184                $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
    185185        }
     
    188188                wp_set_current_user( self::$editor_id );
    189189                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions/' . $this->revision_id1 );
    190                 $response = $this->server->dispatch( $request );
     190                $response = rest_get_server()->dispatch( $request );
    191191                $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
    192192        }
     
    195195                wp_set_current_user( self::$editor_id );
    196196                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions/' . $this->revision_id1 );
    197                 $response = $this->server->dispatch( $request );
     197                $response = rest_get_server()->dispatch( $request );
    198198                $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
    199199        }
     
    203203                $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    204204                $request->set_param( 'force', true );
    205                 $response = $this->server->dispatch( $request );
     205                $response = rest_get_server()->dispatch( $request );
    206206                $this->assertEquals( 200, $response->get_status() );
    207207                $this->assertNull( get_post( $this->revision_id1 ) );
     
    212212
    213213                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    214                 $response = $this->server->dispatch( $request );
     214                $response = rest_get_server()->dispatch( $request );
    215215                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    216216
    217217                $request->set_param( 'force', 'false' );
    218                 $response = $this->server->dispatch( $request );
     218                $response = rest_get_server()->dispatch( $request );
    219219                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    220220
     
    226226                wp_set_current_user( self::$contributor_id );
    227227                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    228                 $response = $this->server->dispatch( $request );
     228                $response = rest_get_server()->dispatch( $request );
    229229                $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
    230230        }
     
    233233                wp_set_current_user( self::$editor_id );
    234234                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    235                 $response = $this->server->dispatch( $request );
     235                $response = rest_get_server()->dispatch( $request );
    236236                $this->assertEquals( 200, $response->get_status() );
    237237                $this->check_get_revision_response( $response, $this->revision_1 );
     
    240240        public function test_get_item_schema() {
    241241                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    242                 $response   = $this->server->dispatch( $request );
     242                $response   = rest_get_server()->dispatch( $request );
    243243                $data       = $response->get_data();
    244244                $properties = $data['schema']['properties'];
     
    260260        public function test_create_item() {
    261261                $request  = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    262                 $response = $this->server->dispatch( $request );
     262                $response = rest_get_server()->dispatch( $request );
    263263                $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    264264        }
     
    266266        public function test_update_item() {
    267267                $request  = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    268                 $response = $this->server->dispatch( $request );
     268                $response = rest_get_server()->dispatch( $request );
    269269                $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    270270        }
     
    289289                $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    290290
    291                 $response = $this->server->dispatch( $request );
     291                $response = rest_get_server()->dispatch( $request );
    292292                $data     = $response->get_data();
    293293
     
    299299                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    300300
    301                 $response = $this->server->dispatch( $request );
     301                $response = rest_get_server()->dispatch( $request );
    302302                $this->assertArrayHasKey( 'my_custom_int', $response->data );
    303303
     
    355355                wp_set_current_user( self::$editor_id );
    356356                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    357                 $this->server->dispatch( $request );
     357                rest_get_server()->dispatch( $request );
    358358
    359359                $post           = get_post();
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r42343 r42724  
    2121                /** @var WP_REST_Server $wp_rest_server */
    2222                global $wp_rest_server;
    23                 $this->server = $wp_rest_server = new Spy_REST_Server;
    24                 do_action( 'rest_api_init' );
     23                $wp_rest_server = new Spy_REST_Server;
     24                do_action( 'rest_api_init', $wp_rest_server );
    2525
    2626                add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
     
    7373
    7474        public function test_expected_routes_in_schema() {
    75                 $routes = $this->server->get_routes();
     75                $routes = rest_get_server()->get_routes();
    7676
    7777                $this->assertTrue( is_array( $routes ), '`get_routes` should return an array.' );
     
    374374                                $request->set_query_params( $route['args'] );
    375375                        }
    376                         $response = $this->server->dispatch( $request );
     376                        $response = rest_get_server()->dispatch( $request );
    377377                        $status   = $response->get_status();
    378378                        $data     = $response->get_data();
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r42343 r42724  
    1717                $GLOBALS['wp_rest_server'] = null;
    1818                add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );
    19                 $this->server = rest_get_server();
     19                $GLOBALS['wp_rest_server'] = rest_get_server();
    2020                remove_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );
    2121        }
     
    4646                $response->header( 'Multiple', 'yes', false );
    4747
    48                 $envelope_response = $this->server->envelope_response( $response, false );
     48                $envelope_response = rest_get_server()->envelope_response( $response, false );
    4949
    5050                // The envelope should still be a response, but with defaults.
     
    7676
    7777                $request  = new WP_REST_Request( 'GET', '/test-ns/test' );
    78                 $response = $this->server->dispatch( $request );
     78                $response = rest_get_server()->dispatch( $request );
    7979
    8080                $this->assertEquals( 'bar', $request['foo'] );
     
    9797                $request = new WP_REST_Request( 'GET', '/test-ns/test' );
    9898                $request->set_query_params( array( 'foo' => 123 ) );
    99                 $response = $this->server->dispatch( $request );
     99                $response = rest_get_server()->dispatch( $request );
    100100
    101101                $this->assertEquals( '123', $request['foo'] );
     
    115115                $request = new WP_REST_Request( 'GET', '/optional/test' );
    116116                $request->set_query_params( array() );
    117                 $response = $this->server->dispatch( $request );
     117                $response = rest_get_server()->dispatch( $request );
    118118                $this->assertInstanceOf( 'WP_REST_Response', $response );
    119119                $this->assertEquals( 200, $response->get_status() );
     
    134134                );
    135135                $request = new WP_REST_Request( 'GET', '/no-zero/test' );
    136                 $this->server->dispatch( $request );
     136                rest_get_server()->dispatch( $request );
    137137                $this->assertEquals( array( 'foo' => 'bar' ), $request->get_params() );
    138138        }
     
    146146                );
    147147                $request  = new WP_REST_Request( 'HEAD', '/head-request/test' );
    148                 $response = $this->server->dispatch( $request );
     148                $response = rest_get_server()->dispatch( $request );
    149149                $this->assertEquals( 200, $response->get_status() );
    150150        }
     
    171171                );
    172172                $request  = new WP_REST_Request( 'HEAD', '/head-request/test' );
    173                 $response = $this->server->dispatch( $request );
     173                $response = rest_get_server()->dispatch( $request );
    174174                $this->assertEquals( 200, $response->get_status() );
    175175        }
     
    177177        public function test_url_params_no_numeric_keys() {
    178178
    179                 $this->server->register_route(
     179                rest_get_server()->register_route(
    180180                        'test', '/test/(?P<data>.*)', array(
    181181                                array(
     
    190190
    191191                $request = new WP_REST_Request( 'GET', '/test/some-value' );
    192                 $this->server->dispatch( $request );
     192                rest_get_server()->dispatch( $request );
    193193                $this->assertEquals( array( 'data' => 'some-value' ), $request->get_params() );
    194194        }
     
    209209
    210210                $request = new WP_REST_Request( 'GET', '/test-ns/test', array() );
    211                 $result  = $this->server->dispatch( $request );
     211                $result  = rest_get_server()->dispatch( $request );
    212212
    213213                $this->assertEquals( 403, $result->get_status() );
     
    234234                wp_set_current_user( $editor );
    235235
    236                 $result = $this->server->dispatch( $request );
     236                $result = rest_get_server()->dispatch( $request );
    237237
    238238                $this->assertEquals( 200, $result->get_status() );
     
    255255                $request = new WP_REST_Request( 'GET', '/test-ns/test', array() );
    256256
    257                 $result = $this->server->dispatch( $request );
    258                 $result = apply_filters( 'rest_post_dispatch', $result, $this->server, $request );
     257                $result = rest_get_server()->dispatch( $request );
     258                $result = apply_filters( 'rest_post_dispatch', $result, rest_get_server(), $request );
    259259
    260260                $this->assertFalse( $result->get_status() !== 200 );
     
    288288                $request = new WP_REST_Request( 'GET', '/test-ns/test', array() );
    289289
    290                 $result = $this->server->dispatch( $request );
     290                $result = rest_get_server()->dispatch( $request );
    291291
    292292                $this->assertFalse( $result->get_status() !== 200 );
    293293
    294                 $result = apply_filters( 'rest_post_dispatch', $result, $this->server, $request );
     294                $result = apply_filters( 'rest_post_dispatch', $result, rest_get_server(), $request );
    295295
    296296                $sent_headers = $result->get_headers();
     
    323323                $request = new WP_REST_Request( 'GET', '/test-ns/test', array() );
    324324
    325                 $result = $this->server->dispatch( $request );
    326                 $result = apply_filters( 'rest_post_dispatch', $result, $this->server, $request );
     325                $result = rest_get_server()->dispatch( $request );
     326                $result = apply_filters( 'rest_post_dispatch', $result, rest_get_server(), $request );
    327327
    328328                $this->assertEquals( $result->get_status(), 403 );
     
    348348
    349349                $request  = new WP_REST_Request( 'OPTIONS', '/test-ns/test' );
    350                 $response = $this->server->dispatch( $request );
    351 
    352                 $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this->server, $request );
     350                $response = rest_get_server()->dispatch( $request );
     351
     352                $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), rest_get_server(), $request );
    353353
    354354                $headers = $result->get_headers();
     
    366366                $error   = new WP_Error( $code, $message );
    367367
    368                 $response = $this->server->error_to_response( $error );
     368                $response = rest_get_server()->error_to_response( $error );
    369369                $this->assertInstanceOf( 'WP_REST_Response', $response );
    370370
     
    383383                $error   = new WP_Error( $code, $message, array( 'status' => 400 ) );
    384384
    385                 $response = $this->server->error_to_response( $error );
     385                $response = rest_get_server()->error_to_response( $error );
    386386                $this->assertInstanceOf( 'WP_REST_Response', $response );
    387387
     
    402402                $error->add( $code2, $message2, array( 'status' => 403 ) );
    403403
    404                 $response = $this->server->error_to_response( $error );
     404                $response = rest_get_server()->error_to_response( $error );
    405405                $this->assertInstanceOf( 'WP_REST_Response', $response );
    406406
     
    421421                );
    422422                $expected = wp_json_encode( $data );
    423                 $response = $this->server->json_error( 'wp-api-test-error', 'Message text' );
     423                $response = rest_get_server()->json_error( 'wp-api-test-error', 'Message text' );
    424424
    425425                $this->assertEquals( $expected, $response );
     
    451451                $response->add_link( 'alternate', 'http://example.org/', array( 'type' => 'application/xml' ) );
    452452
    453                 $data = $this->server->response_to_data( $response, false );
     453                $data = rest_get_server()->response_to_data( $response, false );
    454454                $this->assertArrayHasKey( '_links', $data );
    455455
     
    468468        public function test_link_embedding() {
    469469                // Register our testing route.
    470                 $this->server->register_route(
     470                rest_get_server()->register_route(
    471471                        'test', '/test/embeddable', array(
    472472                                'methods'  => 'GET',
     
    482482                $response->add_link( 'alternate', rest_url( '/test/embeddable' ), array( 'embeddable' => true ) );
    483483
    484                 $data = $this->server->response_to_data( $response, true );
     484                $data = rest_get_server()->response_to_data( $response, true );
    485485                $this->assertArrayHasKey( '_embedded', $data );
    486486
     
    501501                $response->add_link( 'https://api.w.org/term', 'http://example.com/' );
    502502
    503                 $data  = $this->server->response_to_data( $response, false );
     503                $data  = rest_get_server()->response_to_data( $response, false );
    504504                $links = $data['_links'];
    505505
     
    514514                add_filter( 'rest_response_link_curies', array( $this, 'add_custom_curie' ) );
    515515
    516                 $data  = $this->server->response_to_data( $response, false );
     516                $data  = rest_get_server()->response_to_data( $response, false );
    517517                $links = $data['_links'];
    518518
     
    541541        public function test_link_embedding_self() {
    542542                // Register our testing route.
    543                 $this->server->register_route(
     543                rest_get_server()->register_route(
    544544                        'test', '/test/embeddable', array(
    545545                                'methods'  => 'GET',
     
    552552                $response->add_link( 'self', rest_url( '/test/notembeddable' ), array( 'embeddable' => true ) );
    553553
    554                 $data = $this->server->response_to_data( $response, true );
     554                $data = rest_get_server()->response_to_data( $response, true );
    555555
    556556                $this->assertArrayNotHasKey( '_embedded', $data );
     
    562562        public function test_link_embedding_params() {
    563563                // Register our testing route.
    564                 $this->server->register_route(
     564                rest_get_server()->register_route(
    565565                        'test', '/test/embeddable', array(
    566566                                'methods'  => 'GET',
     
    574574                $response->add_link( 'alternate', $url, array( 'embeddable' => true ) );
    575575
    576                 $data = $this->server->response_to_data( $response, true );
     576                $data = rest_get_server()->response_to_data( $response, true );
    577577
    578578                $this->assertArrayHasKey( '_embedded', $data );
     
    588588        public function test_link_embedding_error() {
    589589                // Register our testing route.
    590                 $this->server->register_route(
     590                rest_get_server()->register_route(
    591591                        'test', '/test/embeddable', array(
    592592                                'methods'  => 'GET',
     
    600600                $response->add_link( 'up', $url, array( 'embeddable' => true ) );
    601601
    602                 $data = $this->server->response_to_data( $response, true );
     602                $data = rest_get_server()->response_to_data( $response, true );
    603603
    604604                $this->assertArrayHasKey( '_embedded', $data );
     
    622622                        'untouched' => 'data',
    623623                );
    624                 $result = $this->server->embed_links( $data );
     624                $result = rest_get_server()->embed_links( $data );
    625625
    626626                $this->assertArrayNotHasKey( '_links', $data );
     
    651651                $response->remove_link( 'self' );
    652652
    653                 $data = $this->server->response_to_data( $response, false );
     653                $data = rest_get_server()->response_to_data( $response, false );
    654654                $this->assertArrayHasKey( '_links', $data );
    655655
     
    670670                $response->remove_link( 'self', 'https://example.com/' );
    671671
    672                 $data = $this->server->response_to_data( $response, false );
     672                $data = rest_get_server()->response_to_data( $response, false );
    673673                $this->assertArrayHasKey( '_links', $data );
    674674
     
    790790                $request = new WP_REST_Request( 'GET', '/', array() );
    791791
    792                 $result  = $this->server->serve_request( '/' );
    793                 $headers = $this->server->sent_headers;
     792                $result  = rest_get_server()->serve_request( '/' );
     793                $headers = rest_get_server()->sent_headers;
    794794
    795795                $this->assertEquals( 'noindex', $headers['X-Robots-Tag'] );
     
    802802        public function test_rest_enable_filter_is_deprecated() {
    803803                add_filter( 'rest_enabled', '__return_false' );
    804                 $this->server->serve_request( '/' );
     804                rest_get_server()->serve_request( '/' );
    805805                remove_filter( 'rest_enabled', '__return_false' );
    806806
    807                 $result = json_decode( $this->server->sent_body );
     807                $result = json_decode( rest_get_server()->sent_body );
    808808
    809809                $this->assertObjectNotHasAttribute( 'code', $result );
     
    815815                $request = new WP_REST_Request( 'GET', '/', array() );
    816816
    817                 $result  = $this->server->serve_request( '/' );
    818                 $headers = $this->server->sent_headers;
     817                $result  = rest_get_server()->serve_request( '/' );
     818                $headers = rest_get_server()->sent_headers;
    819819
    820820                $this->assertEquals( '<' . esc_url_raw( $api_root ) . '>; rel="https://api.w.org/"', $headers['Link'] );
     
    826826                wp_set_current_user( $editor );
    827827
    828                 $result  = $this->server->serve_request( '/' );
    829                 $headers = $this->server->sent_headers;
     828                $result  = rest_get_server()->serve_request( '/' );
     829                $headers = rest_get_server()->sent_headers;
    830830
    831831                foreach ( wp_get_nocache_headers() as $header => $value ) {
     
    846846                $request = new WP_REST_Request( 'GET', '/', array() );
    847847
    848                 $result  = $this->server->serve_request( '/' );
    849                 $headers = $this->server->sent_headers;
     848                $result  = rest_get_server()->serve_request( '/' );
     849                $headers = rest_get_server()->sent_headers;
    850850
    851851                foreach ( wp_get_nocache_headers() as $header => $value ) {
     
    856856        public function test_serve_request_url_params_are_unslashed() {
    857857
    858                 $this->server->register_route(
     858                rest_get_server()->register_route(
    859859                        'test', '/test/(?P<data>.*)', array(
    860860                                array(
     
    868868                );
    869869
    870                 $result     = $this->server->serve_request( '/test/data\\with\\slashes' );
    871                 $url_params = $this->server->last_request->get_url_params();
     870                $result     = rest_get_server()->serve_request( '/test/data\\with\\slashes' );
     871                $url_params = rest_get_server()->last_request->get_url_params();
    872872                $this->assertEquals( 'data\\with\\slashes', $url_params['data'] );
    873873        }
     
    875875        public function test_serve_request_query_params_are_unslashed() {
    876876
    877                 $this->server->register_route(
     877                rest_get_server()->register_route(
    878878                        'test', '/test', array(
    879879                                array(
     
    894894                );
    895895
    896                 $result       = $this->server->serve_request( '/test' );
    897                 $query_params = $this->server->last_request->get_query_params();
     896                $result       = rest_get_server()->serve_request( '/test' );
     897                $query_params = rest_get_server()->last_request->get_query_params();
    898898                $this->assertEquals( 'data\\with\\slashes', $query_params['data'] );
    899899        }
     
    901901        public function test_serve_request_body_params_are_unslashed() {
    902902
    903                 $this->server->register_route(
     903                rest_get_server()->register_route(
    904904                        'test', '/test', array(
    905905                                array(
     
    920920                );
    921921
    922                 $result = $this->server->serve_request( '/test/data' );
    923 
    924                 $body_params = $this->server->last_request->get_body_params();
     922                $result = rest_get_server()->serve_request( '/test/data' );
     923
     924                $body_params = rest_get_server()->last_request->get_body_params();
    925925                $this->assertEquals( 'data\\with\\slashes', $body_params['data'] );
    926926        }
     
    928928        public function test_serve_request_json_params_are_unslashed() {
    929929
    930                 $this->server->register_route(
     930                rest_get_server()->register_route(
    931931                        'test', '/test', array(
    932932                                array(
     
    947947                );
    948948
    949                 $result      = $this->server->serve_request( '/test' );
    950                 $json_params = $this->server->last_request->get_json_params();
     949                $result      = rest_get_server()->serve_request( '/test' );
     950                $json_params = rest_get_server()->last_request->get_json_params();
    951951                $this->assertEquals( 'data\\with\\slashes', $json_params['data'] );
    952952        }
     
    954954        public function test_serve_request_file_params_are_unslashed() {
    955955
    956                 $this->server->register_route(
     956                rest_get_server()->register_route(
    957957                        'test', '/test', array(
    958958                                array(
     
    973973                );
    974974
    975                 $result      = $this->server->serve_request( '/test/data\\with\\slashes' );
    976                 $file_params = $this->server->last_request->get_file_params();
     975                $result      = rest_get_server()->serve_request( '/test/data\\with\\slashes' );
     976                $file_params = rest_get_server()->last_request->get_file_params();
    977977                $this->assertEquals( 'data\\with\\slashes', $file_params['data']['name'] );
    978978        }
     
    980980        public function test_serve_request_headers_are_unslashed() {
    981981
    982                 $this->server->register_route(
     982                rest_get_server()->register_route(
    983983                        'test', '/test', array(
    984984                                array(
     
    995995                $_SERVER['HTTP_X_MY_HEADER'] = wp_slash( 'data\\with\\slashes' );
    996996
    997                 $result = $this->server->serve_request( '/test/data\\with\\slashes' );
    998                 $this->assertEquals( 'data\\with\\slashes', $this->server->last_request->get_header( 'x_my_header' ) );
     997                $result = rest_get_server()->serve_request( '/test/data\\with\\slashes' );
     998                $this->assertEquals( 'data\\with\\slashes', rest_get_server()->last_request->get_header( 'x_my_header' ) );
    999999        }
    10001000
     
    10791079                        )
    10801080                );
    1081                 $response = $this->server->dispatch( $request );
     1081                $response = rest_get_server()->dispatch( $request );
    10821082
    10831083                $this->assertEquals( 200, $response->get_status() );
     
    11381138        protected function helper_make_request_and_return_headers_for_rest_send_refreshed_nonce_tests() {
    11391139                $request = new WP_REST_Request( 'GET', '/', array() );
    1140                 $result  = $this->server->serve_request( '/' );
    1141 
    1142                 return $this->server->sent_headers;
     1140                $result  = rest_get_server()->serve_request( '/' );
     1141
     1142                return rest_get_server()->sent_headers;
    11431143        }
    11441144}
  • trunk/tests/phpunit/tests/rest-api/rest-settings-controller.php

    r42423 r42724  
    4040
    4141        public function test_register_routes() {
    42                 $routes = $this->server->get_routes();
     42                $routes = rest_get_server()->get_routes();
    4343                $this->assertArrayHasKey( '/wp/v2/settings', $routes );
    4444        }
     
    4848                wp_set_current_user( self::$administrator );
    4949                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings/title' );
    50                 $response = $this->server->dispatch( $request );
     50                $response = rest_get_server()->dispatch( $request );
    5151                $this->assertEquals( 404, $response->get_status() );
    5252        }
     
    5757        public function test_get_item_is_not_public_not_authenticated() {
    5858                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    59                 $response = $this->server->dispatch( $request );
     59                $response = rest_get_server()->dispatch( $request );
    6060                $this->assertEquals( 401, $response->get_status() );
    6161        }
     
    6464                wp_set_current_user( self::$author );
    6565                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    66                 $response = $this->server->dispatch( $request );
     66                $response = rest_get_server()->dispatch( $request );
    6767                $this->assertEquals( 403, $response->get_status() );
    6868        }
     
    7171                wp_set_current_user( self::$administrator );
    7272                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    73                 $response = $this->server->dispatch( $request );
     73                $response = rest_get_server()->dispatch( $request );
    7474                $data     = $response->get_data();
    7575                $actual   = array_keys( $data );
     
    108108                update_option( 'posts_per_page', 'invalid_number' ); // this is cast to (int) 1
    109109                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    110                 $response = $this->server->dispatch( $request );
     110                $response = rest_get_server()->dispatch( $request );
    111111                $data     = $response->get_data();
    112112
     
    132132
    133133                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    134                 $response = $this->server->dispatch( $request );
     134                $response = rest_get_server()->dispatch( $request );
    135135                $data     = $response->get_data();
    136136
     
    142142
    143143                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    144                 $response = $this->server->dispatch( $request );
     144                $response = rest_get_server()->dispatch( $request );
    145145                $data     = $response->get_data();
    146146                $this->assertEquals( 'validvalue2', $data['mycustomsettinginrest'] );
     
    169169                update_option( 'mycustomsetting', array( '1', '2' ) );
    170170                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    171                 $response = $this->server->dispatch( $request );
     171                $response = rest_get_server()->dispatch( $request );
    172172                $data     = $response->get_data();
    173173                $this->assertEquals( array( 1, 2 ), $data['mycustomsetting'] );
     
    176176                update_option( 'mycustomsetting', array() );
    177177                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    178                 $response = $this->server->dispatch( $request );
     178                $response = rest_get_server()->dispatch( $request );
    179179                $data     = $response->get_data();
    180180                $this->assertEquals( array(), $data['mycustomsetting'] );
     
    183183                update_option( 'mycustomsetting', array( array( 1 ) ) );
    184184                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    185                 $response = $this->server->dispatch( $request );
     185                $response = rest_get_server()->dispatch( $request );
    186186                $data     = $response->get_data();
    187187                $this->assertEquals( null, $data['mycustomsetting'] );
     
    190190                delete_option( 'mycustomsetting' );
    191191                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    192                 $response = $this->server->dispatch( $request );
     192                $response = rest_get_server()->dispatch( $request );
    193193                $data     = $response->get_data();
    194194                $this->assertEquals( null, $data['mycustomsetting'] );
     
    217217
    218218                // We have to re-register the route, as the args changes based off registered settings.
    219                 $this->server->override_by_default = true;
     219                rest_get_server()->override_by_default = true;
    220220                $this->endpoint->register_routes();
    221221
     
    223223                update_option( 'mycustomsetting', array( 'a' => '1' ) );
    224224                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    225                 $response = $this->server->dispatch( $request );
     225                $response = rest_get_server()->dispatch( $request );
    226226                $data     = $response->get_data();
    227227                $this->assertEquals( array( 'a' => 1 ), $data['mycustomsetting'] );
     
    230230                update_option( 'mycustomsetting', array() );
    231231                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    232                 $response = $this->server->dispatch( $request );
     232                $response = rest_get_server()->dispatch( $request );
    233233                $data     = $response->get_data();
    234234                $this->assertEquals( array(), $data['mycustomsetting'] );
     
    242242                );
    243243                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    244                 $response = $this->server->dispatch( $request );
     244                $response = rest_get_server()->dispatch( $request );
    245245                $data     = $response->get_data();
    246246                $this->assertEquals( null, $data['mycustomsetting'] );
     
    284284
    285285                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    286                 $response = $this->server->dispatch( $request );
     286                $response = rest_get_server()->dispatch( $request );
    287287                $data     = $response->get_data();
    288288
     
    318318
    319319                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    320                 $response = $this->server->dispatch( $request );
     320                $response = rest_get_server()->dispatch( $request );
    321321                $data     = $response->get_data();
    322322                $this->assertEquals( null, $data['mycustomsettinginrest'] );
     
    342342
    343343                $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    344                 $response = $this->server->dispatch( $request );
     344                $response = rest_get_server()->dispatch( $request );
    345345                $data     = $response->get_data();
    346346                $this->assertEquals( null, $data['mycustomsettinginrest'] );
     
    356356                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    357357                $request->set_param( 'title', 'The new title!' );
    358                 $response = $this->server->dispatch( $request );
     358                $response = rest_get_server()->dispatch( $request );
    359359                $data     = $response->get_data();
    360360
     
    389389
    390390                // We have to re-register the route, as the args changes based off registered settings.
    391                 $this->server->override_by_default = true;
     391                rest_get_server()->override_by_default = true;
    392392                $this->endpoint->register_routes();
    393393                wp_set_current_user( self::$administrator );
     
    395395                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    396396                $request->set_param( 'mycustomsetting', array( '1', '2' ) );
    397                 $response = $this->server->dispatch( $request );
     397                $response = rest_get_server()->dispatch( $request );
    398398                $data     = $response->get_data();
    399399                $this->assertEquals( array( 1, 2 ), $data['mycustomsetting'] );
     
    403403                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    404404                $request->set_param( 'mycustomsetting', array() );
    405                 $response = $this->server->dispatch( $request );
     405                $response = rest_get_server()->dispatch( $request );
    406406                $data     = $response->get_data();
    407407                $this->assertEquals( array(), $data['mycustomsetting'] );
     
    411411                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    412412                $request->set_param( 'mycustomsetting', array( 'invalid' ) );
    413                 $response = $this->server->dispatch( $request );
     413                $response = rest_get_server()->dispatch( $request );
    414414
    415415                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    440440
    441441                // We have to re-register the route, as the args changes based off registered settings.
    442                 $this->server->override_by_default = true;
     442                rest_get_server()->override_by_default = true;
    443443                $this->endpoint->register_routes();
    444444                wp_set_current_user( self::$administrator );
     
    453453                        )
    454454                );
    455                 $response = $this->server->dispatch( $request );
     455                $response = rest_get_server()->dispatch( $request );
    456456                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    457457        }
     
    475475
    476476                // We have to re-register the route, as the args changes based off registered settings.
    477                 $this->server->override_by_default = true;
     477                rest_get_server()->override_by_default = true;
    478478                $this->endpoint->register_routes();
    479479                wp_set_current_user( self::$administrator );
     
    481481                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    482482                $request->set_param( 'mycustomsetting', array( 'a' => 1 ) );
    483                 $response = $this->server->dispatch( $request );
     483                $response = rest_get_server()->dispatch( $request );
    484484                $data     = $response->get_data();
    485485                $this->assertEquals( array( 'a' => 1 ), $data['mycustomsetting'] );
     
    489489                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    490490                $request->set_param( 'mycustomsetting', array() );
    491                 $response = $this->server->dispatch( $request );
     491                $response = rest_get_server()->dispatch( $request );
    492492                $data     = $response->get_data();
    493493                $this->assertEquals( array(), $data['mycustomsetting'] );
     
    502502                        )
    503503                );
    504                 $response = $this->server->dispatch( $request );
     504                $response = rest_get_server()->dispatch( $request );
    505505
    506506                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    509509                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    510510                $request->set_param( 'mycustomsetting', array( 'a' => 'invalid' ) );
    511                 $response = $this->server->dispatch( $request );
     511                $response = rest_get_server()->dispatch( $request );
    512512                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    513513                unregister_setting( 'somegroup', 'mycustomsetting' );
     
    520520                $request->set_param( 'title', 'The old title!' );
    521521                $request->set_param( 'description', 'The old description!' );
    522                 $response = $this->server->dispatch( $request );
     522                $response = rest_get_server()->dispatch( $request );
    523523                $data     = $response->get_data();
    524524                $this->assertEquals( 200, $response->get_status() );
     
    533533                $request->set_param( 'title', 'The new title!' );
    534534                $request->set_param( 'description', 'The new description!' );
    535                 $response = $this->server->dispatch( $request );
     535                $response = rest_get_server()->dispatch( $request );
    536536                $data     = $response->get_data();
    537537
     
    549549                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    550550                $request->set_param( 'title', array( 'rendered' => 'This should fail.' ) );
    551                 $response = $this->server->dispatch( $request );
     551                $response = rest_get_server()->dispatch( $request );
    552552                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    553553        }
     
    557557                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    558558                $request->set_param( 'posts_per_page', 11 );
    559                 $response = $this->server->dispatch( $request );
     559                $response = rest_get_server()->dispatch( $request );
    560560                $this->assertEquals( 200, $response->get_status() );
    561561        }
     
    565565                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    566566                $request->set_param( 'posts_per_page', 10.5 );
    567                 $response = $this->server->dispatch( $request );
     567                $response = rest_get_server()->dispatch( $request );
    568568                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    569569        }
     
    578578                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    579579                $request->set_param( 'posts_per_page', null );
    580                 $response = $this->server->dispatch( $request );
     580                $response = rest_get_server()->dispatch( $request );
    581581                $data     = $response->get_data();
    582582
     
    591591                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    592592                $request->set_param( 'default_ping_status', 'open&closed' );
    593                 $response = $this->server->dispatch( $request );
     593                $response = rest_get_server()->dispatch( $request );
    594594                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    595595        }
     
    609609                $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' );
    610610                $request->set_param( 'mycustomsetting', null );
    611                 $response = $this->server->dispatch( $request );
     611                $response = rest_get_server()->dispatch( $request );
    612612
    613613                $this->assertErrorResponse( 'rest_invalid_stored_value', $response, 500 );
     
    617617                /** Settings can't be deleted */
    618618                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/settings/title' );
    619                 $response = $this->server->dispatch( $request );
     619                $response = rest_get_server()->dispatch( $request );
    620620                $this->assertEquals( 404, $response->get_status() );
    621621        }
  • trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php

    r42343 r42724  
    5151
    5252        public function test_register_routes() {
    53                 $routes = $this->server->get_routes();
     53                $routes = rest_get_server()->get_routes();
    5454                $this->assertArrayHasKey( '/wp/v2/tags', $routes );
    5555                $this->assertArrayHasKey( '/wp/v2/tags/(?P<id>[\d]+)', $routes );
     
    5959                // Collection
    6060                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );
    61                 $response = $this->server->dispatch( $request );
     61                $response = rest_get_server()->dispatch( $request );
    6262                $data     = $response->get_data();
    6363                $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    6666                $tag1     = $this->factory->tag->create( array( 'name' => 'Season 5' ) );
    6767                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags/' . $tag1 );
    68                 $response = $this->server->dispatch( $request );
     68                $response = rest_get_server()->dispatch( $request );
    6969                $data     = $response->get_data();
    7070                $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    7474        public function test_registered_query_params() {
    7575                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );
    76                 $response = $this->server->dispatch( $request );
     76                $response = rest_get_server()->dispatch( $request );
    7777                $data     = $response->get_data();
    7878                $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    9999                $this->factory->tag->create();
    100100                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    101                 $response = $this->server->dispatch( $request );
     101                $response = rest_get_server()->dispatch( $request );
    102102                $this->check_get_taxonomy_terms_response( $response );
    103103        }
     
    107107                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    108108                $request->set_param( 'context', 'edit' );
    109                 $response = $this->server->dispatch( $request );
     109                $response = rest_get_server()->dispatch( $request );
    110110                $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    111111        }
     
    118118                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    119119                $request->set_param( 'hide_empty', true );
    120                 $response = $this->server->dispatch( $request );
     120                $response = rest_get_server()->dispatch( $request );
    121121                $data     = $response->get_data();
    122122                $this->assertEquals( 2, count( $data ) );
     
    125125                // invalid value should fail
    126126                $request->set_param( 'hide_empty', 'nothanks' );
    127                 $response = $this->server->dispatch( $request );
     127                $response = rest_get_server()->dispatch( $request );
    128128                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    129129        }
     
    136136                // Orderby=>asc
    137137                $request->set_param( 'include', array( $id3, $id1 ) );
    138                 $response = $this->server->dispatch( $request );
     138                $response = rest_get_server()->dispatch( $request );
    139139                $data     = $response->get_data();
    140140                $this->assertEquals( 2, count( $data ) );
     
    142142                // Orderby=>include
    143143                $request->set_param( 'orderby', 'include' );
    144                 $response = $this->server->dispatch( $request );
     144                $response = rest_get_server()->dispatch( $request );
    145145                $data     = $response->get_data();
    146146                $this->assertEquals( 2, count( $data ) );
     
    148148                // Include invalid value shoud fail
    149149                $request->set_param( 'include', array( 'myterm' ) );
    150                 $response = $this->server->dispatch( $request );
     150                $response = rest_get_server()->dispatch( $request );
    151151                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    152152        }
     
    156156                $id2      = $this->factory->tag->create();
    157157                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    158                 $response = $this->server->dispatch( $request );
     158                $response = rest_get_server()->dispatch( $request );
    159159                $data     = $response->get_data();
    160160                $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    161161                $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
    162162                $request->set_param( 'exclude', array( $id2 ) );
    163                 $response = $this->server->dispatch( $request );
     163                $response = rest_get_server()->dispatch( $request );
    164164                $data     = $response->get_data();
    165165                $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     
    167167                // Invalid exclude value should fail
    168168                $request->set_param( 'exclude', array( 'invalid' ) );
    169                 $response = $this->server->dispatch( $request );
     169                $response = rest_get_server()->dispatch( $request );
    170170                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    171171        }
     
    178178                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    179179                $request->set_param( 'offset', 1 );
    180                 $response = $this->server->dispatch( $request );
     180                $response = rest_get_server()->dispatch( $request );
    181181                $this->assertCount( 3, $response->get_data() );
    182182                // 'offset' works with 'per_page'
    183183                $request->set_param( 'per_page', 2 );
    184                 $response = $this->server->dispatch( $request );
     184                $response = rest_get_server()->dispatch( $request );
    185185                $this->assertCount( 2, $response->get_data() );
    186186                // 'offset' takes priority over 'page'
    187187                $request->set_param( 'page', 3 );
    188                 $response = $this->server->dispatch( $request );
     188                $response = rest_get_server()->dispatch( $request );
    189189                $this->assertCount( 2, $response->get_data() );
    190190                // 'offset' invalid value shoudl fail
    191191                $request->set_param( 'offset', 'moreplease' );
    192                 $response = $this->server->dispatch( $request );
     192                $response = rest_get_server()->dispatch( $request );
    193193                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    194194        }
     
    208208                $request->set_param( 'order', 'desc' );
    209209                $request->set_param( 'per_page', 1 );
    210                 $response = $this->server->dispatch( $request );
     210                $response = rest_get_server()->dispatch( $request );
    211211                $this->assertEquals( 200, $response->get_status() );
    212212                $data = $response->get_data();
     
    217217                $request->set_param( 'order', 'asc' );
    218218                $request->set_param( 'per_page', 2 );
    219                 $response = $this->server->dispatch( $request );
     219                $response = rest_get_server()->dispatch( $request );
    220220                $this->assertEquals( 200, $response->get_status() );
    221221                $data = $response->get_data();
     
    224224                // Invalid orderby should fail.
    225225                $request->set_param( 'orderby', 'invalid' );
    226                 $response = $this->server->dispatch( $request );
     226                $response = rest_get_server()->dispatch( $request );
    227227                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    228228        }
     
    234234                // defaults to orderby=name, order=asc
    235235                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    236                 $response = $this->server->dispatch( $request );
     236                $response = rest_get_server()->dispatch( $request );
    237237                $this->assertEquals( 200, $response->get_status() );
    238238                $data = $response->get_data();
     
    243243                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    244244                $request->set_param( 'orderby', 'id' );
    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();
     
    253253                $request->set_param( 'orderby', 'id' );
    254254                $request->set_param( 'order', 'desc' );
    255                 $response = $this->server->dispatch( $request );
     255                $response = rest_get_server()->dispatch( $request );
    256256                $data     = $response->get_data();
    257257                $this->assertEquals( 200, $response->get_status() );
     
    269269                $request->set_param( 'orderby', 'include_slugs' );
    270270                $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) );
    271                 $response = $this->server->dispatch( $request );
     271                $response = rest_get_server()->dispatch( $request );
    272272                $data     = $response->get_data();
    273273                $this->assertEquals( 200, $response->get_status() );
     
    286286                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    287287                $request->set_param( 'post', $post_id );
    288                 $response = $this->server->dispatch( $request );
     288                $response = rest_get_server()->dispatch( $request );
    289289                $this->assertEquals( 200, $response->get_status() );
    290290
     
    296296                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    297297                $request->set_param( 'post', 'invalid-post' );
    298                 $response = $this->server->dispatch( $request );
     298                $response = rest_get_server()->dispatch( $request );
    299299                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    300300        }
     
    318318                $request->set_param( 'per_page', 15 );
    319319                $request->set_param( 'orderby', 'id' );
    320                 $response = $this->server->dispatch( $request );
     320                $response = rest_get_server()->dispatch( $request );
    321321                $tags     = $response->get_data();
    322322
     
    332332                $request->set_param( 'per_page', 15 );
    333333                $request->set_param( 'orderby', 'id' );
    334                 $response = $this->server->dispatch( $request );
     334                $response = rest_get_server()->dispatch( $request );
    335335                $tags     = $response->get_data();
    336336
     
    346346                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    347347                $request->set_param( 'post', $post_id );
    348                 $response = $this->server->dispatch( $request );
     348                $response = rest_get_server()->dispatch( $request );
    349349                $this->assertEquals( 200, $response->get_status() );
    350350
     
    380380                $request = new WP_REST_Request( 'GET', '/wp/v2/batman' );
    381381                $request->set_param( 'post', $post_id );
    382                 $response = $this->server->dispatch( $request );
     382                $response = rest_get_server()->dispatch( $request );
    383383                $this->assertEquals( 200, $response->get_status() );
    384384
     
    397397                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    398398                $request->set_param( 'search', 'App' );
    399                 $response = $this->server->dispatch( $request );
     399                $response = rest_get_server()->dispatch( $request );
    400400                $this->assertEquals( 200, $response->get_status() );
    401401                $data = $response->get_data();
     
    404404                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    405405                $request->set_param( 'search', 'Garbage' );
    406                 $response = $this->server->dispatch( $request );
     406                $response = rest_get_server()->dispatch( $request );
    407407                $this->assertEquals( 200, $response->get_status() );
    408408                $data = $response->get_data();
     
    415415                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    416416                $request->set_param( 'slug', 'apple' );
    417                 $response = $this->server->dispatch( $request );
     417                $response = rest_get_server()->dispatch( $request );
    418418                $this->assertEquals( 200, $response->get_status() );
    419419                $data = $response->get_data();
     
    435435                        )
    436436                );
    437                 $response = $this->server->dispatch( $request );
     437                $response = rest_get_server()->dispatch( $request );
    438438                $this->assertEquals( 200, $response->get_status() );
    439439                $data  = $response->get_data();
     
    450450                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    451451                $request->set_param( 'slug', 'taco,burrito, enchilada' );
    452                 $response = $this->server->dispatch( $request );
     452                $response = rest_get_server()->dispatch( $request );
    453453                $this->assertEquals( 200, $response->get_status() );
    454454                $data  = $response->get_data();
     
    474474
    475475                $request  = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' );
    476                 $response = $this->server->dispatch( $request );
     476                $response = rest_get_server()->dispatch( $request );
    477477                $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    478478        }
     
    488488                }
    489489                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    490                 $response = $this->server->dispatch( $request );
     490                $response = rest_get_server()->dispatch( $request );
    491491                $headers  = $response->get_headers();
    492492                $this->assertEquals( 50, $headers['X-WP-Total'] );
     
    507507                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    508508                $request->set_param( 'page', 3 );
    509                 $response = $this->server->dispatch( $request );
     509                $response = rest_get_server()->dispatch( $request );
    510510                $headers  = $response->get_headers();
    511511                $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    526526                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    527527                $request->set_param( 'page', 6 );
    528                 $response = $this->server->dispatch( $request );
     528                $response = rest_get_server()->dispatch( $request );
    529529                $headers  = $response->get_headers();
    530530                $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    540540                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    541541                $request->set_param( 'page', 8 );
    542                 $response = $this->server->dispatch( $request );
     542                $response = rest_get_server()->dispatch( $request );
    543543                $headers  = $response->get_headers();
    544544                $this->assertEquals( 51, $headers['X-WP-Total'] );
     
    556556                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    557557                $request->set_param( 'context', 'banana' );
    558                 $response = $this->server->dispatch( $request );
     558                $response = rest_get_server()->dispatch( $request );
    559559                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    560560        }
     
    563563                $id       = $this->factory->tag->create();
    564564                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id );
    565                 $response = $this->server->dispatch( $request );
     565                $response = rest_get_server()->dispatch( $request );
    566566                $this->check_get_taxonomy_term_response( $response, $id );
    567567        }
     
    569569        public function test_get_term_invalid_term() {
    570570                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    571                 $response = $this->server->dispatch( $request );
     571                $response = rest_get_server()->dispatch( $request );
    572572                $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    573573        }
     
    578578                $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id );
    579579                $request->set_param( 'context', 'edit' );
    580                 $response = $this->server->dispatch( $request );
     580                $response = rest_get_server()->dispatch( $request );
    581581                $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    582582        }
     
    592592
    593593                $request  = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 );
    594                 $response = $this->server->dispatch( $request );
     594                $response = rest_get_server()->dispatch( $request );
    595595                $this->assertErrorResponse( 'rest_no_route', $response, 404 );
    596596        }
     
    605605                );
    606606                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term1 );
    607                 $response = $this->server->dispatch( $request );
     607                $response = rest_get_server()->dispatch( $request );
    608608                $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    609609        }
     
    615615                $request->set_param( 'description', 'This term is so awesome.' );
    616616                $request->set_param( 'slug', 'so-awesome' );
    617                 $response = $this->server->dispatch( $request );
     617                $response = rest_get_server()->dispatch( $request );
    618618                $this->assertEquals( 201, $response->get_status() );
    619619                $headers = $response->get_headers();
     
    629629                $request = new WP_REST_Request( 'POST', '/wp/v2/tags' );
    630630                $request->set_param( 'name', 'Incorrect permissions' );
    631                 $response = $this->server->dispatch( $request );
     631                $response = rest_get_server()->dispatch( $request );
    632632                $this->assertErrorResponse( 'rest_cannot_create', $response, 403 );
    633633        }
     
    636636                wp_set_current_user( self::$administrator );
    637637                $request  = new WP_REST_Request( 'POST', '/wp/v2/tags' );
    638                 $response = $this->server->dispatch( $request );
     638                $response = rest_get_server()->dispatch( $request );
    639639                $this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 );
    640640        }
     
    646646                $request->set_param( 'name', 'My Awesome Term' );
    647647                $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    648                 $response = $this->server->dispatch( $request );
     648                $response = rest_get_server()->dispatch( $request );
    649649                $this->assertErrorResponse( 'rest_taxonomy_not_hierarchical', $response, 400 );
    650650        }
     
    662662                $request->set_param( 'description', 'New Description' );
    663663                $request->set_param( 'slug', 'new-slug' );
    664                 $response = $this->server->dispatch( $request );
     664                $response = rest_get_server()->dispatch( $request );
    665665                $this->assertEquals( 200, $response->get_status() );
    666666                $data = $response->get_data();
     
    676676                $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id );
    677677
    678                 $response = $this->server->dispatch( $request );
     678                $response = rest_get_server()->dispatch( $request );
    679679                $this->assertEquals( 200, $response->get_status() );
    680680                $request->set_param( 'slug', $term->slug );
     
    682682                // Run twice to make sure that the update still succeeds even if no DB
    683683                // rows are updated.
    684                 $response = $this->server->dispatch( $request );
    685                 $this->assertEquals( 200, $response->get_status() );
    686 
    687                 $response = $this->server->dispatch( $request );
     684                $response = rest_get_server()->dispatch( $request );
     685                $this->assertEquals( 200, $response->get_status() );
     686
     687                $response = rest_get_server()->dispatch( $request );
    688688                $this->assertEquals( 200, $response->get_status() );
    689689        }
     
    693693                $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    694694                $request->set_param( 'name', 'Invalid Term' );
    695                 $response = $this->server->dispatch( $request );
     695                $response = rest_get_server()->dispatch( $request );
    696696                $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    697697        }
     
    702702                $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id );
    703703                $request->set_param( 'name', 'Incorrect permissions' );
    704                 $response = $this->server->dispatch( $request );
     704                $response = rest_get_server()->dispatch( $request );
    705705                $this->assertErrorResponse( 'rest_cannot_update', $response, 403 );
    706706        }
     
    716716
    717717                add_filter( 'map_meta_cap', array( $this, 'grant_edit_term' ), 10, 2 );
    718                 $response = $this->server->dispatch( $request );
     718                $response = rest_get_server()->dispatch( $request );
    719719                remove_filter( 'user_has_cap', array( $this, 'grant_edit_term' ), 10, 2 );
    720720
     
    741741
    742742                add_filter( 'map_meta_cap', array( $this, 'revoke_edit_term' ), 10, 2 );
    743                 $response = $this->server->dispatch( $request );
     743                $response = rest_get_server()->dispatch( $request );
    744744                remove_filter( 'user_has_cap', array( $this, 'revoke_edit_term' ), 10, 2 );
    745745
     
    760760                $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id );
    761761                $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    762                 $response = $this->server->dispatch( $request );
     762                $response = rest_get_server()->dispatch( $request );
    763763                $this->assertErrorResponse( 'rest_taxonomy_not_hierarchical', $response, 400 );
    764764        }
     
    770770                        $request->set_param( $name, $value );
    771771                }
    772                 $response = $this->server->dispatch( $request );
     772                $response = rest_get_server()->dispatch( $request );
    773773                $this->assertEquals( 201, $response->get_status() );
    774774                $actual_output = $response->get_data();
     
    788788                        $request->set_param( $name, $value );
    789789                }
    790                 $response = $this->server->dispatch( $request );
     790                $response = rest_get_server()->dispatch( $request );
    791791                $this->assertEquals( 200, $response->get_status() );
    792792                $actual_output = $response->get_data();
     
    876876                $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
    877877                $request->set_param( 'force', true );
    878                 $response = $this->server->dispatch( $request );
     878                $response = rest_get_server()->dispatch( $request );
    879879                $this->assertEquals( 200, $response->get_status() );
    880880                $data = $response->get_data();
     
    888888
    889889                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
    890                 $response = $this->server->dispatch( $request );
     890                $response = rest_get_server()->dispatch( $request );
    891891                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    892892
    893893                $request->set_param( 'force', 'false' );
    894                 $response = $this->server->dispatch( $request );
     894                $response = rest_get_server()->dispatch( $request );
    895895                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    896896        }
     
    899899                wp_set_current_user( self::$administrator );
    900900                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    901                 $response = $this->server->dispatch( $request );
     901                $response = rest_get_server()->dispatch( $request );
    902902                $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
    903903        }
     
    907907                $term     = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );
    908908                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
    909                 $response = $this->server->dispatch( $request );
     909                $response = rest_get_server()->dispatch( $request );
    910910                $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
    911911        }
     
    921921
    922922                add_filter( 'map_meta_cap', array( $this, 'grant_delete_term' ), 10, 2 );
    923                 $response = $this->server->dispatch( $request );
     923                $response = rest_get_server()->dispatch( $request );
    924924                remove_filter( 'map_meta_cap', array( $this, 'grant_delete_term' ), 10, 2 );
    925925
     
    947947
    948948                add_filter( 'map_meta_cap', array( $this, 'revoke_delete_term' ), 10, 2 );
    949                 $response = $this->server->dispatch( $request );
     949                $response = rest_get_server()->dispatch( $request );
    950950                remove_filter( 'map_meta_cap', array( $this, 'revoke_delete_term' ), 10, 2 );
    951951
     
    963963                $term     = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );
    964964                $request  = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term->term_id );
    965                 $response = $this->server->dispatch( $request );
     965                $response = rest_get_server()->dispatch( $request );
    966966                $data     = $response->get_data();
    967967
     
    971971        public function test_get_item_schema() {
    972972                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );
    973                 $response   = $this->server->dispatch( $request );
     973                $response   = rest_get_server()->dispatch( $request );
    974974                $data       = $response->get_data();
    975975                $properties = $data['schema']['properties'];
     
    988988        public function test_get_item_schema_non_hierarchical() {
    989989                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );
    990                 $response   = $this->server->dispatch( $request );
     990                $response   = rest_get_server()->dispatch( $request );
    991991                $data       = $response->get_data();
    992992                $properties = $data['schema']['properties'];
     
    10131013                $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );
    10141014
    1015                 $response = $this->server->dispatch( $request );
     1015                $response = rest_get_server()->dispatch( $request );
    10161016                $data     = $response->get_data();
    10171017                $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
     
    10211021                $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $tag_id );
    10221022
    1023                 $response = $this->server->dispatch( $request );
     1023                $response = rest_get_server()->dispatch( $request );
    10241024                $this->assertArrayHasKey( 'my_custom_int', $response->data );
    10251025
     
    10541054                );
    10551055
    1056                 $response = $this->server->dispatch( $request );
     1056                $response = rest_get_server()->dispatch( $request );
    10571057
    10581058                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    10741074                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    10751075                $request->set_param( 'post', $p );
    1076                 $response = $this->server->dispatch( $request );
     1076                $response = rest_get_server()->dispatch( $request );
    10771077                $found_1  = wp_list_pluck( $response->data, 'id' );
    10781078
     
    10831083                $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
    10841084                $request->set_param( 'post', $p );
    1085                 $response = $this->server->dispatch( $request );
     1085                $response = rest_get_server()->dispatch( $request );
    10861086                $found_2  = wp_list_pluck( $response->data, 'id' );
    10871087
  • trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

    r42423 r42724  
    2727
    2828        public function test_register_routes() {
    29                 $routes = $this->server->get_routes();
     29                $routes = rest_get_server()->get_routes();
    3030
    3131                $this->assertArrayHasKey( '/wp/v2/taxonomies', $routes );
     
    3636                // Collection
    3737                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies' );
    38                 $response = $this->server->dispatch( $request );
     38                $response = rest_get_server()->dispatch( $request );
    3939                $data     = $response->get_data();
    4040                $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    4242                // Single
    4343                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies/post_tag' );
    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'] );
     
    5050        public function test_get_items() {
    5151                $request    = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );
    52                 $response   = $this->server->dispatch( $request );
     52                $response   = rest_get_server()->dispatch( $request );
    5353                $data       = $response->get_data();
    5454                $taxonomies = $this->get_public_taxonomies( get_taxonomies( '', 'objects' ) );
     
    6767                $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );
    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        }
     
    7474                $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );
    7575                $request->set_param( 'type', 'post' );
    76                 $response = $this->server->dispatch( $request );
     76                $response = rest_get_server()->dispatch( $request );
    7777                $this->check_taxonomies_for_type_response( 'post', $response );
    7878        }
     
    8181                $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );
    8282                $request->set_param( 'type', 'wingding' );
    83                 $response = $this->server->dispatch( $request );
     83                $response = rest_get_server()->dispatch( $request );
    8484                $this->assertEquals( 200, $response->get_status() );
    8585                $data = $response->get_data();
     
    8989        public function test_get_item() {
    9090                $request  = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' );
    91                 $response = $this->server->dispatch( $request );
     91                $response = rest_get_server()->dispatch( $request );
    9292                $this->check_taxonomy_object_response( 'view', $response );
    9393        }
     
    9898                $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' );
    9999                $request->set_param( 'context', 'edit' );
    100                 $response = $this->server->dispatch( $request );
     100                $response = rest_get_server()->dispatch( $request );
    101101                $this->check_taxonomy_object_response( 'edit', $response );
    102102        }
     
    106106                $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' );
    107107                $request->set_param( 'context', 'edit' );
    108                 $response = $this->server->dispatch( $request );
     108                $response = rest_get_server()->dispatch( $request );
    109109                $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    110110        }
     
    112112        public function test_get_invalid_taxonomy() {
    113113                $request  = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/invalid' );
    114                 $response = $this->server->dispatch( $request );
     114                $response = rest_get_server()->dispatch( $request );
    115115                $this->assertErrorResponse( 'rest_taxonomy_invalid', $response, 404 );
    116116        }
     
    120120
    121121                $request  = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/api-private' );
    122                 $response = $this->server->dispatch( $request );
     122                $response = rest_get_server()->dispatch( $request );
    123123                $this->assertErrorResponse( 'rest_forbidden', $response, 401 );
    124124        }
     
    129129
    130130                $request  = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/api-private' );
    131                 $response = $this->server->dispatch( $request );
     131                $response = rest_get_server()->dispatch( $request );
    132132                $this->assertErrorResponse( 'rest_forbidden', $response, 403 );
    133133        }
     
    136136                /** Taxonomies can't be created */
    137137                $request  = new WP_REST_Request( 'POST', '/wp/v2/taxonomies' );
    138                 $response = $this->server->dispatch( $request );
     138                $response = rest_get_server()->dispatch( $request );
    139139                $this->assertEquals( 404, $response->get_status() );
    140140        }
     
    143143                /** Taxonomies can't be updated */
    144144                $request  = new WP_REST_Request( 'POST', '/wp/v2/taxonomies/category' );
    145                 $response = $this->server->dispatch( $request );
     145                $response = rest_get_server()->dispatch( $request );
    146146                $this->assertEquals( 404, $response->get_status() );
    147147        }
     
    150150                /** Taxonomies can't be deleted */
    151151                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/taxonomies/category' );
    152                 $response = $this->server->dispatch( $request );
     152                $response = rest_get_server()->dispatch( $request );
    153153                $this->assertEquals( 404, $response->get_status() );
    154154        }
     
    165165        public function test_get_item_schema() {
    166166                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies' );
    167                 $response   = $this->server->dispatch( $request );
     167                $response   = rest_get_server()->dispatch( $request );
    168168                $data       = $response->get_data();
    169169                $properties = $data['schema']['properties'];
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r42343 r42724  
    124124
    125125        public function test_register_routes() {
    126                 $routes = $this->server->get_routes();
     126                $routes = rest_get_server()->get_routes();
    127127
    128128                $this->assertArrayHasKey( '/wp/v2/users', $routes );
     
    136136                // Collection
    137137                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    138                 $response = $this->server->dispatch( $request );
     138                $response = rest_get_server()->dispatch( $request );
    139139                $data     = $response->get_data();
    140140                $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    142142                // Single
    143143                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user );
    144                 $response = $this->server->dispatch( $request );
     144                $response = rest_get_server()->dispatch( $request );
    145145                $data     = $response->get_data();
    146146                $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    150150        public function test_registered_query_params() {
    151151                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    152                 $response = $this->server->dispatch( $request );
     152                $response = rest_get_server()->dispatch( $request );
    153153                $data     = $response->get_data();
    154154                $keys     = array_keys( $data['endpoints'][0]['args'] );
     
    176176                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    177177                $request->set_param( 'context', 'view' );
    178                 $response = $this->server->dispatch( $request );
     178                $response = rest_get_server()->dispatch( $request );
    179179
    180180                $this->assertEquals( 200, $response->get_status() );
     
    191191                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    192192                $request->set_param( 'context', 'edit' );
    193                 $response = $this->server->dispatch( $request );
     193                $response = rest_get_server()->dispatch( $request );
    194194
    195195                $this->assertEquals( 200, $response->get_status() );
     
    205205                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    206206                $request->set_param( 'context', 'edit' );
    207                 $response = $this->server->dispatch( $request );
     207                $response = rest_get_server()->dispatch( $request );
    208208
    209209                $this->assertEquals( 401, $response->get_status() );
     
    213213                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    214214                $request->set_param( 'context', 'edit' );
    215                 $response = $this->server->dispatch( $request );
     215                $response = rest_get_server()->dispatch( $request );
    216216
    217217                $this->assertEquals( 403, $response->get_status() );
     
    220220        public function test_get_items_unauthenticated_includes_authors_of_post_types_shown_in_rest() {
    221221                $request  = new WP_REST_Request( 'GET', '/wp/v2/users' );
    222                 $response = $this->server->dispatch( $request );
     222                $response = rest_get_server()->dispatch( $request );
    223223                $users    = $response->get_data();
    224224
     
    251251        public function test_get_items_unauthenticated_does_not_include_authors_of_post_types_not_shown_in_rest() {
    252252                $request  = new WP_REST_Request( 'GET', '/wp/v2/users' );
    253                 $response = $this->server->dispatch( $request );
     253                $response = rest_get_server()->dispatch( $request );
    254254                $users    = $response->get_data();
    255255                $user_ids = wp_list_pluck( $users, 'id' );
     
    261261        public function test_get_items_unauthenticated_does_not_include_users_without_published_posts() {
    262262                $request  = new WP_REST_Request( 'GET', '/wp/v2/users' );
    263                 $response = $this->server->dispatch( $request );
     263                $response = rest_get_server()->dispatch( $request );
    264264                $users    = $response->get_data();
    265265                $user_ids = wp_list_pluck( $users, 'id' );
     
    279279                }
    280280                $request  = new WP_REST_Request( 'GET', '/wp/v2/users' );
    281                 $response = $this->server->dispatch( $request );
     281                $response = rest_get_server()->dispatch( $request );
    282282                $headers  = $response->get_headers();
    283283                $this->assertEquals( 53, $headers['X-WP-Total'] );
     
    298298                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    299299                $request->set_param( 'page', 3 );
    300                 $response = $this->server->dispatch( $request );
     300                $response = rest_get_server()->dispatch( $request );
    301301                $headers  = $response->get_headers();
    302302                $this->assertEquals( 54, $headers['X-WP-Total'] );
     
    317317                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    318318                $request->set_param( 'page', 6 );
    319                 $response = $this->server->dispatch( $request );
     319                $response = rest_get_server()->dispatch( $request );
    320320                $headers  = $response->get_headers();
    321321                $this->assertEquals( 54, $headers['X-WP-Total'] );
     
    331331                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    332332                $request->set_param( 'page', 8 );
    333                 $response = $this->server->dispatch( $request );
     333                $response = rest_get_server()->dispatch( $request );
    334334                $headers  = $response->get_headers();
    335335                $this->assertEquals( 54, $headers['X-WP-Total'] );
     
    350350                }
    351351                $request  = new WP_REST_Request( 'GET', '/wp/v2/users' );
    352                 $response = $this->server->dispatch( $request );
     352                $response = rest_get_server()->dispatch( $request );
    353353                $this->assertEquals( 10, count( $response->get_data() ) );
    354354                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    355355                $request->set_param( 'per_page', 5 );
    356                 $response = $this->server->dispatch( $request );
     356                $response = rest_get_server()->dispatch( $request );
    357357                $this->assertEquals( 5, count( $response->get_data() ) );
    358358        }
     
    366366                $request->set_param( 'per_page', 5 );
    367367                $request->set_param( 'page', 2 );
    368                 $response = $this->server->dispatch( $request );
     368                $response = rest_get_server()->dispatch( $request );
    369369                $this->assertEquals( 5, count( $response->get_data() ) );
    370370                $prev_link = add_query_arg(
     
    387387                $request->set_param( 'order', 'desc' );
    388388                $request->set_param( 'per_page', 1 );
    389                 $response = $this->server->dispatch( $request );
     389                $response = rest_get_server()->dispatch( $request );
    390390                $data     = $response->get_data();
    391391                $this->assertEquals( $high_id, $data[0]['id'] );
     
    394394                $request->set_param( 'order', 'asc' );
    395395                $request->set_param( 'per_page', 1 );
    396                 $response = $this->server->dispatch( $request );
     396                $response = rest_get_server()->dispatch( $request );
    397397                $data     = $response->get_data();
    398398                $this->assertEquals( $low_id, $data[0]['id'] );
     
    410410                $request->set_param( 'per_page', 1 );
    411411                $request->set_param( 'include', array( $low_id, $high_id ) );
    412                 $response = $this->server->dispatch( $request );
     412                $response = rest_get_server()->dispatch( $request );
    413413                $data     = $response->get_data();
    414414
     
    420420                $request->set_param( 'per_page', 1 );
    421421                $request->set_param( 'include', array( $low_id, $high_id ) );
    422                 $response = $this->server->dispatch( $request );
     422                $response = rest_get_server()->dispatch( $request );
    423423                $data     = $response->get_data();
    424424                $this->assertEquals( $low_id, $data[0]['id'] );
     
    436436                $request->set_param( 'per_page', 1 );
    437437                $request->set_param( 'include', array( $low_id, $high_id ) );
    438                 $response = $this->server->dispatch( $request );
     438                $response = rest_get_server()->dispatch( $request );
    439439                $data     = $response->get_data();
    440440
     
    446446                $request->set_param( 'per_page', 1 );
    447447                $request->set_param( 'include', array( $low_id, $high_id ) );
    448                 $response = $this->server->dispatch( $request );
     448                $response = rest_get_server()->dispatch( $request );
    449449                $data     = $response->get_data();
    450450                $this->assertEquals( $low_id, $data[0]['id'] );
     
    461461                $request->set_param( 'orderby', 'include_slugs' );
    462462                $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) );
    463                 $response = $this->server->dispatch( $request );
     463                $response = rest_get_server()->dispatch( $request );
    464464                $data     = $response->get_data();
    465465
     
    480480                $request->set_param( 'per_page', 1 );
    481481                $request->set_param( 'include', array( $low_id, $high_id ) );
    482                 $response = $this->server->dispatch( $request );
     482                $response = rest_get_server()->dispatch( $request );
    483483                $data     = $response->get_data();
    484484                $this->assertEquals( $high_id, $data[0]['id'] );
     
    489489                $request->set_param( 'per_page', 1 );
    490490                $request->set_param( 'include', array( $low_id, $high_id ) );
    491                 $response = $this->server->dispatch( $request );
     491                $response = rest_get_server()->dispatch( $request );
    492492                $data     = $response->get_data();
    493493                $this->assertEquals( $low_id, $data[0]['id'] );
     
    498498                $request->set_param( 'orderby', 'email' );
    499499                $request->set_param( 'order', 'desc' );
    500                 $response = $this->server->dispatch( $request );
     500                $response = rest_get_server()->dispatch( $request );
    501501                $this->assertErrorResponse( 'rest_forbidden_orderby', $response, 401 );
    502502        }
     
    506506                $request->set_param( 'orderby', 'registered_date' );
    507507                $request->set_param( 'order', 'desc' );
    508                 $response = $this->server->dispatch( $request );
     508                $response = rest_get_server()->dispatch( $request );
    509509                $this->assertErrorResponse( 'rest_forbidden_orderby', $response, 401 );
    510510        }
     
    513513                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    514514                $request->set_param( 'order', 'asc,id' );
    515                 $response = $this->server->dispatch( $request );
     515                $response = rest_get_server()->dispatch( $request );
    516516                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    517517        }
     
    520520                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    521521                $request->set_param( 'orderby', 'invalid' );
    522                 $response = $this->server->dispatch( $request );
     522                $response = rest_get_server()->dispatch( $request );
    523523                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    524524        }
     
    530530                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    531531                $request->set_param( 'offset', 1 );
    532                 $response = $this->server->dispatch( $request );
     532                $response = rest_get_server()->dispatch( $request );
    533533                $this->assertCount( 9, $response->get_data() );
    534534                // 'offset' works with 'per_page'
    535535                $request->set_param( 'per_page', 2 );
    536                 $response = $this->server->dispatch( $request );
     536                $response = rest_get_server()->dispatch( $request );
    537537                $this->assertCount( 2, $response->get_data() );
    538538                // 'offset' takes priority over 'page'
    539539                $request->set_param( 'page', 3 );
    540                 $response = $this->server->dispatch( $request );
     540                $response = rest_get_server()->dispatch( $request );
    541541                $this->assertCount( 2, $response->get_data() );
    542542                // 'offset' invalid value should error
    543543                $request->set_param( 'offset', 'moreplease' );
    544                 $response = $this->server->dispatch( $request );
     544                $response = rest_get_server()->dispatch( $request );
    545545                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    546546        }
     
    554554                // Orderby=>asc
    555555                $request->set_param( 'include', array( $id3, $id1 ) );
    556                 $response = $this->server->dispatch( $request );
     556                $response = rest_get_server()->dispatch( $request );
    557557                $data     = $response->get_data();
    558558                $this->assertEquals( 2, count( $data ) );
     
    560560                // Orderby=>include
    561561                $request->set_param( 'orderby', 'include' );
    562                 $response = $this->server->dispatch( $request );
     562                $response = rest_get_server()->dispatch( $request );
    563563                $data     = $response->get_data();
    564564                $this->assertEquals( 2, count( $data ) );
     
    566566                // Invalid include should fail
    567567                $request->set_param( 'include', 'invalid' );
    568                 $response = $this->server->dispatch( $request );
     568                $response = rest_get_server()->dispatch( $request );
    569569                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    570570                // No privileges
    571571                $request->set_param( 'include', array( $id3, $id1 ) );
    572572                wp_set_current_user( 0 );
    573                 $response = $this->server->dispatch( $request );
     573                $response = rest_get_server()->dispatch( $request );
    574574                $data     = $response->get_data();
    575575                $this->assertEquals( 0, count( $data ) );
     
    583583                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    584584                $request->set_param( 'per_page', 20 ); // there are >10 users at this point
    585                 $response = $this->server->dispatch( $request );
     585                $response = rest_get_server()->dispatch( $request );
    586586                $data     = $response->get_data();
    587587                $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    588588                $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
    589589                $request->set_param( 'exclude', array( $id2 ) );
    590                 $response = $this->server->dispatch( $request );
     590                $response = rest_get_server()->dispatch( $request );
    591591                $data     = $response->get_data();
    592592                $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     
    594594                // Invalid exlude value should error.
    595595                $request->set_param( 'exclude', 'none-of-those-please' );
    596                 $response = $this->server->dispatch( $request );
     596                $response = rest_get_server()->dispatch( $request );
    597597                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    598598        }
     
    602602                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    603603                $request->set_param( 'search', 'yololololo' );
    604                 $response = $this->server->dispatch( $request );
     604                $response = rest_get_server()->dispatch( $request );
    605605                $this->assertEquals( 0, count( $response->get_data() ) );
    606606                $yolo_id = $this->factory->user->create( array( 'display_name' => 'yololololo' ) );
    607607                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    608608                $request->set_param( 'search', 'yololololo' );
    609                 $response = $this->server->dispatch( $request );
     609                $response = rest_get_server()->dispatch( $request );
    610610                $this->assertEquals( 1, count( $response->get_data() ) );
    611611                // default to wildcard search
     
    618618                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    619619                $request->set_param( 'search', 'ada' );
    620                 $response = $this->server->dispatch( $request );
     620                $response = rest_get_server()->dispatch( $request );
    621621                $data     = $response->get_data();
    622622                $this->assertEquals( 1, count( $data ) );
     
    640640                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    641641                $request->set_param( 'slug', 'foo' );
    642                 $response = $this->server->dispatch( $request );
     642                $response = rest_get_server()->dispatch( $request );
    643643                $data     = $response->get_data();
    644644                $this->assertEquals( 1, count( $data ) );
     
    682682                $request->set_param( 'orderby', 'slug' );
    683683                $request->set_param( 'order', 'asc' );
    684                 $response = $this->server->dispatch( $request );
     684                $response = rest_get_server()->dispatch( $request );
    685685                $this->assertEquals( 200, $response->get_status() );
    686686                $data  = $response->get_data();
     
    719719                $request->set_param( 'orderby', 'slug' );
    720720                $request->set_param( 'order', 'desc' );
    721                 $response = $this->server->dispatch( $request );
     721                $response = rest_get_server()->dispatch( $request );
    722722                $this->assertEquals( 200, $response->get_status() );
    723723                $data  = $response->get_data();
     
    743743                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    744744                $request->set_param( 'roles', 'author,subscriber' );
    745                 $response = $this->server->dispatch( $request );
     745                $response = rest_get_server()->dispatch( $request );
    746746                $data     = $response->get_data();
    747747                $this->assertEquals( 2, count( $data ) );
     
    749749                $this->assertEquals( $yolo, $data[1]['id'] );
    750750                $request->set_param( 'roles', 'author' );
    751                 $response = $this->server->dispatch( $request );
     751                $response = rest_get_server()->dispatch( $request );
    752752                $data     = $response->get_data();
    753753                $this->assertEquals( 1, count( $data ) );
     
    755755                wp_set_current_user( 0 );
    756756                $request->set_param( 'roles', 'author' );
    757                 $response = $this->server->dispatch( $request );
     757                $response = rest_get_server()->dispatch( $request );
    758758                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 );
    759759                wp_set_current_user( self::$editor );
    760760                $request->set_param( 'roles', 'author' );
    761                 $response = $this->server->dispatch( $request );
     761                $response = rest_get_server()->dispatch( $request );
    762762                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 );
    763763        }
     
    773773                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    774774                $request->set_param( 'roles', 'ilovesteak,author' );
    775                 $response = $this->server->dispatch( $request );
     775                $response = rest_get_server()->dispatch( $request );
    776776                $data     = $response->get_data();
    777777                $this->assertEquals( 1, count( $data ) );
     
    779779                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    780780                $request->set_param( 'roles', 'steakisgood' );
    781                 $response = $this->server->dispatch( $request );
     781                $response = rest_get_server()->dispatch( $request );
    782782                $data     = $response->get_data();
    783783                $this->assertEquals( 0, count( $data ) );
     
    791791                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $user_id ) );
    792792
    793                 $response = $this->server->dispatch( $request );
     793                $response = rest_get_server()->dispatch( $request );
    794794                $this->check_get_user_response( $response, 'embed' );
    795795        }
     
    809809                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$editor ) );
    810810
    811                 $response = $this->server->dispatch( $request );
     811                $response = rest_get_server()->dispatch( $request );
    812812
    813813                $data = $response->get_data();
     
    827827                wp_set_current_user( self::$user );
    828828                $request  = new WP_REST_Request( 'GET', '/wp/v2/users/100' );
    829                 $response = $this->server->dispatch( $request );
     829                $response = rest_get_server()->dispatch( $request );
    830830
    831831                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
     
    846846                $request = new WP_REST_Request( 'GET', '/wp/v2/users/' . $lolz );
    847847                $request->set_param( 'context', 'edit' );
    848                 $response = $this->server->dispatch( $request );
     848                $response = rest_get_server()->dispatch( $request );
    849849
    850850                if ( is_multisite() ) {
     
    861861                wp_set_current_user( self::$editor );
    862862                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$user ) );
    863                 $response = $this->server->dispatch( $request );
     863                $response = rest_get_server()->dispatch( $request );
    864864                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 );
    865865        }
     
    867867        public function test_can_get_item_author_of_rest_true_public_true_unauthenticated() {
    868868                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) );
    869                 $response = $this->server->dispatch( $request );
     869                $response = rest_get_server()->dispatch( $request );
    870870                $this->assertEquals( 200, $response->get_status() );
    871871        }
     
    874874                wp_set_current_user( self::$editor );
    875875                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) );
    876                 $response = $this->server->dispatch( $request );
     876                $response = rest_get_server()->dispatch( $request );
    877877                $this->assertEquals( 200, $response->get_status() );
    878878        }
     
    880880        public function test_can_get_item_author_of_rest_true_public_false() {
    881881                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_false'] ) );
    882                 $response = $this->server->dispatch( $request );
     882                $response = rest_get_server()->dispatch( $request );
    883883                $this->assertEquals( 200, $response->get_status() );
    884884        }
     
    886886        public function test_cannot_get_item_author_of_rest_false_public_true_unauthenticated() {
    887887                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) );
    888                 $response = $this->server->dispatch( $request );
     888                $response = rest_get_server()->dispatch( $request );
    889889                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 );
    890890        }
     
    893893                wp_set_current_user( self::$editor );
    894894                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) );
    895                 $response = $this->server->dispatch( $request );
     895                $response = rest_get_server()->dispatch( $request );
    896896                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 );
    897897        }
     
    899899        public function test_cannot_get_item_author_of_rest_false_public_false() {
    900900                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_false'] ) );
    901                 $response = $this->server->dispatch( $request );
     901                $response = rest_get_server()->dispatch( $request );
    902902                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 );
    903903        }
     
    905905        public function test_can_get_item_author_of_post() {
    906906                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$editor ) );
    907                 $response = $this->server->dispatch( $request );
     907                $response = rest_get_server()->dispatch( $request );
    908908                $this->assertEquals( 200, $response->get_status() );
    909909        }
     
    911911        public function test_cannot_get_item_author_of_draft() {
    912912                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$draft_editor ) );
    913                 $response = $this->server->dispatch( $request );
     913                $response = rest_get_server()->dispatch( $request );
    914914                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 );
    915915        }
     
    928928                wp_set_current_user( 0 );
    929929                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );
    930                 $response = $this->server->dispatch( $request );
     930                $response = rest_get_server()->dispatch( $request );
    931931                $this->check_get_user_response( $response, 'embed' );
    932932        }
     
    940940                wp_set_current_user( 0 );
    941941                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );
    942                 $response = $this->server->dispatch( $request );
     942                $response = rest_get_server()->dispatch( $request );
    943943                $this->assertEquals( 401, $response->get_status() );
    944944                $this->post_id = $this->factory->post->create(
     
    948948                        )
    949949                );
    950                 $response      = $this->server->dispatch( $request );
     950                $response      = rest_get_server()->dispatch( $request );
    951951                $this->check_get_user_response( $response, 'embed' );
    952952        }
     
    959959                $request->set_param( 'context', 'edit' );
    960960
    961                 $response = $this->server->dispatch( $request );
     961                $response = rest_get_server()->dispatch( $request );
    962962                $this->check_get_user_response( $response, 'edit' );
    963963        }
     
    977977                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );
    978978                $request->set_param( 'context', 'edit' );
    979                 $response = $this->server->dispatch( $request );
     979                $response = rest_get_server()->dispatch( $request );
    980980                $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 );
    981981        }
     
    986986                $request = new WP_REST_Request( 'GET', '/wp/v2/users/me' );
    987987
    988                 $response = $this->server->dispatch( $request );
     988                $response = rest_get_server()->dispatch( $request );
    989989                $this->assertEquals( 200, $response->get_status() );
    990990                $this->check_get_user_response( $response, 'view' );
     
    10001000                wp_set_current_user( 0 );
    10011001                $request  = new WP_REST_Request( 'GET', '/wp/v2/users/me' );
    1002                 $response = $this->server->dispatch( $request );
     1002                $response = rest_get_server()->dispatch( $request );
    10031003
    10041004                $this->assertErrorResponse( 'rest_not_logged_in', $response, 401 );
     
    10251025                $request->set_body_params( $params );
    10261026
    1027                 $response = $this->server->dispatch( $request );
     1027                $response = rest_get_server()->dispatch( $request );
    10281028                $data     = $response->get_data();
    10291029                $this->assertEquals( 'http://example.com', $data['url'] );
     
    10571057                $request->set_body_params( $params );
    10581058
    1059                 $response = $this->server->dispatch( $request );
     1059                $response = rest_get_server()->dispatch( $request );
    10601060                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    10611061
     
    11011101                $request->set_body_params( $params );
    11021102
    1103                 $response = $this->server->dispatch( $request );
     1103                $response = rest_get_server()->dispatch( $request );
    11041104
    11051105                remove_filter( 'illegal_user_logins', array( $this, 'get_illegal_user_logins' ) );
     
    11311131                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    11321132                $request->set_body_params( $params );
    1133                 $response = $this->server->dispatch( $request );
     1133                $response = rest_get_server()->dispatch( $request );
    11341134                $data     = $response->get_data();
    11351135                $user_id  = $data['id'];
     
    11621162                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    11631163                $request->set_body_params( $params );
    1164                 $response = $this->server->dispatch( $request );
     1164                $response = rest_get_server()->dispatch( $request );
    11651165                $this->assertErrorResponse( 'user_cannot_be_added', $response );
    11661166        }
     
    11851185                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    11861186                $request->set_body_params( $params );
    1187                 $response = $this->server->dispatch( $request );
     1187                $response = rest_get_server()->dispatch( $request );
    11881188                $data     = $response->get_data();
    11891189                $user_id  = $data['id'];
     
    12151215                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    12161216                $request->set_body_params( $params );
    1217                 $response = $this->server->dispatch( $request );
     1217                $response = rest_get_server()->dispatch( $request );
    12181218                $data     = $response->get_data();
    12191219                $user_id  = $data['id'];
     
    12241224                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    12251225                $request->set_body_params( $params );
    1226                 $switched_response = $this->server->dispatch( $request );
     1226                $switched_response = rest_get_server()->dispatch( $request );
    12271227
    12281228                restore_current_blog();
     
    12601260                $request->set_body( wp_json_encode( $params ) );
    12611261
    1262                 $response = $this->server->dispatch( $request );
     1262                $response = rest_get_server()->dispatch( $request );
    12631263                $this->check_add_edit_user_response( $response );
    12641264        }
     
    12761276                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    12771277                $request->set_body_params( $params );
    1278                 $response = $this->server->dispatch( $request );
     1278                $response = rest_get_server()->dispatch( $request );
    12791279
    12801280                $this->assertErrorResponse( 'rest_cannot_create_user', $response, 403 );
     
    12951295                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    12961296                $request->set_body_params( $params );
    1297                 $response = $this->server->dispatch( $request );
     1297                $response = rest_get_server()->dispatch( $request );
    12981298
    12991299                $this->assertErrorResponse( 'rest_user_exists', $response, 400 );
     
    13131313                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    13141314                $request->set_body_params( $params );
    1315                 $response = $this->server->dispatch( $request );
     1315                $response = rest_get_server()->dispatch( $request );
    13161316
    13171317                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    13321332                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    13331333                $request->set_body_params( $params );
    1334                 $response = $this->server->dispatch( $request );
     1334                $response = rest_get_server()->dispatch( $request );
    13351335
    13361336                $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 );
     
    13641364                $request->set_body_params( $_POST );
    13651365
    1366                 $response = $this->server->dispatch( $request );
     1366                $response = rest_get_server()->dispatch( $request );
    13671367                $this->check_add_edit_user_response( $response, true );
    13681368
     
    13921392                // Run twice to make sure that the update still succeeds even if no DB
    13931393                // rows are updated.
    1394                 $response = $this->server->dispatch( $request );
     1394                $response = rest_get_server()->dispatch( $request );
    13951395                $this->assertEquals( 200, $response->get_status() );
    13961396
    1397                 $response = $this->server->dispatch( $request );
     1397                $response = rest_get_server()->dispatch( $request );
    13981398                $this->assertEquals( 200, $response->get_status() );
    13991399        }
     
    14171417                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user2 );
    14181418                $request->set_param( 'email', 'testjson@example.com' );
    1419                 $response = $this->server->dispatch( $request );
     1419                $response = rest_get_server()->dispatch( $request );
    14201420                $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    14211421                $this->assertEquals( 'rest_user_invalid_email', $response->as_error()->get_error_code() );
     
    14341434                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user1 );
    14351435                $request->set_param( 'locale', 'klingon' );
    1436                 $response = $this->server->dispatch( $request );
     1436                $response = rest_get_server()->dispatch( $request );
    14371437                $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    14381438                $this->assertEquals( 'rest_invalid_param', $response->as_error()->get_error_code() );
     
    14511451                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user_id );
    14521452                $request->set_param( 'locale', 'en_US' );
    1453                 $response = $this->server->dispatch( $request );
     1453                $response = rest_get_server()->dispatch( $request );
    14541454                $this->check_add_edit_user_response( $response, true );
    14551455
     
    14741474                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user_id );
    14751475                $request->set_param( 'locale', '' );
    1476                 $response = $this->server->dispatch( $request );
     1476                $response = rest_get_server()->dispatch( $request );
    14771477                $this->check_add_edit_user_response( $response, true );
    14781478
     
    15011501                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user2 );
    15021502                $request->set_param( 'username', 'test_json_user' );
    1503                 $response = $this->server->dispatch( $request );
     1503                $response = rest_get_server()->dispatch( $request );
    15041504                $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    15051505                $this->assertEquals( 'rest_user_invalid_argument', $response->as_error()->get_error_code() );
     
    15241524                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user2 );
    15251525                $request->set_param( 'slug', 'test_json_user' );
    1526                 $response = $this->server->dispatch( $request );
     1526                $response = rest_get_server()->dispatch( $request );
    15271527                $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    15281528                $this->assertEquals( 'rest_user_invalid_slug', $response->as_error()->get_error_code() );
     
    15561556                $request->set_body( wp_json_encode( $params ) );
    15571557
    1558                 $response = $this->server->dispatch( $request );
     1558                $response = rest_get_server()->dispatch( $request );
    15591559                $this->check_add_edit_user_response( $response, true );
    15601560
     
    15801580                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
    15811581                $request->set_param( 'roles', array( 'editor' ) );
    1582                 $response = $this->server->dispatch( $request );
     1582                $response = rest_get_server()->dispatch( $request );
    15831583
    15841584                $new_data = $response->get_data();
     
    16001600                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
    16011601                $request->set_param( 'roles', 'author,editor' );
    1602                 $response = $this->server->dispatch( $request );
     1602                $response = rest_get_server()->dispatch( $request );
    16031603
    16041604                $new_data = $response->get_data();
     
    16171617                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) );
    16181618                $request->set_param( 'roles', array( 'administrator' ) );
    1619                 $response = $this->server->dispatch( $request );
     1619                $response = rest_get_server()->dispatch( $request );
    16201620
    16211621                $this->assertErrorResponse( 'rest_cannot_edit_roles', $response, 403 );
     
    16261626                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' );
    16271627                $request->set_param( 'roles', array( 'administrator' ) );
    1628                 $response = $this->server->dispatch( $request );
     1628                $response = rest_get_server()->dispatch( $request );
    16291629
    16301630                $this->assertErrorResponse( 'rest_cannot_edit_roles', $response, 403 );
     
    16441644                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
    16451645                $request->set_param( 'roles', array( 'editor' ) );
    1646                 $response = $this->server->dispatch( $request );
     1646                $response = rest_get_server()->dispatch( $request );
    16471647
    16481648                $this->assertErrorResponse( 'rest_user_invalid_role', $response, 403 );
     
    16541654                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' );
    16551655                $request->set_param( 'roles', array( 'editor' ) );
    1656                 $response = $this->server->dispatch( $request );
     1656                $response = rest_get_server()->dispatch( $request );
    16571657
    16581658                $this->assertErrorResponse( 'rest_user_invalid_role', $response, 403 );
     
    16751675                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
    16761676                $request->set_param( 'roles', array( 'editor' ) );
    1677                 $response = $this->server->dispatch( $request );
     1677                $response = rest_get_server()->dispatch( $request );
    16781678
    16791679                $new_data = $response->get_data();
     
    16891689                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' );
    16901690                $request->set_param( 'roles', array( 'editor' ) );
    1691                 $response = $this->server->dispatch( $request );
     1691                $response = rest_get_server()->dispatch( $request );
    16921692
    16931693                $new_data = $response->get_data();
     
    17031703                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) );
    17041704                $request->set_param( 'roles', array( 'BeSharp' ) );
    1705                 $response = $this->server->dispatch( $request );
     1705                $response = rest_get_server()->dispatch( $request );
    17061706
    17071707                $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 );
     
    17131713                $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' );
    17141714                $request->set_param( 'roles', array( 'BeSharp' ) );
    1715                 $response = $this->server->dispatch( $request );
     1715                $response = rest_get_server()->dispatch( $request );
    17161716
    17171717                $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 );
     
    17341734                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    17351735                $request->set_body_params( $params );
    1736                 $response = $this->server->dispatch( $request );
     1736                $response = rest_get_server()->dispatch( $request );
    17371737
    17381738                $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
     
    17411741                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    17421742                $request->set_body_params( $params );
    1743                 $response = $this->server->dispatch( $request );
     1743                $response = rest_get_server()->dispatch( $request );
    17441744
    17451745                $this->assertErrorResponse( 'rest_user_invalid_argument', $response, 400 );
     
    17601760                $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    17611761                $request->set_body_params( $params );
    1762                 $response = $this->server->dispatch( $request );
     1762                $response = rest_get_server()->dispatch( $request );
    17631763
    17641764                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
     
    17781778                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
    17791779                $request->set_param( 'roles', array( 'editor' ) );
    1780                 $response = $this->server->dispatch( $request );
     1780                $response = rest_get_server()->dispatch( $request );
    17811781                $this->assertErrorResponse( 'rest_cannot_edit_roles', $response, 403 );
    17821782        }
     
    17951795                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
    17961796                $request->set_param( 'roles', array( 'editor' ) );
    1797                 $response = $this->server->dispatch( $request );
     1797                $response = rest_get_server()->dispatch( $request );
    17981798                $this->assertEquals( 200, $response->get_status() );
    17991799
     
    18161816                $request->set_param( 'roles', array( 'editor' ) );
    18171817                $request->set_param( 'name', 'Short-Lived User' );
    1818                 $response = $this->server->dispatch( $request );
     1818                $response = rest_get_server()->dispatch( $request );
    18191819
    18201820                if ( is_multisite() ) {
     
    18401840
    18411841                $request->set_param( 'password', 'no\\backslashes\\allowed' );
    1842                 $response = $this->server->dispatch( $request );
     1842                $response = rest_get_server()->dispatch( $request );
    18431843                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    18441844
    18451845                $request->set_param( 'password', '' );
    1846                 $response = $this->server->dispatch( $request );
     1846                $response = rest_get_server()->dispatch( $request );
    18471847                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    18481848        }
     
    18591859                        }
    18601860                        $request->set_param( 'email', 'cbg@androidsdungeon.com' );
    1861                         $response = $this->server->dispatch( $request );
     1861                        $response = rest_get_server()->dispatch( $request );
    18621862                        $this->assertEquals( 201, $response->get_status() );
    18631863                        $actual_output = $response->get_data();
     
    18931893                        }
    18941894                }
    1895                 $response = $this->server->dispatch( $request );
     1895                $response = rest_get_server()->dispatch( $request );
    18961896                $this->assertEquals( 200, $response->get_status() );
    18971897                $actual_output = $response->get_data();
     
    20602060                $request->set_param( 'force', true );
    20612061                $request->set_param( 'reassign', false );
    2062                 $response = $this->server->dispatch( $request );
     2062                $response = rest_get_server()->dispatch( $request );
    20632063
    20642064                // Not implemented in multisite.
     
    20842084                $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) );
    20852085                $request->set_param( 'reassign', false );
    2086                 $response = $this->server->dispatch( $request );
     2086                $response = rest_get_server()->dispatch( $request );
    20872087
    20882088                // Not implemented in multisite.
     
    20952095
    20962096                $request->set_param( 'force', 'false' );
    2097                 $response = $this->server->dispatch( $request );
     2097                $response = rest_get_server()->dispatch( $request );
    20982098                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    20992099
     
    21182118                $request['force'] = true;
    21192119                $request->set_param( 'reassign', false );
    2120                 $response = $this->server->dispatch( $request );
     2120                $response = rest_get_server()->dispatch( $request );
    21212121
    21222122                // Not implemented in multisite.
     
    21462146                $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' );
    21472147                $request->set_param( 'reassign', false );
    2148                 $response = $this->server->dispatch( $request );
     2148                $response = rest_get_server()->dispatch( $request );
    21492149
    21502150                // Not implemented in multisite.
     
    21572157
    21582158                $request->set_param( 'force', 'false' );
    2159                 $response = $this->server->dispatch( $request );
     2159                $response = rest_get_server()->dispatch( $request );
    21602160                $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    21612161
     
    21742174                $request['force'] = true;
    21752175                $request->set_param( 'reassign', false );
    2176                 $response = $this->server->dispatch( $request );
     2176                $response = rest_get_server()->dispatch( $request );
    21772177
    21782178                $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 );
     
    21812181                $request['force'] = true;
    21822182                $request->set_param( 'reassign', false );
    2183                 $response = $this->server->dispatch( $request );
     2183                $response = rest_get_server()->dispatch( $request );
    21842184
    21852185                $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 );
     
    21932193                $request['force'] = true;
    21942194                $request->set_param( 'reassign', false );
    2195                 $response = $this->server->dispatch( $request );
     2195                $response = rest_get_server()->dispatch( $request );
    21962196
    21972197                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
     
    22192219                $request['force'] = true;
    22202220                $request->set_param( 'reassign', $reassign_id );
    2221                 $response = $this->server->dispatch( $request );
     2221                $response = rest_get_server()->dispatch( $request );
    22222222
    22232223                // Not implemented in multisite.
     
    22432243                $request['force'] = true;
    22442244                $request->set_param( 'reassign', 100 );
    2245                 $response = $this->server->dispatch( $request );
     2245                $response = rest_get_server()->dispatch( $request );
    22462246
    22472247                // Not implemented in multisite.
     
    22632263                $request['force'] = true;
    22642264                $request->set_param( 'reassign', 'null' );
    2265                 $response = $this->server->dispatch( $request );
     2265                $response = rest_get_server()->dispatch( $request );
    22662266
    22672267                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    22832283                $request['force'] = true;
    22842284                $request->set_param( 'reassign', false );
    2285                 $response = $this->server->dispatch( $request );
     2285                $response = rest_get_server()->dispatch( $request );
    22862286
    22872287                // Not implemented in multisite.
     
    23102310                $request['force'] = true;
    23112311                $request->set_param( 'reassign', 'false' );
    2312                 $response = $this->server->dispatch( $request );
     2312                $response = rest_get_server()->dispatch( $request );
    23132313
    23142314                // Not implemented in multisite.
     
    23372337                $request['force'] = true;
    23382338                $request->set_param( 'reassign', '' );
    2339                 $response = $this->server->dispatch( $request );
     2339                $response = rest_get_server()->dispatch( $request );
    23402340
    23412341                // Not implemented in multisite.
     
    23642364                $request['force'] = true;
    23652365                $request->set_param( 'reassign', 0 );
    2366                 $response = $this->server->dispatch( $request );
     2366                $response = rest_get_server()->dispatch( $request );
    23672367
    23682368                // Not implemented in multisite.
     
    23782378        public function test_get_item_schema() {
    23792379                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    2380                 $response   = $this->server->dispatch( $request );
     2380                $response   = rest_get_server()->dispatch( $request );
    23812381                $data       = $response->get_data();
    23822382                $properties = $data['schema']['properties'];
     
    24082408                update_option( 'show_avatars', false );
    24092409                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    2410                 $response   = $this->server->dispatch( $request );
     2410                $response   = rest_get_server()->dispatch( $request );
    24112411                $data       = $response->get_data();
    24122412                $properties = $data['schema']['properties'];
     
    24342434                $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    24352435
    2436                 $response = $this->server->dispatch( $request );
     2436                $response = rest_get_server()->dispatch( $request );
    24372437                $data     = $response->get_data();
    24382438
     
    24482448                $request = new WP_REST_Request( 'GET', '/wp/v2/users/1' );
    24492449
    2450                 $response = $this->server->dispatch( $request );
     2450                $response = rest_get_server()->dispatch( $request );
    24512451                $this->assertArrayHasKey( 'my_custom_int', $response->data );
    24522452
     
    24582458                );
    24592459
    2460                 $response = $this->server->dispatch( $request );
     2460                $response = rest_get_server()->dispatch( $request );
    24612461                $this->assertEquals( 123, get_user_meta( 1, 'my_custom_int', true ) );
    24622462
     
    24712471                );
    24722472
    2473                 $response = $this->server->dispatch( $request );
     2473                $response = rest_get_server()->dispatch( $request );
    24742474
    24752475                $this->assertEquals( 123, $response->data['my_custom_int'] );
     
    25092509                );
    25102510
    2511                 $response = $this->server->dispatch( $request );
     2511                $response = rest_get_server()->dispatch( $request );
    25122512
    25132513                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    25332533                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $user_id ) );
    25342534
    2535                 $response = $this->server->dispatch( $request );
     2535                $response = rest_get_server()->dispatch( $request );
    25362536                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
    25372537        }
     
    25532553                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $user_id ) );
    25542554
    2555                 $response = $this->server->dispatch( $request );
     2555                $response = rest_get_server()->dispatch( $request );
    25562556                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
    25572557        }
     
    25752575                $request->set_body_params( array( 'first_name' => 'New Name' ) );
    25762576
    2577                 $response = $this->server->dispatch( $request );
     2577                $response = rest_get_server()->dispatch( $request );
    25782578                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
    25792579        }
     
    25972597                $request->set_body_params( array( 'first_name' => 'New Name' ) );
    25982598
    2599                 $response = $this->server->dispatch( $request );
     2599                $response = rest_get_server()->dispatch( $request );
    26002600                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
    26012601        }
     
    26192619                $request->set_param( 'reassign', false );
    26202620
    2621                 $response = $this->server->dispatch( $request );
     2621                $response = rest_get_server()->dispatch( $request );
    26222622                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
    26232623        }
     
    26412641                $request->set_param( 'reassign', false );
    26422642
    2643                 $response = $this->server->dispatch( $request );
     2643                $response = rest_get_server()->dispatch( $request );
    26442644                $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
    26452645        }
Note: See TracChangeset for help on using the changeset viewer.