- Timestamp:
- 02/21/2018 04:24:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
r42343 r42724 123 123 /** @var WP_REST_Server $wp_rest_server */ 124 124 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 ); 127 127 } 128 128 … … 141 141 142 142 $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 ); 144 144 145 145 $this->assertEquals( 200, $response->get_status() ); … … 160 160 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 161 161 162 $response = $this->server->dispatch( $request );162 $response = rest_get_server()->dispatch( $request ); 163 163 $this->assertEquals( 200, $response->get_status() ); 164 164 … … 172 172 add_post_meta( self::$post_id, 'test_multi', 'value2' ); 173 173 174 $response = $this->server->dispatch( $request );174 $response = rest_get_server()->dispatch( $request ); 175 175 $this->assertEquals( 200, $response->get_status() ); 176 176 $data = $response->get_data(); … … 187 187 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 188 188 189 $response = $this->server->dispatch( $request );189 $response = rest_get_server()->dispatch( $request ); 190 190 $this->assertEquals( 200, $response->get_status() ); 191 191 … … 202 202 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 203 203 204 $response = $this->server->dispatch( $request );204 $response = rest_get_server()->dispatch( $request ); 205 205 $this->assertEquals( 200, $response->get_status() ); 206 206 … … 217 217 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 218 218 219 $response = $this->server->dispatch( $request );219 $response = rest_get_server()->dispatch( $request ); 220 220 $this->assertEquals( 200, $response->get_status() ); 221 221 … … 250 250 /** @var WP_REST_Server $wp_rest_server */ 251 251 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 ); 254 254 255 255 add_post_meta( self::$post_id, 'test_string', 42 ); … … 258 258 259 259 $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 ); 261 261 $this->assertEquals( 200, $response->get_status() ); 262 262 … … 281 281 282 282 $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 ); 284 284 285 285 $this->assertEquals( 200, $response->get_status() ); … … 311 311 $request->set_body_params( $data ); 312 312 313 $response = $this->server->dispatch( $request );313 $response = rest_get_server()->dispatch( $request ); 314 314 $this->assertEquals( 200, $response->get_status() ); 315 315 … … 343 343 $request->set_body_params( $data ); 344 344 345 $response = $this->server->dispatch( $request );345 $response = rest_get_server()->dispatch( $request ); 346 346 $this->assertEquals( 200, $response->get_status() ); 347 347 … … 371 371 $request->set_body_params( $data ); 372 372 373 $response = $this->server->dispatch( $request );373 $response = rest_get_server()->dispatch( $request ); 374 374 $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 ); 375 375 … … 393 393 $request->set_body_params( $data ); 394 394 395 $response = $this->server->dispatch( $request );395 $response = rest_get_server()->dispatch( $request ); 396 396 $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); 397 397 $this->assertEmpty( get_post_meta( self::$post_id, 'test_bad_auth', false ) ); … … 421 421 add_filter( 'query', array( $this, 'error_insert_query' ) ); 422 422 423 $response = $this->server->dispatch( $request );423 $response = rest_get_server()->dispatch( $request ); 424 424 remove_filter( 'query', array( $this, 'error_insert_query' ) ); 425 425 $wpdb->show_errors = true; … … 442 442 $request->set_body_params( $data ); 443 443 444 $response = $this->server->dispatch( $request );444 $response = rest_get_server()->dispatch( $request ); 445 445 $this->assertEmpty( get_post_meta( self::$post_id, 'test_invalid_type', false ) ); 446 446 } … … 461 461 $request->set_body_params( $data ); 462 462 463 $response = $this->server->dispatch( $request );463 $response = rest_get_server()->dispatch( $request ); 464 464 $this->assertEquals( 200, $response->get_status() ); 465 465 … … 477 477 $request->set_body_params( $data ); 478 478 479 $response = $this->server->dispatch( $request );479 $response = rest_get_server()->dispatch( $request ); 480 480 $this->assertEquals( 200, $response->get_status() ); 481 481 … … 505 505 $request->set_body_params( $data ); 506 506 507 $response = $this->server->dispatch( $request );507 $response = rest_get_server()->dispatch( $request ); 508 508 $this->assertEquals( 200, $response->get_status() ); 509 509 … … 533 533 $request->set_body_params( $data ); 534 534 535 $response = $this->server->dispatch( $request );535 $response = rest_get_server()->dispatch( $request ); 536 536 $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 ); 537 537 … … 559 559 $request->set_body_params( $data ); 560 560 561 $response = $this->server->dispatch( $request );561 $response = rest_get_server()->dispatch( $request ); 562 562 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 563 563 } … … 582 582 $request->set_body_params( $data ); 583 583 584 $response = $this->server->dispatch( $request );584 $response = rest_get_server()->dispatch( $request ); 585 585 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 586 586 } … … 605 605 $request->set_body_params( $data ); 606 606 607 $response = $this->server->dispatch( $request );607 $response = rest_get_server()->dispatch( $request ); 608 608 $data = $response->get_data(); 609 609 $this->assertEquals( 1, $data['meta']['my_meta_key'] ); … … 629 629 $request->set_body_params( $data ); 630 630 631 $response = $this->server->dispatch( $request );631 $response = rest_get_server()->dispatch( $request ); 632 632 $data = $response->get_data(); 633 633 $this->assertEquals( array( 1, 2, 3 ), $data['meta']['my_meta_key'] ); … … 649 649 $request->set_body_params( $data ); 650 650 651 $response = $this->server->dispatch( $request );651 $response = rest_get_server()->dispatch( $request ); 652 652 $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); 653 653 $this->assertEmpty( get_post_meta( self::$post_id, 'test_bad_auth_multi', false ) ); … … 677 677 add_filter( 'query', array( $this, 'error_insert_query' ) ); 678 678 679 $response = $this->server->dispatch( $request );679 $response = rest_get_server()->dispatch( $request ); 680 680 remove_filter( 'query', array( $this, 'error_insert_query' ) ); 681 681 $wpdb->show_errors = true; … … 702 702 $request->set_body_params( $data ); 703 703 704 $response = $this->server->dispatch( $request );704 $response = rest_get_server()->dispatch( $request ); 705 705 $this->assertEquals( 200, $response->get_status() ); 706 706 … … 731 731 $request->set_body_params( $data ); 732 732 733 $response = $this->server->dispatch( $request );733 $response = rest_get_server()->dispatch( $request ); 734 734 $this->assertEquals( 200, $response->get_status() ); 735 735 … … 747 747 $request->set_body_params( $data ); 748 748 749 $response = $this->server->dispatch( $request );749 $response = rest_get_server()->dispatch( $request ); 750 750 $this->assertEquals( 200, $response->get_status() ); 751 751 … … 775 775 $request->set_body_params( $data ); 776 776 777 $response = $this->server->dispatch( $request );777 $response = rest_get_server()->dispatch( $request ); 778 778 $this->assertEquals( 200, $response->get_status() ); 779 779 … … 804 804 $request->set_body_params( $data ); 805 805 806 $response = $this->server->dispatch( $request );806 $response = rest_get_server()->dispatch( $request ); 807 807 $this->assertEquals( 200, $response->get_status() ); 808 808 … … 820 820 $request->set_body_params( $data ); 821 821 822 $response = $this->server->dispatch( $request );822 $response = rest_get_server()->dispatch( $request ); 823 823 $this->assertEquals( 200, $response->get_status() ); 824 824 … … 847 847 $request->set_body_params( $data ); 848 848 849 $response = $this->server->dispatch( $request );849 $response = rest_get_server()->dispatch( $request ); 850 850 851 851 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 877 877 $request->set_body_params( $data ); 878 878 879 $response = $this->server->dispatch( $request );879 $response = rest_get_server()->dispatch( $request ); 880 880 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 881 881 … … 912 912 add_filter( 'query', array( $this, 'error_delete_query' ) ); 913 913 914 $response = $this->server->dispatch( $request );914 $response = rest_get_server()->dispatch( $request ); 915 915 remove_filter( 'query', array( $this, 'error_delete_query' ) ); 916 916 $wpdb->show_errors = true; … … 935 935 $request->set_body_params( $data ); 936 936 937 $response = $this->server->dispatch( $request );937 $response = rest_get_server()->dispatch( $request ); 938 938 $this->assertEquals( 200, $response->get_status() ); 939 939 … … 960 960 $request->set_body_params( $data ); 961 961 962 $response = $this->server->dispatch( $request );962 $response = rest_get_server()->dispatch( $request ); 963 963 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); 964 964 … … 992 992 add_filter( 'query', array( $this, 'error_delete_query' ) ); 993 993 994 $response = $this->server->dispatch( $request );994 $response = rest_get_server()->dispatch( $request ); 995 995 remove_filter( 'query', array( $this, 'error_delete_query' ) ); 996 996 $wpdb->show_errors = true; … … 1014 1014 $request->set_body_params( $data ); 1015 1015 1016 $response = $this->server->dispatch( $request );1016 $response = rest_get_server()->dispatch( $request ); 1017 1017 $this->assertEquals( 200, $response->get_status() ); 1018 1018 … … 1023 1023 public function test_get_schema() { 1024 1024 $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 ); 1026 1026 1027 1027 $data = $response->get_data();
Note: See TracChangeset
for help on using the changeset viewer.