- 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-posts-controller.php
r42423 r42724 111 111 112 112 public function test_register_routes() { 113 $routes = $this->server->get_routes();113 $routes = rest_get_server()->get_routes(); 114 114 115 115 $this->assertArrayHasKey( '/wp/v2/posts', $routes ); … … 122 122 // Collection 123 123 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 124 $response = $this->server->dispatch( $request );124 $response = rest_get_server()->dispatch( $request ); 125 125 $data = $response->get_data(); 126 126 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 128 128 // Single 129 129 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id ); 130 $response = $this->server->dispatch( $request );130 $response = rest_get_server()->dispatch( $request ); 131 131 $data = $response->get_data(); 132 132 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 136 136 public function test_registered_query_params() { 137 137 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 138 $response = $this->server->dispatch( $request );138 $response = rest_get_server()->dispatch( $request ); 139 139 $data = $response->get_data(); 140 140 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 168 168 public function test_registered_get_item_params() { 169 169 $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 170 $response = $this->server->dispatch( $request );170 $response = rest_get_server()->dispatch( $request ); 171 171 $data = $response->get_data(); 172 172 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 177 177 public function test_get_items() { 178 178 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 179 $response = $this->server->dispatch( $request );179 $response = rest_get_server()->dispatch( $request ); 180 180 181 181 $this->check_get_posts_response( $response ); … … 194 194 ) 195 195 ); 196 $response = $this->server->dispatch( $request );196 $response = rest_get_server()->dispatch( $request ); 197 197 198 198 $this->assertEmpty( $response->get_data() ); … … 205 205 // All 3 posts 206 206 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 207 $response = $this->server->dispatch( $request );207 $response = rest_get_server()->dispatch( $request ); 208 208 $this->assertEquals( 200, $response->get_status() ); 209 209 $this->assertEquals( 3, count( $response->get_data() ) ); … … 211 211 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 212 212 $request->set_param( 'author', array( self::$editor_id, self::$author_id ) ); 213 $response = $this->server->dispatch( $request );213 $response = rest_get_server()->dispatch( $request ); 214 214 $this->assertEquals( 200, $response->get_status() ); 215 215 $data = $response->get_data(); … … 219 219 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 220 220 $request->set_param( 'author', self::$editor_id ); 221 $response = $this->server->dispatch( $request );221 $response = rest_get_server()->dispatch( $request ); 222 222 $this->assertEquals( 200, $response->get_status() ); 223 223 $data = $response->get_data(); … … 231 231 // All 3 posts 232 232 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 233 $response = $this->server->dispatch( $request );233 $response = rest_get_server()->dispatch( $request ); 234 234 $this->assertEquals( 200, $response->get_status() ); 235 235 $this->assertEquals( 3, count( $response->get_data() ) ); … … 237 237 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 238 238 $request->set_param( 'author_exclude', array( self::$editor_id, self::$author_id ) ); 239 $response = $this->server->dispatch( $request );239 $response = rest_get_server()->dispatch( $request ); 240 240 $this->assertEquals( 200, $response->get_status() ); 241 241 $data = $response->get_data(); … … 246 246 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 247 247 $request->set_param( 'author_exclude', self::$editor_id ); 248 $response = $this->server->dispatch( $request );248 $response = rest_get_server()->dispatch( $request ); 249 249 $this->assertEquals( 200, $response->get_status() ); 250 250 $data = $response->get_data(); … … 255 255 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 256 256 $request->set_param( 'author_exclude', 'invalid' ); 257 $response = $this->server->dispatch( $request );257 $response = rest_get_server()->dispatch( $request ); 258 258 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 259 259 } … … 266 266 // Orderby=>desc 267 267 $request->set_param( 'include', array( $id1, $id3 ) ); 268 $response = $this->server->dispatch( $request );268 $response = rest_get_server()->dispatch( $request ); 269 269 $data = $response->get_data(); 270 270 $this->assertEquals( 2, count( $data ) ); … … 273 273 // Orderby=>include 274 274 $request->set_param( 'orderby', 'include' ); 275 $response = $this->server->dispatch( $request );275 $response = rest_get_server()->dispatch( $request ); 276 276 $data = $response->get_data(); 277 277 $this->assertEquals( 2, count( $data ) ); … … 281 281 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 282 282 $request->set_param( 'include', 'invalid' ); 283 $response = $this->server->dispatch( $request );283 $response = rest_get_server()->dispatch( $request ); 284 284 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 285 285 } … … 309 309 $request->set_param( 'orderby', 'author' ); 310 310 311 $response = $this->server->dispatch( $request );311 $response = rest_get_server()->dispatch( $request ); 312 312 $data = $response->get_data(); 313 313 … … 333 333 $request->set_param( 'orderby', 'modified' ); 334 334 335 $response = $this->server->dispatch( $request );335 $response = rest_get_server()->dispatch( $request ); 336 336 $data = $response->get_data(); 337 337 … … 369 369 $request->set_param( 'orderby', 'parent' ); 370 370 371 $response = $this->server->dispatch( $request );371 $response = rest_get_server()->dispatch( $request ); 372 372 $data = $response->get_data(); 373 373 … … 386 386 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 387 387 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 388 $response = $this->server->dispatch( $request );388 $response = rest_get_server()->dispatch( $request ); 389 389 $data = $response->get_data(); 390 390 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 392 392 393 393 $request->set_param( 'exclude', array( $id2 ) ); 394 $response = $this->server->dispatch( $request );394 $response = rest_get_server()->dispatch( $request ); 395 395 $data = $response->get_data(); 396 396 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 398 398 399 399 $request->set_param( 'exclude', "$id2" ); 400 $response = $this->server->dispatch( $request );400 $response = rest_get_server()->dispatch( $request ); 401 401 $data = $response->get_data(); 402 402 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 404 404 405 405 $request->set_param( 'exclude', 'invalid' ); 406 $response = $this->server->dispatch( $request );406 $response = rest_get_server()->dispatch( $request ); 407 407 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 408 408 } … … 419 419 ); 420 420 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 421 $response = $this->server->dispatch( $request );421 $response = rest_get_server()->dispatch( $request ); 422 422 $this->assertEquals( 7, count( $response->get_data() ) ); 423 423 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 424 424 $request->set_param( 'search', 'Search Result' ); 425 $response = $this->server->dispatch( $request );425 $response = rest_get_server()->dispatch( $request ); 426 426 $data = $response->get_data(); 427 427 $this->assertEquals( 1, count( $data ) ); … … 444 444 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 445 445 $request->set_param( 'slug', 'apple' ); 446 $response = $this->server->dispatch( $request );446 $response = rest_get_server()->dispatch( $request ); 447 447 $this->assertEquals( 200, $response->get_status() ); 448 448 $data = $response->get_data(); … … 472 472 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 473 473 $request->set_param( 'slug', array( 'banana', 'peach' ) ); 474 $response = $this->server->dispatch( $request );474 $response = rest_get_server()->dispatch( $request ); 475 475 $this->assertEquals( 200, $response->get_status() ); 476 476 $data = $response->get_data(); … … 505 505 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 506 506 $request->set_param( 'slug', 'apple,banana' ); 507 $response = $this->server->dispatch( $request );507 $response = rest_get_server()->dispatch( $request ); 508 508 $this->assertEquals( 200, $response->get_status() ); 509 509 $data = $response->get_data(); … … 522 522 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 523 523 $request->set_param( 'status', 'publish' ); 524 $response = $this->server->dispatch( $request );524 $response = rest_get_server()->dispatch( $request ); 525 525 $this->assertEquals( 200, $response->get_status() ); 526 526 $this->assertEquals( 1, count( $response->get_data() ) ); 527 527 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 528 528 $request->set_param( 'status', 'draft' ); 529 $response = $this->server->dispatch( $request );529 $response = rest_get_server()->dispatch( $request ); 530 530 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 531 531 wp_set_current_user( self::$editor_id ); 532 532 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 533 533 $request->set_param( 'status', 'draft' ); 534 $response = $this->server->dispatch( $request );534 $response = rest_get_server()->dispatch( $request ); 535 535 $this->assertEquals( 200, $response->get_status() ); 536 536 $this->assertEquals( 1, count( $response->get_data() ) ); … … 548 548 $request->set_param( 'status', 'draft,private' ); 549 549 550 $response = $this->server->dispatch( $request );550 $response = rest_get_server()->dispatch( $request ); 551 551 $this->assertEquals( 200, $response->get_status() ); 552 552 $data = $response->get_data(); … … 571 571 $request->set_param( 'status', array( 'draft', 'pending' ) ); 572 572 573 $response = $this->server->dispatch( $request );573 $response = rest_get_server()->dispatch( $request ); 574 574 $this->assertEquals( 200, $response->get_status() ); 575 575 $data = $response->get_data(); … … 587 587 $request->set_param( 'context', 'edit' ); 588 588 $request->set_param( 'status', array( 'draft', 'nonsense' ) ); 589 $response = $this->server->dispatch( $request );589 $response = rest_get_server()->dispatch( $request ); 590 590 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 591 591 } … … 595 595 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 596 596 $request->set_param( 'status', 'invalid' ); 597 $response = $this->server->dispatch( $request );597 $response = rest_get_server()->dispatch( $request ); 598 598 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 599 599 } … … 608 608 609 609 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 610 $response = $this->server->dispatch( $request );610 $response = rest_get_server()->dispatch( $request ); 611 611 612 612 $this->assertEquals( 200, $response->get_status() ); … … 647 647 // order defaults to 'desc' 648 648 $request->set_param( 'orderby', 'title' ); 649 $response = $this->server->dispatch( $request );649 $response = rest_get_server()->dispatch( $request ); 650 650 $data = $response->get_data(); 651 651 $this->assertEquals( 'Apple Sauce', $data[0]['title']['rendered'] ); … … 653 653 // order=>asc 654 654 $request->set_param( 'order', 'asc' ); 655 $response = $this->server->dispatch( $request );655 $response = rest_get_server()->dispatch( $request ); 656 656 $data = $response->get_data(); 657 657 $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] ); … … 659 659 // order=>asc,id should fail 660 660 $request->set_param( 'order', 'asc,id' ); 661 $response = $this->server->dispatch( $request );661 $response = rest_get_server()->dispatch( $request ); 662 662 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 663 663 // orderby=>content should fail (invalid param test) 664 664 $request->set_param( 'order', 'asc' ); 665 665 $request->set_param( 'orderby', 'content' ); 666 $response = $this->server->dispatch( $request );666 $response = rest_get_server()->dispatch( $request ); 667 667 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 668 668 } … … 673 673 $request->set_param( 'orderby', 'include' ); 674 674 675 $response = $this->server->dispatch( $request );675 $response = rest_get_server()->dispatch( $request ); 676 676 677 677 $this->assertErrorResponse( 'rest_orderby_include_missing_include', $response, 400 ); … … 702 702 $request->set_param( 'include', array( $id1, $id2, $id3 ) ); 703 703 704 $response = $this->server->dispatch( $request );704 $response = rest_get_server()->dispatch( $request ); 705 705 $data = $response->get_data(); 706 706 … … 732 732 $request->set_param( 'include', array( $id1, $id2 ) ); 733 733 734 $response = $this->server->dispatch( $request );734 $response = rest_get_server()->dispatch( $request ); 735 735 $data = $response->get_data(); 736 736 … … 757 757 $request->set_param( 'slug', array( 'taco', 'chalupa', 'burrito' ) ); 758 758 759 $response = $this->server->dispatch( $request );759 $response = rest_get_server()->dispatch( $request ); 760 760 $data = $response->get_data(); 761 761 … … 783 783 $request->set_param( 'orderby', 'relevance' ); 784 784 $request->set_param( 'search', 'relevant' ); 785 $response = $this->server->dispatch( $request );785 $response = rest_get_server()->dispatch( $request ); 786 786 $this->assertEquals( 200, $response->get_status() ); 787 787 $data = $response->get_data(); … … 810 810 $request->set_param( 'orderby', 'relevance' ); 811 811 $request->set_param( 'search', 'relevant content' ); 812 $response = $this->server->dispatch( $request );812 $response = rest_get_server()->dispatch( $request ); 813 813 $this->assertEquals( 200, $response->get_status() ); 814 814 $data = $response->get_data(); … … 822 822 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 823 823 $request->set_param( 'orderby', 'relevance' ); 824 $response = $this->server->dispatch( $request );824 $response = rest_get_server()->dispatch( $request ); 825 825 $this->assertErrorResponse( 'rest_no_search_term_defined', $response, 400 ); 826 826 } … … 833 833 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 834 834 $request->set_param( 'offset', 1 ); 835 $response = $this->server->dispatch( $request );835 $response = rest_get_server()->dispatch( $request ); 836 836 $this->assertCount( 3, $response->get_data() ); 837 837 // 'offset' works with 'per_page' 838 838 $request->set_param( 'per_page', 2 ); 839 $response = $this->server->dispatch( $request );839 $response = rest_get_server()->dispatch( $request ); 840 840 $this->assertCount( 2, $response->get_data() ); 841 841 // 'offset' takes priority over 'page' 842 842 $request->set_param( 'page', 2 ); 843 $response = $this->server->dispatch( $request );843 $response = rest_get_server()->dispatch( $request ); 844 844 $this->assertCount( 2, $response->get_data() ); 845 845 // Invalid 'offset' should error 846 846 $request->set_param( 'offset', 'moreplease' ); 847 $response = $this->server->dispatch( $request );847 $response = rest_get_server()->dispatch( $request ); 848 848 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 849 849 } … … 860 860 $request->set_param( 'tags', array( $tag['term_id'] ) ); 861 861 862 $response = $this->server->dispatch( $request );862 $response = rest_get_server()->dispatch( $request ); 863 863 $data = $response->get_data(); 864 864 $this->assertCount( 1, $data ); … … 877 877 $request->set_param( 'tags_exclude', array( $tag['term_id'] ) ); 878 878 879 $response = $this->server->dispatch( $request );879 $response = rest_get_server()->dispatch( $request ); 880 880 $data = $response->get_data(); 881 881 $this->assertCount( 3, $data ); … … 901 901 $request->set_param( 'categories', array( $category['term_id'] ) ); 902 902 903 $response = $this->server->dispatch( $request );903 $response = rest_get_server()->dispatch( $request ); 904 904 $this->assertCount( 1, $response->get_data() ); 905 905 906 906 $request->set_param( 'tags', array( 'my-tag' ) ); 907 $response = $this->server->dispatch( $request );907 $response = rest_get_server()->dispatch( $request ); 908 908 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 909 909 } … … 925 925 $request->set_param( 'categories_exclude', array( $category['term_id'] ) ); 926 926 927 $response = $this->server->dispatch( $request );927 $response = rest_get_server()->dispatch( $request ); 928 928 $data = $response->get_data(); 929 929 $this->assertCount( 1, $data ); … … 931 931 932 932 $request->set_param( 'tags_exclude', array( 'my-tag' ) ); 933 $response = $this->server->dispatch( $request );933 $response = rest_get_server()->dispatch( $request ); 934 934 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 935 935 } … … 944 944 $request->set_param( 'sticky', true ); 945 945 946 $response = $this->server->dispatch( $request );946 $response = rest_get_server()->dispatch( $request ); 947 947 $this->assertCount( 1, $response->get_data() ); 948 948 … … 952 952 953 953 $request->set_param( 'sticky', 'nothanks' ); 954 $response = $this->server->dispatch( $request );954 $response = rest_get_server()->dispatch( $request ); 955 955 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 956 956 } … … 967 967 $request->set_param( 'include', array( $id1 ) ); 968 968 969 $response = $this->server->dispatch( $request );969 $response = rest_get_server()->dispatch( $request ); 970 970 $this->assertCount( 0, $response->get_data() ); 971 971 … … 982 982 $request->set_param( 'include', array( $id1 ) ); 983 983 984 $response = $this->server->dispatch( $request );984 $response = rest_get_server()->dispatch( $request ); 985 985 986 986 $this->assertCount( 1, $response->get_data() ); … … 1001 1001 $request->set_param( 'sticky', true ); 1002 1002 1003 $response = $this->server->dispatch( $request );1003 $response = rest_get_server()->dispatch( $request ); 1004 1004 $this->assertCount( 0, $response->get_data() ); 1005 1005 … … 1020 1020 $request->set_param( 'include', array( $id1 ) ); 1021 1021 1022 $response = $this->server->dispatch( $request );1022 $response = rest_get_server()->dispatch( $request ); 1023 1023 $this->assertCount( 0, $response->get_data() ); 1024 1024 … … 1039 1039 $request->set_param( 'sticky', false ); 1040 1040 1041 $response = $this->server->dispatch( $request );1041 $response = rest_get_server()->dispatch( $request ); 1042 1042 $this->assertCount( 1, $response->get_data() ); 1043 1043 … … 1060 1060 $request->set_param( 'exclude', array( $id3 ) ); 1061 1061 1062 $response = $this->server->dispatch( $request );1062 $response = rest_get_server()->dispatch( $request ); 1063 1063 $this->assertCount( 1, $response->get_data() ); 1064 1064 … … 1081 1081 $request->set_param( 'exclude', array( $id3 ) ); 1082 1082 1083 $response = $this->server->dispatch( $request );1083 $response = rest_get_server()->dispatch( $request ); 1084 1084 $this->assertCount( 2, $response->get_data() ); 1085 1085 … … 1102 1102 } 1103 1103 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1104 $response = $this->server->dispatch( $request );1104 $response = rest_get_server()->dispatch( $request ); 1105 1105 $headers = $response->get_headers(); 1106 1106 $this->assertEquals( 50, $headers['X-WP-Total'] ); … … 1121 1121 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1122 1122 $request->set_param( 'page', 3 ); 1123 $response = $this->server->dispatch( $request );1123 $response = rest_get_server()->dispatch( $request ); 1124 1124 $headers = $response->get_headers(); 1125 1125 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 1140 1140 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1141 1141 $request->set_param( 'page', 6 ); 1142 $response = $this->server->dispatch( $request );1142 $response = rest_get_server()->dispatch( $request ); 1143 1143 $headers = $response->get_headers(); 1144 1144 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 1155 1155 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1156 1156 $request->set_param( 'page', 8 ); 1157 $response = $this->server->dispatch( $request );1157 $response = rest_get_server()->dispatch( $request ); 1158 1158 $headers = $response->get_headers(); 1159 1159 $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 ); … … 1167 1167 ) 1168 1168 ); 1169 $response = $this->server->dispatch( $request );1169 $response = rest_get_server()->dispatch( $request ); 1170 1170 $headers = $response->get_headers(); 1171 1171 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 1193 1193 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1194 1194 $request->set_param( 'status', 'draft' ); 1195 $response = $this->server->dispatch( $request );1195 $response = rest_get_server()->dispatch( $request ); 1196 1196 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1197 1197 1198 1198 // But they are accessible to authorized users 1199 1199 wp_set_current_user( self::$editor_id ); 1200 $response = $this->server->dispatch( $request );1200 $response = rest_get_server()->dispatch( $request ); 1201 1201 $data = $response->get_data(); 1202 1202 $this->assertCount( 1, $data ); … … 1207 1207 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1208 1208 $request->set_query_params( array( 'per_page' => -1 ) ); 1209 $response = $this->server->dispatch( $request );1209 $response = rest_get_server()->dispatch( $request ); 1210 1210 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1211 1211 } … … 1218 1218 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1219 1219 $request->set_param( 'page', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 1220 $response = $this->server->dispatch( $request );1220 $response = rest_get_server()->dispatch( $request ); 1221 1221 $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 ); 1222 1222 } … … 1225 1225 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1226 1226 $request->set_param( 'context', 'banana' ); 1227 $response = $this->server->dispatch( $request );1227 $response = rest_get_server()->dispatch( $request ); 1228 1228 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1229 1229 } … … 1233 1233 $request->set_param( 'after', rand_str() ); 1234 1234 $request->set_param( 'before', rand_str() ); 1235 $response = $this->server->dispatch( $request );1235 $response = rest_get_server()->dispatch( $request ); 1236 1236 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1237 1237 } … … 1245 1245 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 1246 1246 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 1247 $response = $this->server->dispatch( $request );1247 $response = rest_get_server()->dispatch( $request ); 1248 1248 $data = $response->get_data(); 1249 1249 $this->assertCount( 1, $data ); … … 1253 1253 public function test_get_items_all_post_formats() { 1254 1254 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 1255 $response = $this->server->dispatch( $request );1255 $response = rest_get_server()->dispatch( $request ); 1256 1256 $data = $response->get_data(); 1257 1257 … … 1263 1263 public function test_get_item() { 1264 1264 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1265 $response = $this->server->dispatch( $request );1265 $response = rest_get_server()->dispatch( $request ); 1266 1266 1267 1267 $this->check_get_post_response( $response, 'view' ); … … 1270 1270 public function test_get_item_links() { 1271 1271 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1272 $response = $this->server->dispatch( $request );1272 $response = rest_get_server()->dispatch( $request ); 1273 1273 1274 1274 $links = $response->get_links(); … … 1313 1313 public function test_get_item_links_no_author() { 1314 1314 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1315 $response = $this->server->dispatch( $request );1315 $response = rest_get_server()->dispatch( $request ); 1316 1316 $links = $response->get_links(); 1317 1317 $this->assertFalse( isset( $links['author'] ) ); … … 1323 1323 ); 1324 1324 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1325 $response = $this->server->dispatch( $request );1325 $response = rest_get_server()->dispatch( $request ); 1326 1326 $links = $response->get_links(); 1327 1327 $this->assertEquals( rest_url( '/wp/v2/users/' . self::$author_id ), $links['author'][0]['href'] ); … … 1337 1337 1338 1338 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $draft_id ) ); 1339 $response = $this->server->dispatch( $request );1339 $response = rest_get_server()->dispatch( $request ); 1340 1340 1341 1341 $this->assertErrorResponse( 'rest_forbidden', $response, 401 ); … … 1344 1344 public function test_get_post_invalid_id() { 1345 1345 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 1346 $response = $this->server->dispatch( $request );1346 $response = rest_get_server()->dispatch( $request ); 1347 1347 1348 1348 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 1359 1359 wp_set_current_user( self::$editor_id ); 1360 1360 1361 $response = $this->server->dispatch( $request );1361 $response = rest_get_server()->dispatch( $request ); 1362 1362 1363 1363 $this->check_get_posts_response( $response, 'edit' ); … … 1372 1372 ) 1373 1373 ); 1374 $response = $this->server->dispatch( $request );1374 $response = rest_get_server()->dispatch( $request ); 1375 1375 1376 1376 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); … … 1385 1385 ) 1386 1386 ); 1387 $response = $this->server->dispatch( $request );1387 $response = rest_get_server()->dispatch( $request ); 1388 1388 1389 1389 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); … … 1398 1398 1399 1399 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1400 $response = $this->server->dispatch( $request );1400 $response = rest_get_server()->dispatch( $request ); 1401 1401 1402 1402 $this->check_get_post_response( $response, 'view' ); … … 1421 1421 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1422 1422 $request->set_param( 'password', '$inthebananastand' ); 1423 $response = $this->server->dispatch( $request );1423 $response = rest_get_server()->dispatch( $request ); 1424 1424 1425 1425 $this->check_get_post_response( $response, 'view' ); … … 1442 1442 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1443 1443 $request->set_param( 'password', 'wrongpassword' ); 1444 $response = $this->server->dispatch( $request );1444 $response = rest_get_server()->dispatch( $request ); 1445 1445 1446 1446 $this->assertErrorResponse( 'rest_post_incorrect_password', $response, 403 ); … … 1456 1456 ); 1457 1457 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1458 $response = $this->server->dispatch( $request );1458 $response = rest_get_server()->dispatch( $request ); 1459 1459 $data = $response->get_data(); 1460 1460 $this->check_get_post_response( $response, 'view' ); … … 1476 1476 ); 1477 1477 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1478 $response = $this->server->dispatch( $request );1478 $response = rest_get_server()->dispatch( $request ); 1479 1479 $this->assertEquals( 200, $response->get_status() ); 1480 1480 // Private status … … 1486 1486 ); 1487 1487 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1488 $response = $this->server->dispatch( $request );1488 $response = rest_get_server()->dispatch( $request ); 1489 1489 $this->assertEquals( 401, $response->get_status() ); 1490 1490 } … … 1495 1495 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1496 1496 $request->set_query_params( array( 'context' => 'edit' ) ); 1497 $response = $this->server->dispatch( $request );1497 $response = rest_get_server()->dispatch( $request ); 1498 1498 1499 1499 $this->check_get_post_response( $response, 'edit' ); … … 1507 1507 $params = $this->set_post_data(); 1508 1508 $request->set_body_params( $params ); 1509 $response = $this->server->dispatch( $request );1509 $response = rest_get_server()->dispatch( $request ); 1510 1510 1511 1511 $this->check_create_post_response( $response ); … … 1598 1598 $request->set_param( 'date_gmt', $params['date_gmt'] ); 1599 1599 } 1600 $response = $this->server->dispatch( $request );1600 $response = rest_get_server()->dispatch( $request ); 1601 1601 1602 1602 update_option( 'timezone_string', '' ); … … 1635 1635 ); 1636 1636 $request->set_body_params( $params ); 1637 $response = $this->server->dispatch( $request );1637 $response = rest_get_server()->dispatch( $request ); 1638 1638 1639 1639 $data = $response->get_data(); … … 1659 1659 ); 1660 1660 $request->set_body_params( $params ); 1661 $response = $this->server->dispatch( $request );1661 $response = rest_get_server()->dispatch( $request ); 1662 1662 1663 1663 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1679 1679 ); 1680 1680 $request->set_body_params( $params ); 1681 $response = $this->server->dispatch( $request );1681 $response = rest_get_server()->dispatch( $request ); 1682 1682 1683 1683 $data = $response->get_data(); … … 1695 1695 $params = $this->set_post_data(); 1696 1696 $request->set_body( wp_json_encode( $params ) ); 1697 $response = $this->server->dispatch( $request );1697 $response = rest_get_server()->dispatch( $request ); 1698 1698 1699 1699 $this->check_create_post_response( $response ); … … 1710 1710 ); 1711 1711 $request->set_body_params( $params ); 1712 $response = $this->server->dispatch( $request );1712 $response = rest_get_server()->dispatch( $request ); 1713 1713 1714 1714 $this->assertErrorResponse( 'rest_post_exists', $response, 400 ); … … 1729 1729 1730 1730 $request->set_body_params( $params ); 1731 $response = $this->server->dispatch( $request );1731 $response = rest_get_server()->dispatch( $request ); 1732 1732 $this->assertEquals( 201, $response->get_status() ); 1733 1733 … … 1752 1752 ); 1753 1753 $request->set_body_params( $params ); 1754 $response = $this->server->dispatch( $request );1754 $response = rest_get_server()->dispatch( $request ); 1755 1755 1756 1756 $new_data = $response->get_data(); … … 1771 1771 ); 1772 1772 $request->set_body_params( $params ); 1773 $response = $this->server->dispatch( $request );1773 $response = rest_get_server()->dispatch( $request ); 1774 1774 1775 1775 $this->assertErrorResponse( 'rest_cannot_assign_sticky', $response, 403 ); … … 1786 1786 ); 1787 1787 $request->set_body_params( $params ); 1788 $response = $this->server->dispatch( $request );1788 $response = rest_get_server()->dispatch( $request ); 1789 1789 1790 1790 $this->assertErrorResponse( 'rest_cannot_edit_others', $response, 403 ); … … 1801 1801 ); 1802 1802 $request->set_body_params( $params ); 1803 $response = $this->server->dispatch( $request );1803 $response = rest_get_server()->dispatch( $request ); 1804 1804 1805 1805 $this->assertErrorResponse( 'rest_cannot_create', $response, 401 ); … … 1816 1816 ); 1817 1817 $request->set_body_params( $params ); 1818 $response = $this->server->dispatch( $request );1818 $response = rest_get_server()->dispatch( $request ); 1819 1819 1820 1820 $data = $response->get_data(); … … 1840 1840 ); 1841 1841 $request->set_body_params( $params ); 1842 $response = $this->server->dispatch( $request );1842 $response = rest_get_server()->dispatch( $request ); 1843 1843 1844 1844 $data = $response->get_data(); … … 1864 1864 ); 1865 1865 $request->set_body_params( $params ); 1866 $response = $this->server->dispatch( $request );1866 $response = rest_get_server()->dispatch( $request ); 1867 1867 1868 1868 $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 ); … … 1884 1884 ); 1885 1885 $request->set_body_params( $params ); 1886 $response = $this->server->dispatch( $request );1886 $response = rest_get_server()->dispatch( $request ); 1887 1887 1888 1888 $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 ); … … 1899 1899 ); 1900 1900 $request->set_body_params( $params ); 1901 $response = $this->server->dispatch( $request );1901 $response = rest_get_server()->dispatch( $request ); 1902 1902 1903 1903 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1914 1914 ); 1915 1915 $request->set_body_params( $params ); 1916 $response = $this->server->dispatch( $request );1916 $response = rest_get_server()->dispatch( $request ); 1917 1917 1918 1918 $data = $response->get_data(); … … 1932 1932 ); 1933 1933 $request->set_body_params( $params ); 1934 $response = $this->server->dispatch( $request );1934 $response = rest_get_server()->dispatch( $request ); 1935 1935 1936 1936 $data = $response->get_data(); … … 1950 1950 ); 1951 1951 $request->set_body_params( $params ); 1952 $response = $this->server->dispatch( $request );1952 $response = rest_get_server()->dispatch( $request ); 1953 1953 1954 1954 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1970 1970 ); 1971 1971 $request->set_body_params( $params ); 1972 $response = $this->server->dispatch( $request );1972 $response = rest_get_server()->dispatch( $request ); 1973 1973 $this->assertEquals( 201, $response->get_status() ); 1974 1974 … … 1996 1996 ); 1997 1997 $request->set_body_params( $params ); 1998 $response = $this->server->dispatch( $request );1998 $response = rest_get_server()->dispatch( $request ); 1999 1999 $data = $response->get_data(); 2000 2000 $new_post = get_post( $data['id'] ); … … 2009 2009 ); 2010 2010 $request->set_body_params( $params ); 2011 $response = $this->server->dispatch( $request );2011 $response = rest_get_server()->dispatch( $request ); 2012 2012 $data = $response->get_data(); 2013 2013 $this->assertEquals( 0, $data['featured_media'] ); … … 2025 2025 ); 2026 2026 $request->set_body_params( $params ); 2027 $response = $this->server->dispatch( $request );2027 $response = rest_get_server()->dispatch( $request ); 2028 2028 2029 2029 $this->assertErrorResponse( 'rest_invalid_author', $response, 400 ); … … 2040 2040 ); 2041 2041 $request->set_body_params( $params ); 2042 $response = $this->server->dispatch( $request );2042 $response = rest_get_server()->dispatch( $request ); 2043 2043 2044 2044 $this->assertErrorResponse( 'rest_cannot_edit_others', $response, 403 ); … … 2055 2055 ); 2056 2056 $request->set_body_params( $params ); 2057 $response = $this->server->dispatch( $request );2057 $response = rest_get_server()->dispatch( $request ); 2058 2058 2059 2059 $data = $response->get_data(); … … 2071 2071 ); 2072 2072 $request->set_body_params( $params ); 2073 $response = $this->server->dispatch( $request );2073 $response = rest_get_server()->dispatch( $request ); 2074 2074 2075 2075 $data = $response->get_data(); … … 2089 2089 ); 2090 2090 $request->set_body_params( $params ); 2091 $response = $this->server->dispatch( $request );2091 $response = rest_get_server()->dispatch( $request ); 2092 2092 2093 2093 $this->assertEquals( 201, $response->get_status() ); … … 2107 2107 ); 2108 2108 $request->set_body_params( $params ); 2109 $response = $this->server->dispatch( $request );2109 $response = rest_get_server()->dispatch( $request ); 2110 2110 2111 2111 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2122 2122 ); 2123 2123 $request->set_body_params( $params ); 2124 $response = $this->server->dispatch( $request );2124 $response = rest_get_server()->dispatch( $request ); 2125 2125 2126 2126 $data = $response->get_data(); … … 2141 2141 ); 2142 2142 $request->set_body_params( $params ); 2143 $response = $this->server->dispatch( $request );2143 $response = rest_get_server()->dispatch( $request ); 2144 2144 2145 2145 $data = $response->get_data(); … … 2169 2169 add_filter( 'query', array( $this, 'error_insert_query' ) ); 2170 2170 2171 $response = $this->server->dispatch( $request );2171 $response = rest_get_server()->dispatch( $request ); 2172 2172 remove_filter( 'query', array( $this, 'error_insert_query' ) ); 2173 2173 $wpdb->show_errors = true; … … 2186 2186 ); 2187 2187 $request->set_body_params( $params ); 2188 $response = $this->server->dispatch( $request );2188 $response = rest_get_server()->dispatch( $request ); 2189 2189 2190 2190 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2201 2201 ); 2202 2202 $request->set_body_params( $params ); 2203 $response = $this->server->dispatch( $request );2203 $response = rest_get_server()->dispatch( $request ); 2204 2204 2205 2205 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2216 2216 ); 2217 2217 $request->set_body_params( $params ); 2218 $response = $this->server->dispatch( $request );2218 $response = rest_get_server()->dispatch( $request ); 2219 2219 $new_data = $response->get_data(); 2220 2220 $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] ); … … 2234 2234 ); 2235 2235 $request->set_body_params( $params ); 2236 $response = $this->server->dispatch( $request );2236 $response = rest_get_server()->dispatch( $request ); 2237 2237 2238 2238 $data = $response->get_data(); … … 2251 2251 ); 2252 2252 $request->set_body_params( $params ); 2253 $response = $this->server->dispatch( $request );2253 $response = rest_get_server()->dispatch( $request ); 2254 2254 2255 2255 $data = $response->get_data(); … … 2269 2269 ); 2270 2270 $request->set_body_params( $params ); 2271 $response = $this->server->dispatch( $request );2271 $response = rest_get_server()->dispatch( $request ); 2272 2272 2273 2273 $data = $response->get_data(); … … 2293 2293 2294 2294 add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2295 $response = $this->server->dispatch( $request );2295 $response = rest_get_server()->dispatch( $request ); 2296 2296 remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2297 2297 … … 2313 2313 $params = $this->set_post_data(); 2314 2314 $request->set_body_params( $params ); 2315 $response = $this->server->dispatch( $request );2315 $response = rest_get_server()->dispatch( $request ); 2316 2316 2317 2317 $this->check_update_post_response( $response ); … … 2336 2336 // Run twice to make sure that the update still succeeds even if no DB 2337 2337 // rows are updated. 2338 $response = $this->server->dispatch( $request );2338 $response = rest_get_server()->dispatch( $request ); 2339 2339 $this->check_update_post_response( $response ); 2340 2340 2341 $response = $this->server->dispatch( $request );2341 $response = rest_get_server()->dispatch( $request ); 2342 2342 $this->check_update_post_response( $response ); 2343 2343 } … … 2350 2350 $params = $this->set_post_data(); 2351 2351 $request->set_body( wp_json_encode( $params ) ); 2352 $response = $this->server->dispatch( $request );2352 $response = rest_get_server()->dispatch( $request ); 2353 2353 2354 2354 $this->check_update_post_response( $response ); … … 2371 2371 $params = $this->set_raw_post_data(); 2372 2372 $request->set_body( wp_json_encode( $params ) ); 2373 $response = $this->server->dispatch( $request );2373 $response = rest_get_server()->dispatch( $request ); 2374 2374 2375 2375 $this->check_update_post_response( $response ); … … 2395 2395 unset( $params['status'] ); 2396 2396 $request->set_body_params( $params ); 2397 $response = $this->server->dispatch( $request );2397 $response = rest_get_server()->dispatch( $request ); 2398 2398 2399 2399 $this->check_update_post_response( $response ); … … 2411 2411 $params = $this->set_post_data(); 2412 2412 $request->set_body_params( $params ); 2413 $response = $this->server->dispatch( $request );2413 $response = rest_get_server()->dispatch( $request ); 2414 2414 2415 2415 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); … … 2427 2427 ); 2428 2428 $request->set_body_params( $params ); 2429 $response = $this->server->dispatch( $request );2429 $response = rest_get_server()->dispatch( $request ); 2430 2430 2431 2431 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); … … 2436 2436 2437 2437 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) ); 2438 $response = $this->server->dispatch( $request );2438 $response = rest_get_server()->dispatch( $request ); 2439 2439 2440 2440 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 2445 2445 2446 2446 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) ); 2447 $response = $this->server->dispatch( $request );2447 $response = rest_get_server()->dispatch( $request ); 2448 2448 2449 2449 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 2460 2460 ); 2461 2461 $request->set_body_params( $params ); 2462 $response = $this->server->dispatch( $request );2462 $response = rest_get_server()->dispatch( $request ); 2463 2463 2464 2464 $data = $response->get_data(); … … 2478 2478 ); 2479 2479 $request->set_body_params( $params ); 2480 $response = $this->server->dispatch( $request );2480 $response = rest_get_server()->dispatch( $request ); 2481 2481 2482 2482 $data = $response->get_data(); … … 2496 2496 ); 2497 2497 $request->set_body_params( $params ); 2498 $response = $this->server->dispatch( $request );2498 $response = rest_get_server()->dispatch( $request ); 2499 2499 2500 2500 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2516 2516 ); 2517 2517 $request->set_body_params( $params ); 2518 $response = $this->server->dispatch( $request );2518 $response = rest_get_server()->dispatch( $request ); 2519 2519 $this->assertEquals( 200, $response->get_status() ); 2520 2520 … … 2537 2537 ); 2538 2538 $request->set_body_params( $params ); 2539 $response = $this->server->dispatch( $request );2539 $response = rest_get_server()->dispatch( $request ); 2540 2540 2541 2541 // The readonly modified param should be ignored, request should be a success. … … 2567 2567 $request->set_param( 'date_gmt', $params['date_gmt'] ); 2568 2568 } 2569 $response = $this->server->dispatch( $request );2569 $response = rest_get_server()->dispatch( $request ); 2570 2570 2571 2571 update_option( 'timezone_string', '' ); … … 2594 2594 ); 2595 2595 $request->set_body_params( $params ); 2596 $response = $this->server->dispatch( $request );2596 $response = rest_get_server()->dispatch( $request ); 2597 2597 2598 2598 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2609 2609 ); 2610 2610 $request->set_body_params( $params ); 2611 $response = $this->server->dispatch( $request );2611 $response = rest_get_server()->dispatch( $request ); 2612 2612 2613 2613 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2642 2642 2643 2643 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2644 $response = $this->server->dispatch( $request );2644 $response = rest_get_server()->dispatch( $request ); 2645 2645 $this->assertEquals( 200, $response->get_status() ); 2646 2646 $data = $response->get_data(); … … 2651 2651 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2652 2652 $request->set_param( 'date', '2016-02-23T13:00:00' ); 2653 $response = $this->server->dispatch( $request );2653 $response = rest_get_server()->dispatch( $request ); 2654 2654 $this->assertEquals( 200, $response->get_status() ); 2655 2655 $data = $response->get_data(); … … 2675 2675 ); 2676 2676 $request->set_body_params( $params ); 2677 $response = $this->server->dispatch( $request );2677 $response = rest_get_server()->dispatch( $request ); 2678 2678 2679 2679 $new_data = $response->get_data(); … … 2693 2693 ); 2694 2694 $request->set_body_params( $params ); 2695 $response = $this->server->dispatch( $request );2695 $response = rest_get_server()->dispatch( $request ); 2696 2696 2697 2697 $new_data = $response->get_data(); … … 2711 2711 ); 2712 2712 $request->set_body_params( $params ); 2713 $response = $this->server->dispatch( $request );2713 $response = rest_get_server()->dispatch( $request ); 2714 2714 2715 2715 $new_data = $response->get_data(); … … 2726 2726 ); 2727 2727 $request->set_body_params( $params ); 2728 $response = $this->server->dispatch( $request );2728 $response = rest_get_server()->dispatch( $request ); 2729 2729 2730 2730 $new_data = $response->get_data(); … … 2744 2744 ); 2745 2745 2746 $response = $this->server->dispatch( $request );2746 $response = rest_get_server()->dispatch( $request ); 2747 2747 $new_data = $response->get_data(); 2748 2748 $this->assertEquals( 'An Excerpt', $new_data['excerpt']['raw'] ); … … 2759 2759 ); 2760 2760 2761 $response = $this->server->dispatch( $request );2761 $response = rest_get_server()->dispatch( $request ); 2762 2762 $new_data = $response->get_data(); 2763 2763 $this->assertEquals( '', $new_data['excerpt']['raw'] ); … … 2774 2774 ); 2775 2775 2776 $response = $this->server->dispatch( $request );2776 $response = rest_get_server()->dispatch( $request ); 2777 2777 $new_data = $response->get_data(); 2778 2778 $this->assertEquals( 'Some Content', $new_data['content']['raw'] ); … … 2789 2789 ); 2790 2790 2791 $response = $this->server->dispatch( $request );2791 $response = rest_get_server()->dispatch( $request ); 2792 2792 $new_data = $response->get_data(); 2793 2793 $this->assertEquals( '', $new_data['content']['raw'] ); … … 2810 2810 ); 2811 2811 $request->set_body_params( $params ); 2812 $response = $this->server->dispatch( $request );2812 $response = rest_get_server()->dispatch( $request ); 2813 2813 $data = $response->get_data(); 2814 2814 $this->assertEquals( '', $data['password'] ); … … 2826 2826 ); 2827 2827 $request->set_body_params( $params ); 2828 $response = $this->server->dispatch( $request );2828 $response = rest_get_server()->dispatch( $request ); 2829 2829 2830 2830 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2843 2843 ); 2844 2844 $request->set_body_params( $params ); 2845 $response = $this->server->dispatch( $request );2845 $response = rest_get_server()->dispatch( $request ); 2846 2846 2847 2847 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2865 2865 ); 2866 2866 $request->set_body_params( $params ); 2867 $response = $this->server->dispatch( $request );2867 $response = rest_get_server()->dispatch( $request ); 2868 2868 2869 2869 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2880 2880 ); 2881 2881 $request->set_body_params( $params ); 2882 $response = $this->server->dispatch( $request );2882 $response = rest_get_server()->dispatch( $request ); 2883 2883 $new_data = $response->get_data(); 2884 2884 $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] ); … … 2900 2900 ); 2901 2901 $request->set_body_params( $params ); 2902 $response = $this->server->dispatch( $request );2902 $response = rest_get_server()->dispatch( $request ); 2903 2903 $new_data = $response->get_data(); 2904 2904 $this->assertEquals( array( $category['term_id'] ), $new_data['categories'] ); … … 2915 2915 unset( $args['rest_route'] ); 2916 2916 $request->set_query_params( $args ); 2917 $response = $this->server->dispatch( $request );2917 $response = rest_get_server()->dispatch( $request ); 2918 2918 $data = $response->get_data(); 2919 2919 $this->assertCount( 1, $data ); … … 2935 2935 ); 2936 2936 $request->set_body_params( $params ); 2937 $response = $this->server->dispatch( $request );2937 $response = rest_get_server()->dispatch( $request ); 2938 2938 $new_data = $response->get_data(); 2939 2939 $this->assertEquals( array(), $new_data['categories'] ); … … 2958 2958 2959 2959 add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2960 $response = $this->server->dispatch( $request );2960 $response = rest_get_server()->dispatch( $request ); 2961 2961 remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2962 2962 … … 2984 2984 ); 2985 2985 $request->set_body_params( $params ); 2986 $response = $this->server->dispatch( $request );2986 $response = rest_get_server()->dispatch( $request ); 2987 2987 2988 2988 $data = $response->get_data(); … … 3014 3014 ); 3015 3015 $request->set_body_params( $params ); 3016 $response = $this->server->dispatch( $request );3016 $response = rest_get_server()->dispatch( $request ); 3017 3017 3018 3018 $data = $response->get_data(); … … 3042 3042 ); 3043 3043 $request->set_body_params( $params ); 3044 $response = $this->server->dispatch( $request );3044 $response = rest_get_server()->dispatch( $request ); 3045 3045 3046 3046 $this->assertEquals( 200, $response->get_status() ); … … 3059 3059 $request->set_param( $name, $value ); 3060 3060 } 3061 $response = $this->server->dispatch( $request );3061 $response = rest_get_server()->dispatch( $request ); 3062 3062 $this->assertEquals( 201, $response->get_status() ); 3063 3063 $actual_output = $response->get_data(); … … 3082 3082 $request->set_param( $name, $value ); 3083 3083 } 3084 $response = $this->server->dispatch( $request );3084 $response = rest_get_server()->dispatch( $request ); 3085 3085 $this->assertEquals( 200, $response->get_status() ); 3086 3086 $actual_output = $response->get_data(); … … 3287 3287 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 3288 3288 $request->set_param( 'force', 'false' ); 3289 $response = $this->server->dispatch( $request );3289 $response = rest_get_server()->dispatch( $request ); 3290 3290 3291 3291 $this->assertEquals( 200, $response->get_status() ); … … 3301 3301 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 3302 3302 $request['force'] = true; 3303 $response = $this->server->dispatch( $request );3303 $response = rest_get_server()->dispatch( $request ); 3304 3304 3305 3305 $this->assertEquals( 200, $response->get_status() ); … … 3313 3313 wp_set_current_user( self::$editor_id ); 3314 3314 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 3315 $response = $this->server->dispatch( $request );3315 $response = rest_get_server()->dispatch( $request ); 3316 3316 $this->assertEquals( 200, $response->get_status() ); 3317 $response = $this->server->dispatch( $request );3317 $response = rest_get_server()->dispatch( $request ); 3318 3318 $this->assertErrorResponse( 'rest_already_trashed', $response, 410 ); 3319 3319 } … … 3323 3323 3324 3324 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 3325 $response = $this->server->dispatch( $request );3325 $response = rest_get_server()->dispatch( $request ); 3326 3326 3327 3327 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 3333 3333 3334 3334 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id ); 3335 $response = $this->server->dispatch( $request );3335 $response = rest_get_server()->dispatch( $request ); 3336 3336 3337 3337 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 3342 3342 3343 3343 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3344 $response = $this->server->dispatch( $request );3344 $response = rest_get_server()->dispatch( $request ); 3345 3345 3346 3346 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); … … 3356 3356 ); 3357 3357 create_initial_rest_routes(); 3358 $routes = $this->server->get_routes();3358 $routes = rest_get_server()->get_routes(); 3359 3359 $this->assertFalse( isset( $routes['/wp/v2/invalid-controller'] ) ); 3360 3360 _unregister_post_type( 'invalid-controller' ); … … 3364 3364 public function test_get_item_schema() { 3365 3365 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3366 $response = $this->server->dispatch( $request );3366 $response = rest_get_server()->dispatch( $request ); 3367 3367 $data = $response->get_data(); 3368 3368 $properties = $data['schema']['properties']; … … 3400 3400 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3401 3401 $request->set_param( 'context', 'view' ); 3402 $response = $this->server->dispatch( $request );3402 $response = rest_get_server()->dispatch( $request ); 3403 3403 $keys = array_keys( $response->get_data() ); 3404 3404 sort( $keys ); … … 3438 3438 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3439 3439 $request->set_param( 'context', 'edit' ); 3440 $response = $this->server->dispatch( $request );3440 $response = rest_get_server()->dispatch( $request ); 3441 3441 $keys = array_keys( $response->get_data() ); 3442 3442 sort( $keys ); … … 3475 3475 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3476 3476 $request->set_param( 'context', 'embed' ); 3477 $response = $this->server->dispatch( $request );3477 $response = rest_get_server()->dispatch( $request ); 3478 3478 $keys = array_keys( $response->get_data() ); 3479 3479 sort( $keys ); … … 3496 3496 public function test_status_array_enum_args() { 3497 3497 $request = new WP_REST_Request( 'GET', '/wp/v2' ); 3498 $response = $this->server->dispatch( $request );3498 $response = rest_get_server()->dispatch( $request ); 3499 3499 $data = $response->get_data(); 3500 3500 $list_posts_args = $data['routes']['/wp/v2/posts']['endpoints'][0]['args']; … … 3528 3528 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3529 3529 3530 $response = $this->server->dispatch( $request );3530 $response = rest_get_server()->dispatch( $request ); 3531 3531 $data = $response->get_data(); 3532 3532 … … 3540 3540 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3541 3541 3542 $response = $this->server->dispatch( $request );3542 $response = rest_get_server()->dispatch( $request ); 3543 3543 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 3544 3544 … … 3550 3550 ); 3551 3551 3552 $response = $this->server->dispatch( $request );3552 $response = rest_get_server()->dispatch( $request ); 3553 3553 $this->assertEquals( 123, get_post_meta( $post_id, 'my_custom_int', true ) ); 3554 3554 … … 3561 3561 ); 3562 3562 3563 $response = $this->server->dispatch( $request );3563 $response = rest_get_server()->dispatch( $request ); 3564 3564 3565 3565 $this->assertEquals( 123, $response->data['my_custom_int'] ); … … 3594 3594 ); 3595 3595 3596 $response = $this->server->dispatch( $request );3596 $response = rest_get_server()->dispatch( $request ); 3597 3597 3598 3598 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
Note: See TracChangeset
for help on using the changeset viewer.