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-post-meta-fields.php

    r42343 r42724  
    123123        /** @var WP_REST_Server $wp_rest_server */
    124124        global $wp_rest_server;
    125         $this->server = $wp_rest_server = new Spy_REST_Server;
    126         do_action( 'rest_api_init' );
     125        $wp_rest_server = new Spy_REST_Server;
     126        do_action( 'rest_api_init', $wp_rest_server );
    127127    }
    128128
     
    141141
    142142        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    143         $response = $this->server->dispatch( $request );
     143        $response = rest_get_server()->dispatch( $request );
    144144
    145145        $this->assertEquals( 200, $response->get_status() );
     
    160160        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    161161
    162         $response = $this->server->dispatch( $request );
     162        $response = rest_get_server()->dispatch( $request );
    163163        $this->assertEquals( 200, $response->get_status() );
    164164
     
    172172        add_post_meta( self::$post_id, 'test_multi', 'value2' );
    173173
    174         $response = $this->server->dispatch( $request );
     174        $response = rest_get_server()->dispatch( $request );
    175175        $this->assertEquals( 200, $response->get_status() );
    176176        $data = $response->get_data();
     
    187187        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    188188
    189         $response = $this->server->dispatch( $request );
     189        $response = rest_get_server()->dispatch( $request );
    190190        $this->assertEquals( 200, $response->get_status() );
    191191
     
    202202        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    203203
    204         $response = $this->server->dispatch( $request );
     204        $response = rest_get_server()->dispatch( $request );
    205205        $this->assertEquals( 200, $response->get_status() );
    206206
     
    217217        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    218218
    219         $response = $this->server->dispatch( $request );
     219        $response = rest_get_server()->dispatch( $request );
    220220        $this->assertEquals( 200, $response->get_status() );
    221221
     
    250250        /** @var WP_REST_Server $wp_rest_server */
    251251        global $wp_rest_server;
    252         $this->server = $wp_rest_server = new Spy_REST_Server;
    253         do_action( 'rest_api_init' );
     252        $wp_rest_server = new Spy_REST_Server;
     253        do_action( 'rest_api_init', $wp_rest_server );
    254254
    255255        add_post_meta( self::$post_id, 'test_string', 42 );
     
    258258
    259259        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    260         $response = $this->server->dispatch( $request );
     260        $response = rest_get_server()->dispatch( $request );
    261261        $this->assertEquals( 200, $response->get_status() );
    262262
     
    281281
    282282        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    283         $response = $this->server->dispatch( $request );
     283        $response = rest_get_server()->dispatch( $request );
    284284
    285285        $this->assertEquals( 200, $response->get_status() );
     
    311311        $request->set_body_params( $data );
    312312
    313         $response = $this->server->dispatch( $request );
     313        $response = rest_get_server()->dispatch( $request );
    314314        $this->assertEquals( 200, $response->get_status() );
    315315
     
    343343        $request->set_body_params( $data );
    344344
    345         $response = $this->server->dispatch( $request );
     345        $response = rest_get_server()->dispatch( $request );
    346346        $this->assertEquals( 200, $response->get_status() );
    347347
     
    371371        $request->set_body_params( $data );
    372372
    373         $response = $this->server->dispatch( $request );
     373        $response = rest_get_server()->dispatch( $request );
    374374        $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 );
    375375
     
    393393        $request->set_body_params( $data );
    394394
    395         $response = $this->server->dispatch( $request );
     395        $response = rest_get_server()->dispatch( $request );
    396396        $this->assertErrorResponse( 'rest_cannot_update', $response, 403 );
    397397        $this->assertEmpty( get_post_meta( self::$post_id, 'test_bad_auth', false ) );
     
    421421        add_filter( 'query', array( $this, 'error_insert_query' ) );
    422422
    423         $response = $this->server->dispatch( $request );
     423        $response = rest_get_server()->dispatch( $request );
    424424        remove_filter( 'query', array( $this, 'error_insert_query' ) );
    425425        $wpdb->show_errors = true;
     
    442442        $request->set_body_params( $data );
    443443
    444         $response = $this->server->dispatch( $request );
     444        $response = rest_get_server()->dispatch( $request );
    445445        $this->assertEmpty( get_post_meta( self::$post_id, 'test_invalid_type', false ) );
    446446    }
     
    461461        $request->set_body_params( $data );
    462462
    463         $response = $this->server->dispatch( $request );
     463        $response = rest_get_server()->dispatch( $request );
    464464        $this->assertEquals( 200, $response->get_status() );
    465465
     
    477477        $request->set_body_params( $data );
    478478
    479         $response = $this->server->dispatch( $request );
     479        $response = rest_get_server()->dispatch( $request );
    480480        $this->assertEquals( 200, $response->get_status() );
    481481
     
    505505        $request->set_body_params( $data );
    506506
    507         $response = $this->server->dispatch( $request );
     507        $response = rest_get_server()->dispatch( $request );
    508508        $this->assertEquals( 200, $response->get_status() );
    509509
     
    533533        $request->set_body_params( $data );
    534534
    535         $response = $this->server->dispatch( $request );
     535        $response = rest_get_server()->dispatch( $request );
    536536        $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 );
    537537
     
    559559        $request->set_body_params( $data );
    560560
    561         $response = $this->server->dispatch( $request );
     561        $response = rest_get_server()->dispatch( $request );
    562562        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    563563    }
     
    582582        $request->set_body_params( $data );
    583583
    584         $response = $this->server->dispatch( $request );
     584        $response = rest_get_server()->dispatch( $request );
    585585        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    586586    }
     
    605605        $request->set_body_params( $data );
    606606
    607         $response = $this->server->dispatch( $request );
     607        $response = rest_get_server()->dispatch( $request );
    608608        $data     = $response->get_data();
    609609        $this->assertEquals( 1, $data['meta']['my_meta_key'] );
     
    629629        $request->set_body_params( $data );
    630630
    631         $response = $this->server->dispatch( $request );
     631        $response = rest_get_server()->dispatch( $request );
    632632        $data     = $response->get_data();
    633633        $this->assertEquals( array( 1, 2, 3 ), $data['meta']['my_meta_key'] );
     
    649649        $request->set_body_params( $data );
    650650
    651         $response = $this->server->dispatch( $request );
     651        $response = rest_get_server()->dispatch( $request );
    652652        $this->assertErrorResponse( 'rest_cannot_update', $response, 403 );
    653653        $this->assertEmpty( get_post_meta( self::$post_id, 'test_bad_auth_multi', false ) );
     
    677677        add_filter( 'query', array( $this, 'error_insert_query' ) );
    678678
    679         $response = $this->server->dispatch( $request );
     679        $response = rest_get_server()->dispatch( $request );
    680680        remove_filter( 'query', array( $this, 'error_insert_query' ) );
    681681        $wpdb->show_errors = true;
     
    702702        $request->set_body_params( $data );
    703703
    704         $response = $this->server->dispatch( $request );
     704        $response = rest_get_server()->dispatch( $request );
    705705        $this->assertEquals( 200, $response->get_status() );
    706706
     
    731731        $request->set_body_params( $data );
    732732
    733         $response = $this->server->dispatch( $request );
     733        $response = rest_get_server()->dispatch( $request );
    734734        $this->assertEquals( 200, $response->get_status() );
    735735
     
    747747        $request->set_body_params( $data );
    748748
    749         $response = $this->server->dispatch( $request );
     749        $response = rest_get_server()->dispatch( $request );
    750750        $this->assertEquals( 200, $response->get_status() );
    751751
     
    775775        $request->set_body_params( $data );
    776776
    777         $response = $this->server->dispatch( $request );
     777        $response = rest_get_server()->dispatch( $request );
    778778        $this->assertEquals( 200, $response->get_status() );
    779779
     
    804804        $request->set_body_params( $data );
    805805
    806         $response = $this->server->dispatch( $request );
     806        $response = rest_get_server()->dispatch( $request );
    807807        $this->assertEquals( 200, $response->get_status() );
    808808
     
    820820        $request->set_body_params( $data );
    821821
    822         $response = $this->server->dispatch( $request );
     822        $response = rest_get_server()->dispatch( $request );
    823823        $this->assertEquals( 200, $response->get_status() );
    824824
     
    847847        $request->set_body_params( $data );
    848848
    849         $response = $this->server->dispatch( $request );
     849        $response = rest_get_server()->dispatch( $request );
    850850
    851851        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     
    877877        $request->set_body_params( $data );
    878878
    879         $response = $this->server->dispatch( $request );
     879        $response = rest_get_server()->dispatch( $request );
    880880        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    881881
     
    912912        add_filter( 'query', array( $this, 'error_delete_query' ) );
    913913
    914         $response = $this->server->dispatch( $request );
     914        $response = rest_get_server()->dispatch( $request );
    915915        remove_filter( 'query', array( $this, 'error_delete_query' ) );
    916916        $wpdb->show_errors = true;
     
    935935        $request->set_body_params( $data );
    936936
    937         $response = $this->server->dispatch( $request );
     937        $response = rest_get_server()->dispatch( $request );
    938938        $this->assertEquals( 200, $response->get_status() );
    939939
     
    960960        $request->set_body_params( $data );
    961961
    962         $response = $this->server->dispatch( $request );
     962        $response = rest_get_server()->dispatch( $request );
    963963        $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
    964964
     
    992992        add_filter( 'query', array( $this, 'error_delete_query' ) );
    993993
    994         $response = $this->server->dispatch( $request );
     994        $response = rest_get_server()->dispatch( $request );
    995995        remove_filter( 'query', array( $this, 'error_delete_query' ) );
    996996        $wpdb->show_errors = true;
     
    10141014        $request->set_body_params( $data );
    10151015
    1016         $response = $this->server->dispatch( $request );
     1016        $response = rest_get_server()->dispatch( $request );
    10171017        $this->assertEquals( 200, $response->get_status() );
    10181018
     
    10231023    public function test_get_schema() {
    10241024        $request  = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1025         $response = $this->server->dispatch( $request );
     1025        $response = rest_get_server()->dispatch( $request );
    10261026
    10271027        $data   = $response->get_data();
Note: See TracChangeset for help on using the changeset viewer.