WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/21/2018 04:24:30 PM (19 months 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-revisions-controller.php

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