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-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.