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-types-controller.php

    r42343 r42724  
    1313
    1414    public function test_register_routes() {
    15         $routes = $this->server->get_routes();
     15        $routes = rest_get_server()->get_routes();
    1616        $this->assertArrayHasKey( '/wp/v2/types', $routes );
    1717        $this->assertArrayHasKey( '/wp/v2/types/(?P<type>[\w-]+)', $routes );
     
    2121        // Collection
    2222        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' );
    23         $response = $this->server->dispatch( $request );
     23        $response = rest_get_server()->dispatch( $request );
    2424        $data     = $response->get_data();
    2525        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    2727        // Single
    2828        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/post' );
    29         $response = $this->server->dispatch( $request );
     29        $response = rest_get_server()->dispatch( $request );
    3030        $data     = $response->get_data();
    3131        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     
    3535    public function test_get_items() {
    3636        $request  = new WP_REST_Request( 'GET', '/wp/v2/types' );
    37         $response = $this->server->dispatch( $request );
     37        $response = rest_get_server()->dispatch( $request );
    3838
    3939        $data       = $response->get_data();
     
    5151        $request = new WP_REST_Request( 'GET', '/wp/v2/types' );
    5252        $request->set_param( 'context', 'edit' );
    53         $response = $this->server->dispatch( $request );
     53        $response = rest_get_server()->dispatch( $request );
    5454        $this->assertErrorResponse( 'rest_cannot_view', $response, 401 );
    5555    }
     
    5757    public function test_get_item() {
    5858        $request  = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    59         $response = $this->server->dispatch( $request );
     59        $response = rest_get_server()->dispatch( $request );
    6060        $this->check_post_type_object_response( 'view', $response );
    6161        $data = $response->get_data();
     
    6565    public function test_get_item_page() {
    6666        $request  = new WP_REST_Request( 'GET', '/wp/v2/types/page' );
    67         $response = $this->server->dispatch( $request );
     67        $response = rest_get_server()->dispatch( $request );
    6868        $this->check_post_type_object_response( 'view', $response, 'page' );
    6969        $data = $response->get_data();
     
    7373    public function test_get_item_invalid_type() {
    7474        $request  = new WP_REST_Request( 'GET', '/wp/v2/types/invalid' );
    75         $response = $this->server->dispatch( $request );
     75        $response = rest_get_server()->dispatch( $request );
    7676        $this->assertErrorResponse( 'rest_type_invalid', $response, 404 );
    7777    }
     
    8282        $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    8383        $request->set_param( 'context', 'edit' );
    84         $response = $this->server->dispatch( $request );
     84        $response = rest_get_server()->dispatch( $request );
    8585        $this->check_post_type_object_response( 'edit', $response );
    8686    }
     
    9090        $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    9191        $request->set_param( 'context', 'edit' );
    92         $response = $this->server->dispatch( $request );
     92        $response = rest_get_server()->dispatch( $request );
    9393        $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 );
    9494    }
     
    9797        /** Post types can't be created */
    9898        $request  = new WP_REST_Request( 'POST', '/wp/v2/types' );
    99         $response = $this->server->dispatch( $request );
     99        $response = rest_get_server()->dispatch( $request );
    100100        $this->assertEquals( 404, $response->get_status() );
    101101    }
     
    104104        /** Post types can't be updated */
    105105        $request  = new WP_REST_Request( 'POST', '/wp/v2/types/post' );
    106         $response = $this->server->dispatch( $request );
     106        $response = rest_get_server()->dispatch( $request );
    107107        $this->assertEquals( 404, $response->get_status() );
    108108    }
     
    111111        /** Post types can't be deleted */
    112112        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/types/post' );
    113         $response = $this->server->dispatch( $request );
     113        $response = rest_get_server()->dispatch( $request );
    114114        $this->assertEquals( 404, $response->get_status() );
    115115    }
     
    126126    public function test_get_item_schema() {
    127127        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' );
    128         $response   = $this->server->dispatch( $request );
     128        $response   = rest_get_server()->dispatch( $request );
    129129        $data       = $response->get_data();
    130130        $properties = $data['schema']['properties'];
     
    160160        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/schema' );
    161161
    162         $response = $this->server->dispatch( $request );
     162        $response = rest_get_server()->dispatch( $request );
    163163        $data     = $response->get_data();
    164164
     
    168168        $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' );
    169169
    170         $response = $this->server->dispatch( $request );
     170        $response = rest_get_server()->dispatch( $request );
    171171        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    172172
Note: See TracChangeset for help on using the changeset viewer.