Make WordPress Core


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

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

Props danielbachhuber.
Fixes #41641.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php

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