Make WordPress Core


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

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

Props danielbachhuber.
Fixes #41641.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-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 );
Note: See TracChangeset for help on using the changeset viewer.