Changeset 42724
- Timestamp:
- 02/21/2018 04:24:30 PM (7 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/bootstrap.php
r42343 r42724 86 86 // Allow tests to override wp_die 87 87 tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter' ); 88 // Use the Spy REST Server instead of default 89 tests_add_filter( 'wp_rest_server_class', '_wp_rest_server_class_filter' ); 88 90 89 91 // Preset WordPress options defined in bootstrap file. -
trunk/tests/phpunit/includes/functions.php
r42381 r42724 181 181 } 182 182 183 /** 184 * Use the Spy_REST_Server class for the REST server. 185 */ 186 function _wp_rest_server_class_filter() { 187 return 'Spy_REST_Server'; 188 } 189 183 190 // Skip `setcookie` calls in auth_cookie functions due to warning: 184 191 // Cannot modify header information - headers already sent by ... -
trunk/tests/phpunit/includes/testcase-rest-controller.php
r39177 r42724 10 10 /** @var WP_REST_Server $wp_rest_server */ 11 11 global $wp_rest_server; 12 $ this->server = $wp_rest_server = new Spy_REST_Server;13 do_action( 'rest_api_init' );12 $wp_rest_server = new Spy_REST_Server; 13 do_action( 'rest_api_init', $wp_rest_server ); 14 14 } 15 15 -
trunk/tests/phpunit/tests/oembed/controller.php
r42343 r42724 46 46 /** @var WP_REST_Server $wp_rest_server */ 47 47 global $wp_rest_server; 48 $ this->server = $wp_rest_server = new Spy_REST_Server();49 50 do_action( 'rest_api_init', $this->server ); 48 $wp_rest_server = new Spy_REST_Server; 49 do_action( 'rest_api_init', $wp_rest_server ); 50 51 51 add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 ); 52 52 $this->request_count = 0; … … 55 55 public function tearDown() { 56 56 parent::tearDown(); 57 /** @var WP_REST_Server $wp_rest_server */ 58 global $wp_rest_server; 59 $wp_rest_server = null; 57 60 58 61 remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 ); … … 180 183 public function test_route_availability() { 181 184 // Check the route was registered correctly. 182 $filtered_routes = $this->server->get_routes();185 $filtered_routes = rest_get_server()->get_routes(); 183 186 $this->assertArrayHasKey( '/oembed/1.0/embed', $filtered_routes ); 184 187 $route = $filtered_routes['/oembed/1.0/embed']; … … 201 204 $request = new WP_REST_Request( 'POST', '/oembed/1.0/embed' ); 202 205 203 $response = $this->server->dispatch( $request );206 $response = rest_get_server()->dispatch( $request ); 204 207 $data = $response->get_data(); 205 208 … … 210 213 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 211 214 212 $response = $this->server->dispatch( $request );215 $response = rest_get_server()->dispatch( $request ); 213 216 $data = $response->get_data(); 214 217 … … 221 224 $request->set_param( 'url', 'http://google.com/' ); 222 225 223 $response = $this->server->dispatch( $request );226 $response = rest_get_server()->dispatch( $request ); 224 227 $data = $response->get_data(); 225 228 … … 234 237 $request->set_param( 'format', 'random' ); 235 238 236 $response = $this->server->dispatch( $request );239 $response = rest_get_server()->dispatch( $request ); 237 240 $data = $response->get_data(); 238 241 … … 258 261 $request->set_param( 'maxwidth', 400 ); 259 262 260 $response = $this->server->dispatch( $request );263 $response = rest_get_server()->dispatch( $request ); 261 264 $data = $response->get_data(); 262 265 … … 301 304 $request->set_param( 'maxwidth', 400 ); 302 305 303 $response = $this->server->dispatch( $request );306 $response = rest_get_server()->dispatch( $request ); 304 307 $data = $response->get_data(); 305 308 … … 346 349 $request->set_param( 'maxwidth', 400 ); 347 350 348 $response = $this->server->dispatch( $request );351 $response = rest_get_server()->dispatch( $request ); 349 352 $data = $response->get_data(); 350 353 … … 389 392 $request->set_param( 'maxwidth', 400 ); 390 393 391 $response = $this->server->dispatch( $request );394 $response = rest_get_server()->dispatch( $request ); 392 395 $data = $response->get_data(); 393 396 … … 415 418 $request->set_param( 'format', 'xml' ); 416 419 417 $response = $this->server->dispatch( $request );418 $output = get_echo( '_oembed_rest_pre_serve_request', array( true, $response, $request, $this->server) );420 $response = rest_get_server()->dispatch( $request ); 421 $output = get_echo( '_oembed_rest_pre_serve_request', array( true, $response, $request, rest_get_server() ) ); 419 422 420 423 $xml = simplexml_load_string( $output ); … … 429 432 $request->set_param( 'format', 'json' ); 430 433 431 $response = $this->server->dispatch( $request );432 433 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, $this->server) );434 $response = rest_get_server()->dispatch( $request ); 435 436 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) ); 434 437 } 435 438 … … 441 444 $request->set_param( 'format', 'xml' ); 442 445 443 $response = $this->server->dispatch( $request );444 445 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, $this->server) );446 $response = rest_get_server()->dispatch( $request ); 447 448 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) ); 446 449 } 447 450 … … 478 481 // Test without a login. 479 482 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 480 $response = $this->server->dispatch( $request );483 $response = rest_get_server()->dispatch( $request ); 481 484 482 485 $this->assertEquals( 400, $response->get_status() ); … … 486 489 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 487 490 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 488 $response = $this->server->dispatch( $request );491 $response = rest_get_server()->dispatch( $request ); 489 492 490 493 $this->assertEquals( 403, $response->get_status() ); … … 497 500 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 498 501 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 499 $response = $this->server->dispatch( $request );502 $response = rest_get_server()->dispatch( $request ); 500 503 $this->assertEquals( 404, $response->get_status() ); 501 504 $data = $response->get_data(); … … 507 510 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 508 511 $request->set_param( 'type', 'xml' ); 509 $response = $this->server->dispatch( $request );512 $response = rest_get_server()->dispatch( $request ); 510 513 511 514 $this->assertEquals( 400, $response->get_status() ); … … 519 522 $request->set_param( 'maxheight', 789 ); 520 523 $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) ); 521 $response = $this->server->dispatch( $request );524 $response = rest_get_server()->dispatch( $request ); 522 525 $this->assertEquals( 200, $response->get_status() ); 523 526 $this->assertEquals( 1, $this->request_count ); 524 527 525 528 // Subsequent request is cached and so it should not cause a request. 526 $this->server->dispatch( $request );529 rest_get_server()->dispatch( $request ); 527 530 $this->assertEquals( 1, $this->request_count ); 528 531 … … 534 537 $request->set_param( 'maxwidth', 456 ); 535 538 $request->set_param( 'maxheight', 789 ); 536 $response = $this->server->dispatch( $request );539 $response = rest_get_server()->dispatch( $request ); 537 540 $this->assertEquals( 1, $this->request_count ); 538 541 … … 555 558 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 556 559 $request->set_param( 'discover', 0 ); 557 $response = $this->server->dispatch( $request );560 $response = rest_get_server()->dispatch( $request ); 558 561 $this->assertEquals( 404, $response->get_status() ); 559 562 $this->assertEquals( 0, $this->request_count ); … … 566 569 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); 567 570 $request->set_param( 'url', self::INVALID_OEMBED_URL ); 568 $response = $this->server->dispatch( $request );571 $response = rest_get_server()->dispatch( $request ); 569 572 $this->assertEquals( 404, $response->get_status() ); 570 573 $this->assertEquals( 1, $this->request_count ); … … 577 580 $request->set_param( 'discover', 'notaboolean' ); 578 581 579 $response = $this->server->dispatch( $request );582 $response = rest_get_server()->dispatch( $request ); 580 583 581 584 $this->assertEquals( 400, $response->get_status() ); -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r42423 r42724 77 77 78 78 public function test_register_routes() { 79 $routes = $this->server->get_routes();79 $routes = rest_get_server()->get_routes(); 80 80 $this->assertArrayHasKey( '/wp/v2/media', $routes ); 81 81 $this->assertCount( 2, $routes['/wp/v2/media'] ); … … 128 128 // Collection 129 129 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' ); 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'] ); … … 140 140 ); 141 141 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media/' . $attachment_id ); 142 $response = $this->server->dispatch( $request );142 $response = rest_get_server()->dispatch( $request ); 143 143 $data = $response->get_data(); 144 144 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 148 148 public function test_registered_query_params() { 149 149 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' ); 150 $response = $this->server->dispatch( $request );150 $response = rest_get_server()->dispatch( $request ); 151 151 $data = $response->get_data(); 152 152 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 195 195 ); 196 196 $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/media/%d', $id1 ) ); 197 $response = $this->server->dispatch( $request );197 $response = rest_get_server()->dispatch( $request ); 198 198 $data = $response->get_data(); 199 199 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 225 225 ); 226 226 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 227 $response = $this->server->dispatch( $request );227 $response = rest_get_server()->dispatch( $request ); 228 228 $data = $response->get_data(); 229 229 $this->assertCount( 2, $data ); … … 259 259 ); 260 260 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 261 $response = $this->server->dispatch( $request );261 $response = rest_get_server()->dispatch( $request ); 262 262 263 263 $data = $response->get_data(); … … 276 276 ); 277 277 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 278 $response = $this->server->dispatch( $request );278 $response = rest_get_server()->dispatch( $request ); 279 279 $data = $response->get_data(); 280 280 $this->assertEquals( $id1, $data[0]['id'] ); 281 281 // media_type=video 282 282 $request->set_param( 'media_type', 'video' ); 283 $response = $this->server->dispatch( $request );283 $response = rest_get_server()->dispatch( $request ); 284 284 $this->assertCount( 0, $response->get_data() ); 285 285 // media_type=image 286 286 $request->set_param( 'media_type', 'image' ); 287 $response = $this->server->dispatch( $request );287 $response = rest_get_server()->dispatch( $request ); 288 288 $data = $response->get_data(); 289 289 $this->assertEquals( $id1, $data[0]['id'] ); … … 297 297 ); 298 298 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 299 $response = $this->server->dispatch( $request );299 $response = rest_get_server()->dispatch( $request ); 300 300 $data = $response->get_data(); 301 301 $this->assertEquals( $id1, $data[0]['id'] ); 302 302 // mime_type=image/png 303 303 $request->set_param( 'mime_type', 'image/png' ); 304 $response = $this->server->dispatch( $request );304 $response = rest_get_server()->dispatch( $request ); 305 305 $this->assertCount( 0, $response->get_data() ); 306 306 // mime_type=image/jpeg 307 307 $request->set_param( 'mime_type', 'image/jpeg' ); 308 $response = $this->server->dispatch( $request );308 $response = rest_get_server()->dispatch( $request ); 309 309 $data = $response->get_data(); 310 310 $this->assertEquals( $id1, $data[0]['id'] ); … … 327 327 // all attachments 328 328 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 329 $response = $this->server->dispatch( $request );329 $response = rest_get_server()->dispatch( $request ); 330 330 $this->assertEquals( 2, count( $response->get_data() ) ); 331 331 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 332 332 // attachments without a parent 333 333 $request->set_param( 'parent', 0 ); 334 $response = $this->server->dispatch( $request );334 $response = rest_get_server()->dispatch( $request ); 335 335 $data = $response->get_data(); 336 336 $this->assertEquals( 1, count( $data ) ); … … 339 339 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 340 340 $request->set_param( 'parent', $post_id ); 341 $response = $this->server->dispatch( $request );341 $response = rest_get_server()->dispatch( $request ); 342 342 $data = $response->get_data(); 343 343 $this->assertEquals( 1, count( $data ) ); … … 346 346 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 347 347 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 348 $response = $this->server->dispatch( $request );348 $response = rest_get_server()->dispatch( $request ); 349 349 $data = $response->get_data(); 350 350 $this->assertEquals( 0, count( $data ) ); … … 362 362 $request->set_param( 'status', 'publish' ); 363 363 $request->set_param( 'context', 'edit' ); 364 $response = $this->server->dispatch( $request );364 $response = rest_get_server()->dispatch( $request ); 365 365 $data = $response->get_data(); 366 366 $this->assertCount( 3, $data ); … … 380 380 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 381 381 $request->set_param( 'status', 'private' ); 382 $response = $this->server->dispatch( $request );382 $response = rest_get_server()->dispatch( $request ); 383 383 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 384 384 // Properly authorized users can make the request 385 385 wp_set_current_user( self::$editor_id ); 386 $response = $this->server->dispatch( $request );386 $response = rest_get_server()->dispatch( $request ); 387 387 $this->assertEquals( 200, $response->get_status() ); 388 388 $data = $response->get_data(); … … 409 409 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 410 410 $request->set_param( 'status', array( 'private', 'trash' ) ); 411 $response = $this->server->dispatch( $request );411 $response = rest_get_server()->dispatch( $request ); 412 412 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 413 413 // Properly authorized users can make the request 414 414 wp_set_current_user( self::$editor_id ); 415 $response = $this->server->dispatch( $request );415 $response = rest_get_server()->dispatch( $request ); 416 416 $this->assertEquals( 200, $response->get_status() ); 417 417 $data = $response->get_data(); … … 429 429 $request->set_param( 'after', rand_str() ); 430 430 $request->set_param( 'before', rand_str() ); 431 $response = $this->server->dispatch( $request );431 $response = rest_get_server()->dispatch( $request ); 432 432 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 433 433 } … … 458 458 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 459 459 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 460 $response = $this->server->dispatch( $request );460 $response = rest_get_server()->dispatch( $request ); 461 461 $data = $response->get_data(); 462 462 $this->assertCount( 1, $data ); … … 473 473 update_post_meta( $attachment_id, '_wp_attachment_image_alt', 'Sample alt text' ); 474 474 $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id ); 475 $response = $this->server->dispatch( $request );475 $response = rest_get_server()->dispatch( $request ); 476 476 $this->check_get_post_response( $response ); 477 477 $data = $response->get_data(); … … 491 491 492 492 $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id ); 493 $response = $this->server->dispatch( $request );493 $response = rest_get_server()->dispatch( $request ); 494 494 $data = $response->get_data(); 495 495 $image_src = wp_get_attachment_image_src( $attachment_id, 'rest-api-test' ); … … 517 517 518 518 $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id ); 519 $response = $this->server->dispatch( $request );519 $response = rest_get_server()->dispatch( $request ); 520 520 $data = $response->get_data(); 521 521 remove_filter( 'wp_get_attachment_image_src', '__return_false' ); … … 535 535 ); 536 536 $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $id1 ); 537 $response = $this->server->dispatch( $request );537 $response = rest_get_server()->dispatch( $request ); 538 538 $this->assertEquals( 401, $response->get_status() ); 539 539 } … … 547 547 ); 548 548 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/media/%d', $attachment_id ) ); 549 $response = $this->server->dispatch( $request );549 $response = rest_get_server()->dispatch( $request ); 550 550 $data = $response->get_data(); 551 551 … … 563 563 ); 564 564 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/media/%d', $attachment_id ) ); 565 $response = $this->server->dispatch( $request );565 $response = rest_get_server()->dispatch( $request ); 566 566 567 567 $this->assertErrorResponse( 'rest_forbidden', $response, 401 ); … … 580 580 581 581 $request->set_body( file_get_contents( $this->test_file ) ); 582 $response = $this->server->dispatch( $request );582 $response = rest_get_server()->dispatch( $request ); 583 583 $data = $response->get_data(); 584 584 … … 611 611 ); 612 612 $request->set_header( 'Content-MD5', md5_file( $this->test_file2 ) ); 613 $response = $this->server->dispatch( $request );613 $response = rest_get_server()->dispatch( $request ); 614 614 $this->assertEquals( 201, $response->get_status() ); 615 615 $data = $response->get_data(); … … 631 631 ); 632 632 $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); 633 $response = $this->server->dispatch( $request );633 $response = rest_get_server()->dispatch( $request ); 634 634 $this->assertEquals( 201, $response->get_status() ); 635 635 } … … 649 649 ); 650 650 $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); 651 $response = $this->server->dispatch( $request );651 $response = rest_get_server()->dispatch( $request ); 652 652 $this->assertEquals( 201, $response->get_status() ); 653 653 } … … 656 656 wp_set_current_user( self::$author_id ); 657 657 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 658 $response = $this->server->dispatch( $request );658 $response = rest_get_server()->dispatch( $request ); 659 659 $this->assertErrorResponse( 'rest_upload_no_data', $response, 400 ); 660 660 } … … 664 664 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 665 665 $request->set_body( file_get_contents( $this->test_file ) ); 666 $response = $this->server->dispatch( $request );666 $response = rest_get_server()->dispatch( $request ); 667 667 $this->assertErrorResponse( 'rest_upload_no_content_type', $response, 400 ); 668 668 } … … 673 673 $request->set_header( 'Content-Type', 'image/jpeg' ); 674 674 $request->set_body( file_get_contents( $this->test_file ) ); 675 $response = $this->server->dispatch( $request );675 $response = rest_get_server()->dispatch( $request ); 676 676 $this->assertErrorResponse( 'rest_upload_no_content_disposition', $response, 400 ); 677 677 } … … 684 684 $request->set_header( 'Content-MD5', 'abc123' ); 685 685 $request->set_body( file_get_contents( $this->test_file ) ); 686 $response = $this->server->dispatch( $request );686 $response = rest_get_server()->dispatch( $request ); 687 687 $this->assertErrorResponse( 'rest_upload_hash_mismatch', $response, 412 ); 688 688 } … … 702 702 ); 703 703 $request->set_header( 'Content-MD5', 'abc123' ); 704 $response = $this->server->dispatch( $request );704 $response = rest_get_server()->dispatch( $request ); 705 705 $this->assertErrorResponse( 'rest_upload_hash_mismatch', $response, 412 ); 706 706 } … … 709 709 wp_set_current_user( self::$contributor_id ); 710 710 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 711 $response = $this->server->dispatch( $request );711 $response = rest_get_server()->dispatch( $request ); 712 712 $this->assertErrorResponse( 'rest_cannot_create', $response, 403 ); 713 713 } … … 718 718 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 719 719 $request->set_param( 'post', $post_id ); 720 $response = $this->server->dispatch( $request );720 $response = rest_get_server()->dispatch( $request ); 721 721 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); 722 722 } … … 727 727 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 728 728 $request->set_param( 'post', $post_id ); 729 $response = $this->server->dispatch( $request );729 $response = rest_get_server()->dispatch( $request ); 730 730 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); 731 731 } … … 745 745 $request->set_body( file_get_contents( $this->test_file ) ); 746 746 $request->set_param( 'post', $attachment_id ); 747 $response = $this->server->dispatch( $request );747 $response = rest_get_server()->dispatch( $request ); 748 748 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 749 749 } … … 757 757 $request->set_body( file_get_contents( $this->test_file ) ); 758 758 $request->set_param( 'alt_text', 'test alt text' ); 759 $response = $this->server->dispatch( $request );759 $response = rest_get_server()->dispatch( $request ); 760 760 $attachment = $response->get_data(); 761 761 $this->assertEquals( 'test alt text', $attachment['alt_text'] ); … … 769 769 $request->set_body( file_get_contents( $this->test_file ) ); 770 770 $request->set_param( 'alt_text', '<script>alert(document.cookie)</script>' ); 771 $response = $this->server->dispatch( $request );771 $response = rest_get_server()->dispatch( $request ); 772 772 $attachment = $response->get_data(); 773 773 $this->assertEquals( '', $attachment['alt_text'] ); … … 788 788 $request->set_param( 'description', 'Without a description, my attachment is descriptionless.' ); 789 789 $request->set_param( 'alt_text', 'Alt text is stored outside post schema.' ); 790 $response = $this->server->dispatch( $request );790 $response = rest_get_server()->dispatch( $request ); 791 791 $data = $response->get_data(); 792 792 $attachment = get_post( $data['id'] ); … … 818 818 $request = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id ); 819 819 $request->set_param( 'post', $new_parent ); 820 $this->server->dispatch( $request );820 rest_get_server()->dispatch( $request ); 821 821 822 822 $attachment = get_post( $attachment_id ); … … 835 835 $request = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id ); 836 836 $request->set_param( 'caption', 'This is a better caption.' ); 837 $response = $this->server->dispatch( $request );837 $response = rest_get_server()->dispatch( $request ); 838 838 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); 839 839 } … … 857 857 $request = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id ); 858 858 $request->set_param( 'post', $attachment_id ); 859 $response = $this->server->dispatch( $request );859 $response = rest_get_server()->dispatch( $request ); 860 860 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 861 861 } … … 871 871 $request->set_param( $name, $value ); 872 872 } 873 $response = $this->server->dispatch( $request );873 $response = rest_get_server()->dispatch( $request ); 874 874 $this->assertEquals( 201, $response->get_status() ); 875 875 $actual_output = $response->get_data(); … … 903 903 $request->set_param( $name, $value ); 904 904 } 905 $response = $this->server->dispatch( $request );905 $response = rest_get_server()->dispatch( $request ); 906 906 $this->assertEquals( 200, $response->get_status() ); 907 907 $actual_output = $response->get_data(); … … 1121 1121 $request = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id ); 1122 1122 $request['force'] = true; 1123 $response = $this->server->dispatch( $request );1123 $response = rest_get_server()->dispatch( $request ); 1124 1124 $this->assertEquals( 200, $response->get_status() ); 1125 1125 } … … 1136 1136 // Attempt trashing 1137 1137 $request = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id ); 1138 $response = $this->server->dispatch( $request );1138 $response = rest_get_server()->dispatch( $request ); 1139 1139 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1140 1140 1141 1141 $request->set_param( 'force', 'false' ); 1142 $response = $this->server->dispatch( $request );1142 $response = rest_get_server()->dispatch( $request ); 1143 1143 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1144 1144 … … 1158 1158 ); 1159 1159 $request = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id ); 1160 $response = $this->server->dispatch( $request );1160 $response = rest_get_server()->dispatch( $request ); 1161 1161 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); 1162 1162 } … … 1173 1173 $attachment = get_post( $attachment_id ); 1174 1174 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/media/%d', $attachment_id ) ); 1175 $response = $this->server->dispatch( $request );1175 $response = rest_get_server()->dispatch( $request ); 1176 1176 $data = $response->get_data(); 1177 1177 $this->check_post_data( $attachment, $data, 'view', $response->get_links() ); … … 1181 1181 public function test_get_item_schema() { 1182 1182 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' ); 1183 $response = $this->server->dispatch( $request );1183 $response = rest_get_server()->dispatch( $request ); 1184 1184 $data = $response->get_data(); 1185 1185 $properties = $data['schema']['properties']; … … 1235 1235 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' ); 1236 1236 1237 $response = $this->server->dispatch( $request );1237 $response = rest_get_server()->dispatch( $request ); 1238 1238 $data = $response->get_data(); 1239 1239 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 1249 1249 $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id ); 1250 1250 1251 $response = $this->server->dispatch( $request );1251 $response = rest_get_server()->dispatch( $request ); 1252 1252 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 1253 1253 … … 1288 1288 ); 1289 1289 1290 $response = $this->server->dispatch( $request );1290 $response = rest_get_server()->dispatch( $request ); 1291 1291 1292 1292 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1312 1312 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 1313 1313 $request->set_param( 'search', $filename ); 1314 $response = $this->server->dispatch( $request );1314 $response = rest_get_server()->dispatch( $request ); 1315 1315 $data = $response->get_data(); 1316 1316 -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r42354 r42724 34 34 35 35 public function test_register_routes() { 36 $routes = $this->server->get_routes();36 $routes = rest_get_server()->get_routes(); 37 37 $this->assertArrayHasKey( '/wp/v2/categories', $routes ); 38 38 $this->assertArrayHasKey( '/wp/v2/categories/(?P<id>[\d]+)', $routes ); … … 42 42 // Collection 43 43 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 44 $response = $this->server->dispatch( $request );44 $response = rest_get_server()->dispatch( $request ); 45 45 $data = $response->get_data(); 46 46 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 49 49 $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) ); 50 50 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 ); 51 $response = $this->server->dispatch( $request );51 $response = rest_get_server()->dispatch( $request ); 52 52 $data = $response->get_data(); 53 53 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 57 57 public function test_registered_query_params() { 58 58 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 59 $response = $this->server->dispatch( $request );59 $response = rest_get_server()->dispatch( $request ); 60 60 $data = $response->get_data(); 61 61 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 81 81 public function test_get_items() { 82 82 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 83 $response = $this->server->dispatch( $request );83 $response = rest_get_server()->dispatch( $request ); 84 84 $this->check_get_taxonomy_terms_response( $response ); 85 85 } … … 89 89 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 90 90 $request->set_param( 'context', 'edit' ); 91 $response = $this->server->dispatch( $request );91 $response = rest_get_server()->dispatch( $request ); 92 92 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 93 93 } … … 100 100 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 101 101 $request->set_param( 'hide_empty', true ); 102 $response = $this->server->dispatch( $request );102 $response = rest_get_server()->dispatch( $request ); 103 103 $data = $response->get_data(); 104 104 $this->assertEquals( 2, count( $data ) ); … … 108 108 // Confirm the empty category "Uncategorized" category appears. 109 109 $request->set_param( 'hide_empty', 'false' ); 110 $response = $this->server->dispatch( $request );110 $response = rest_get_server()->dispatch( $request ); 111 111 $data = $response->get_data(); 112 112 $this->assertEquals( 3, count( $data ) ); … … 130 130 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 131 131 $request->set_param( 'parent', 0 ); 132 $response = $this->server->dispatch( $request );132 $response = rest_get_server()->dispatch( $request ); 133 133 134 134 $this->assertEquals( 200, $response->get_status() ); … … 160 160 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 161 161 $request->set_param( 'parent', '0' ); 162 $response = $this->server->dispatch( $request );162 $response = rest_get_server()->dispatch( $request ); 163 163 164 164 $this->assertEquals( 200, $response->get_status() ); … … 178 178 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 179 179 $request->set_param( 'parent', $parent1 ); 180 $response = $this->server->dispatch( $request );180 $response = rest_get_server()->dispatch( $request ); 181 181 182 182 $this->assertEquals( 200, $response->get_status() ); … … 189 189 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 190 190 $request->set_param( 'page', 0 ); 191 $response = $this->server->dispatch( $request );191 $response = rest_get_server()->dispatch( $request ); 192 192 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 193 193 $data = $response->get_data(); … … 203 203 // Orderby=>asc 204 204 $request->set_param( 'include', array( $id3, $id1 ) ); 205 $response = $this->server->dispatch( $request );205 $response = rest_get_server()->dispatch( $request ); 206 206 $data = $response->get_data(); 207 207 $this->assertEquals( 2, count( $data ) ); … … 209 209 // Orderby=>include 210 210 $request->set_param( 'orderby', 'include' ); 211 $response = $this->server->dispatch( $request );211 $response = rest_get_server()->dispatch( $request ); 212 212 $data = $response->get_data(); 213 213 $this->assertEquals( 2, count( $data ) ); … … 219 219 $id2 = $this->factory->category->create(); 220 220 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 221 $response = $this->server->dispatch( $request );221 $response = rest_get_server()->dispatch( $request ); 222 222 $data = $response->get_data(); 223 223 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 224 224 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 225 225 $request->set_param( 'exclude', array( $id2 ) ); 226 $response = $this->server->dispatch( $request );226 $response = rest_get_server()->dispatch( $request ); 227 227 $data = $response->get_data(); 228 228 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 243 243 $request->set_param( 'order', 'desc' ); 244 244 $request->set_param( 'per_page', 1 ); 245 $response = $this->server->dispatch( $request );245 $response = rest_get_server()->dispatch( $request ); 246 246 $this->assertEquals( 200, $response->get_status() ); 247 247 $data = $response->get_data(); … … 252 252 $request->set_param( 'order', 'asc' ); 253 253 $request->set_param( 'per_page', 2 ); 254 $response = $this->server->dispatch( $request );254 $response = rest_get_server()->dispatch( $request ); 255 255 $this->assertEquals( 200, $response->get_status() ); 256 256 $data = $response->get_data(); … … 265 265 // defaults to orderby=name, order=asc 266 266 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 267 $response = $this->server->dispatch( $request );267 $response = rest_get_server()->dispatch( $request ); 268 268 $this->assertEquals( 200, $response->get_status() ); 269 269 $data = $response->get_data(); … … 275 275 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 276 276 $request->set_param( 'orderby', 'id' ); 277 $response = $this->server->dispatch( $request );277 $response = rest_get_server()->dispatch( $request ); 278 278 $this->assertEquals( 200, $response->get_status() ); 279 279 $data = $response->get_data(); … … 286 286 $request->set_param( 'orderby', 'id' ); 287 287 $request->set_param( 'order', 'desc' ); 288 $response = $this->server->dispatch( $request );288 $response = rest_get_server()->dispatch( $request ); 289 289 $data = $response->get_data(); 290 290 $this->assertEquals( 200, $response->get_status() ); … … 302 302 $request->set_param( 'orderby', 'include_slugs' ); 303 303 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 304 $response = $this->server->dispatch( $request );304 $response = rest_get_server()->dispatch( $request ); 305 305 $data = $response->get_data(); 306 306 $this->assertEquals( 200, $response->get_status() ); … … 340 340 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 341 341 $request->set_param( 'post', $post_id ); 342 $response = $this->server->dispatch( $request );342 $response = rest_get_server()->dispatch( $request ); 343 343 $this->assertEquals( 200, $response->get_status() ); 344 344 … … 358 358 $request->set_param( 'post', $post_id ); 359 359 $request->set_param( 'orderby', 'description' ); 360 $response = $this->server->dispatch( $request );360 $response = rest_get_server()->dispatch( $request ); 361 361 $this->assertEquals( 200, $response->get_status() ); 362 362 … … 368 368 // Flip the order 369 369 $request->set_param( 'order', 'desc' ); 370 $response = $this->server->dispatch( $request );370 $response = rest_get_server()->dispatch( $request ); 371 371 $this->assertEquals( 200, $response->get_status() ); 372 372 … … 383 383 $request->set_param( 'post', $post_id ); 384 384 $request->set_param( 'orderby', 'id' ); 385 $response = $this->server->dispatch( $request );385 $response = rest_get_server()->dispatch( $request ); 386 386 $this->assertEquals( 200, $response->get_status() ); 387 387 … … 419 419 $request = new WP_REST_Request( 'GET', '/wp/v2/batman' ); 420 420 $request->set_param( 'post', $post_id ); 421 $response = $this->server->dispatch( $request );421 $response = rest_get_server()->dispatch( $request ); 422 422 $this->assertEquals( 200, $response->get_status() ); 423 423 … … 436 436 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 437 437 $request->set_param( 'search', 'App' ); 438 $response = $this->server->dispatch( $request );438 $response = rest_get_server()->dispatch( $request ); 439 439 $this->assertEquals( 200, $response->get_status() ); 440 440 $data = $response->get_data(); … … 443 443 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 444 444 $request->set_param( 'search', 'Garbage' ); 445 $response = $this->server->dispatch( $request );445 $response = rest_get_server()->dispatch( $request ); 446 446 $this->assertEquals( 200, $response->get_status() ); 447 447 $data = $response->get_data(); … … 454 454 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 455 455 $request->set_param( 'slug', 'apple' ); 456 $response = $this->server->dispatch( $request );456 $response = rest_get_server()->dispatch( $request ); 457 457 $this->assertEquals( 200, $response->get_status() ); 458 458 $data = $response->get_data(); … … 471 471 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 472 472 $request->set_param( 'parent', $category1 ); 473 $response = $this->server->dispatch( $request );473 $response = rest_get_server()->dispatch( $request ); 474 474 $data = $response->get_data(); 475 475 $this->assertEquals( 1, count( $data ) ); … … 487 487 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 488 488 $request->set_param( 'parent', 'invalid-parent' ); 489 $response = $this->server->dispatch( $request );489 $response = rest_get_server()->dispatch( $request ); 490 490 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 491 491 } … … 507 507 508 508 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' ); 509 $response = $this->server->dispatch( $request );509 $response = rest_get_server()->dispatch( $request ); 510 510 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 511 511 } … … 513 513 public function test_get_terms_invalid_taxonomy() { 514 514 $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy' ); 515 $response = $this->server->dispatch( $request );515 $response = rest_get_server()->dispatch( $request ); 516 516 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 517 517 } … … 527 527 } 528 528 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 529 $response = $this->server->dispatch( $request );529 $response = rest_get_server()->dispatch( $request ); 530 530 $headers = $response->get_headers(); 531 531 $this->assertEquals( 50, $headers['X-WP-Total'] ); … … 547 547 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 548 548 $request->set_param( 'page', 3 ); 549 $response = $this->server->dispatch( $request );549 $response = rest_get_server()->dispatch( $request ); 550 550 $headers = $response->get_headers(); 551 551 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 567 567 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 568 568 $request->set_param( 'page', 6 ); 569 $response = $this->server->dispatch( $request );569 $response = rest_get_server()->dispatch( $request ); 570 570 $headers = $response->get_headers(); 571 571 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 582 582 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 583 583 $request->set_param( 'page', 8 ); 584 $response = $this->server->dispatch( $request );584 $response = rest_get_server()->dispatch( $request ); 585 585 $headers = $response->get_headers(); 586 586 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 608 608 $request->set_param( 'page', 1 ); 609 609 $request->set_param( 'per_page', 100 ); 610 $response = $this->server->dispatch( $request );610 $response = rest_get_server()->dispatch( $request ); 611 611 $headers = $response->get_headers(); 612 612 $this->assertEquals( 18, $headers['X-WP-Total'] ); … … 616 616 $request->set_param( 'page', 2 ); 617 617 $request->set_param( 'per_page', 100 ); 618 $response = $this->server->dispatch( $request );618 $response = rest_get_server()->dispatch( $request ); 619 619 $headers = $response->get_headers(); 620 620 $this->assertEquals( 18, $headers['X-WP-Total'] ); … … 625 625 public function test_get_item() { 626 626 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 627 $response = $this->server->dispatch( $request );627 $response = rest_get_server()->dispatch( $request ); 628 628 $this->check_get_taxonomy_term_response( $response ); 629 629 } … … 631 631 public function test_get_term_invalid_taxonomy() { 632 632 $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' ); 633 $response = $this->server->dispatch( $request );633 $response = rest_get_server()->dispatch( $request ); 634 634 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 635 635 } … … 637 637 public function test_get_term_invalid_term() { 638 638 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 639 $response = $this->server->dispatch( $request );639 $response = rest_get_server()->dispatch( $request ); 640 640 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 641 641 } … … 645 645 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 646 646 $request->set_param( 'context', 'edit' ); 647 $response = $this->server->dispatch( $request );647 $response = rest_get_server()->dispatch( $request ); 648 648 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 649 649 } … … 659 659 660 660 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 ); 661 $response = $this->server->dispatch( $request );661 $response = rest_get_server()->dispatch( $request ); 662 662 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 663 663 } … … 672 672 ); 673 673 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $term1 ); 674 $response = $this->server->dispatch( $request );674 $response = rest_get_server()->dispatch( $request ); 675 675 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 676 676 } … … 682 682 $request->set_param( 'description', 'This term is so awesome.' ); 683 683 $request->set_param( 'slug', 'so-awesome' ); 684 $response = $this->server->dispatch( $request );684 $response = rest_get_server()->dispatch( $request ); 685 685 $this->assertEquals( 201, $response->get_status() ); 686 686 $headers = $response->get_headers(); … … 702 702 $request->set_param( 'name', 'Existing' ); 703 703 704 $response = $this->server->dispatch( $request );704 $response = rest_get_server()->dispatch( $request ); 705 705 $this->assertEquals( 400, $response->get_status() ); 706 706 $data = $response->get_data(); … … 715 715 $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy' ); 716 716 $request->set_param( 'name', 'Invalid Taxonomy' ); 717 $response = $this->server->dispatch( $request );717 $response = rest_get_server()->dispatch( $request ); 718 718 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 719 719 } … … 723 723 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 724 724 $request->set_param( 'name', 'Incorrect permissions' ); 725 $response = $this->server->dispatch( $request );725 $response = rest_get_server()->dispatch( $request ); 726 726 $this->assertErrorResponse( 'rest_cannot_create', $response, 403 ); 727 727 } … … 730 730 wp_set_current_user( self::$administrator ); 731 731 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 732 $response = $this->server->dispatch( $request );732 $response = rest_get_server()->dispatch( $request ); 733 733 $this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 ); 734 734 } … … 740 740 $request->set_param( 'name', 'My Awesome Term' ); 741 741 $request->set_param( 'parent', $parent['term_id'] ); 742 $response = $this->server->dispatch( $request );742 $response = rest_get_server()->dispatch( $request ); 743 743 $this->assertEquals( 201, $response->get_status() ); 744 744 $data = $response->get_data(); … … 753 753 $request->set_param( 'name', 'My Awesome Term' ); 754 754 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 755 $response = $this->server->dispatch( $request );755 $response = rest_get_server()->dispatch( $request ); 756 756 $this->assertErrorResponse( 'rest_term_invalid', $response, 400 ); 757 757 } … … 769 769 $request->set_param( 'description', 'New Description' ); 770 770 $request->set_param( 'slug', 'new-slug' ); 771 $response = $this->server->dispatch( $request );771 $response = rest_get_server()->dispatch( $request ); 772 772 $this->assertEquals( 200, $response->get_status() ); 773 773 $data = $response->get_data(); … … 781 781 $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 782 782 $request->set_param( 'name', 'Invalid Taxonomy' ); 783 $response = $this->server->dispatch( $request );783 $response = rest_get_server()->dispatch( $request ); 784 784 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 785 785 } … … 789 789 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 790 790 $request->set_param( 'name', 'Invalid Term' ); 791 $response = $this->server->dispatch( $request );791 $response = rest_get_server()->dispatch( $request ); 792 792 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 793 793 } … … 798 798 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); 799 799 $request->set_param( 'name', 'Incorrect permissions' ); 800 $response = $this->server->dispatch( $request );800 $response = rest_get_server()->dispatch( $request ); 801 801 $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); 802 802 } … … 809 809 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); 810 810 $request->set_param( 'parent', $parent->term_id ); 811 $response = $this->server->dispatch( $request );811 $response = rest_get_server()->dispatch( $request ); 812 812 $this->assertEquals( 200, $response->get_status() ); 813 813 … … 822 822 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); 823 823 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 824 $response = $this->server->dispatch( $request );824 $response = rest_get_server()->dispatch( $request ); 825 825 $this->assertErrorResponse( 'rest_term_invalid', $response, 400 ); 826 826 } … … 831 831 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); 832 832 $request->set_param( 'force', true ); 833 $response = $this->server->dispatch( $request );833 $response = rest_get_server()->dispatch( $request ); 834 834 $this->assertEquals( 200, $response->get_status() ); 835 835 $data = $response->get_data(); … … 843 843 844 844 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); 845 $response = $this->server->dispatch( $request );845 $response = rest_get_server()->dispatch( $request ); 846 846 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 847 847 848 848 $request->set_param( 'force', 'false' ); 849 $response = $this->server->dispatch( $request );849 $response = rest_get_server()->dispatch( $request ); 850 850 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 851 851 } … … 854 854 wp_set_current_user( self::$administrator ); 855 855 $request = new WP_REST_Request( 'DELETE', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 856 $response = $this->server->dispatch( $request );856 $response = rest_get_server()->dispatch( $request ); 857 857 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 858 858 } … … 861 861 wp_set_current_user( self::$administrator ); 862 862 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 863 $response = $this->server->dispatch( $request );863 $response = rest_get_server()->dispatch( $request ); 864 864 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 865 865 } … … 869 869 $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); 870 870 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); 871 $response = $this->server->dispatch( $request );871 $response = rest_get_server()->dispatch( $request ); 872 872 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); 873 873 } … … 877 877 878 878 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 879 $response = $this->server->dispatch( $request );879 $response = rest_get_server()->dispatch( $request ); 880 880 $data = $response->get_data(); 881 881 … … 892 892 893 893 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $child ); 894 $response = $this->server->dispatch( $request );894 $response = rest_get_server()->dispatch( $request ); 895 895 $data = $response->get_data(); 896 896 … … 905 905 public function test_get_item_schema() { 906 906 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 907 $response = $this->server->dispatch( $request );907 $response = rest_get_server()->dispatch( $request ); 908 908 $data = $response->get_data(); 909 909 $properties = $data['schema']['properties']; … … 939 939 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 940 940 941 $response = $this->server->dispatch( $request );941 $response = rest_get_server()->dispatch( $request ); 942 942 $data = $response->get_data(); 943 943 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 947 947 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id ); 948 948 949 $response = $this->server->dispatch( $request );949 $response = rest_get_server()->dispatch( $request ); 950 950 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 951 951 -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r42343 r42724 123 123 124 124 public function test_register_routes() { 125 $routes = $this->server->get_routes();125 $routes = rest_get_server()->get_routes(); 126 126 127 127 $this->assertArrayHasKey( '/wp/v2/comments', $routes ); … … 134 134 // Collection 135 135 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' ); 136 $response = $this->server->dispatch( $request );136 $response = rest_get_server()->dispatch( $request ); 137 137 $data = $response->get_data(); 138 138 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 140 140 // Single 141 141 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . self::$approved_id ); 142 $response = $this->server->dispatch( $request );142 $response = rest_get_server()->dispatch( $request ); 143 143 $data = $response->get_data(); 144 144 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 148 148 public function test_registered_query_params() { 149 149 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' ); 150 $response = $this->server->dispatch( $request );150 $response = rest_get_server()->dispatch( $request ); 151 151 $data = $response->get_data(); 152 152 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 183 183 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 184 184 185 $response = $this->server->dispatch( $request );185 $response = rest_get_server()->dispatch( $request ); 186 186 $this->assertEquals( 200, $response->get_status() ); 187 187 … … 207 207 $request->set_param( 'post', self::$password_id ); 208 208 209 $response = $this->server->dispatch( $request );209 $response = rest_get_server()->dispatch( $request ); 210 210 $this->assertEquals( 200, $response->get_status() ); 211 211 … … 228 228 $request->set_param( 'password', 'toomanysecrets' ); 229 229 230 $response = $this->server->dispatch( $request );230 $response = rest_get_server()->dispatch( $request ); 231 231 $this->assertEquals( 200, $response->get_status() ); 232 232 … … 250 250 $request->set_param( 'post', array( self::$password_id, self::$post_id ) ); 251 251 252 $response = $this->server->dispatch( $request );252 $response = rest_get_server()->dispatch( $request ); 253 253 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 401 ); 254 254 } … … 265 265 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 266 266 267 $response = $this->server->dispatch( $request );267 $response = rest_get_server()->dispatch( $request ); 268 268 $this->assertEquals( 200, $response->get_status() ); 269 269 … … 283 283 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 284 284 285 $response = $this->server->dispatch( $request );285 $response = rest_get_server()->dispatch( $request ); 286 286 $this->assertEquals( 200, $response->get_status() ); 287 287 … … 301 301 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 302 302 303 $response = $this->server->dispatch( $request );303 $response = rest_get_server()->dispatch( $request ); 304 304 $this->assertEquals( 200, $response->get_status() ); 305 305 … … 319 319 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 320 320 321 $response = $this->server->dispatch( $request );321 $response = rest_get_server()->dispatch( $request ); 322 322 $this->assertEquals( 200, $response->get_status() ); 323 323 … … 338 338 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 339 339 340 $response = $this->server->dispatch( $request );340 $response = rest_get_server()->dispatch( $request ); 341 341 $this->assertEquals( 200, $response->get_status() ); 342 342 … … 359 359 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 360 360 361 $response = $this->server->dispatch( $request );361 $response = rest_get_server()->dispatch( $request ); 362 362 $this->assertEquals( 200, $response->get_status() ); 363 363 … … 372 372 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 373 373 $request->set_param( 'context', 'edit' ); 374 $response = $this->server->dispatch( $request );374 $response = rest_get_server()->dispatch( $request ); 375 375 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 376 376 } … … 381 381 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 382 382 $request->set_param( 'post', 0 ); 383 $response = $this->server->dispatch( $request );383 $response = rest_get_server()->dispatch( $request ); 384 384 $this->assertEquals( 200, $response->get_status() ); 385 385 $comments = $response->get_data(); … … 391 391 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 392 392 $request->set_param( 'post', 0 ); 393 $response = $this->server->dispatch( $request );393 $response = rest_get_server()->dispatch( $request ); 394 394 $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); 395 395 } … … 399 399 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 400 400 $request->set_param( 'context', 'edit' ); 401 $response = $this->server->dispatch( $request );401 $response = rest_get_server()->dispatch( $request ); 402 402 $this->assertEquals( 200, $response->get_status() ); 403 403 } … … 414 414 ); 415 415 416 $response = $this->server->dispatch( $request );416 $response = rest_get_server()->dispatch( $request ); 417 417 $this->assertEquals( 200, $response->get_status() ); 418 418 … … 434 434 $request->set_param( 'order', 'asc' ); 435 435 $request->set_param( 'include', array( $id3, $id1 ) ); 436 $response = $this->server->dispatch( $request );436 $response = rest_get_server()->dispatch( $request ); 437 437 $data = $response->get_data(); 438 438 $this->assertEquals( 2, count( $data ) ); … … 440 440 // Orderby=>include 441 441 $request->set_param( 'orderby', 'include' ); 442 $response = $this->server->dispatch( $request );442 $response = rest_get_server()->dispatch( $request ); 443 443 $data = $response->get_data(); 444 444 $this->assertEquals( 2, count( $data ) ); … … 446 446 // Orderby=>invalid should fail. 447 447 $request->set_param( 'orderby', 'invalid' ); 448 $response = $this->server->dispatch( $request );448 $response = rest_get_server()->dispatch( $request ); 449 449 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 450 450 // fails on invalid id. 451 451 $request->set_param( 'orderby', array( 'include' ) ); 452 452 $request->set_param( 'include', array( 'invalid' ) ); 453 $response = $this->server->dispatch( $request );453 $response = rest_get_server()->dispatch( $request ); 454 454 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 455 455 } … … 464 464 $id2 = $this->factory->comment->create( $args ); 465 465 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 466 $response = $this->server->dispatch( $request );466 $response = rest_get_server()->dispatch( $request ); 467 467 $data = $response->get_data(); 468 468 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 469 469 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 470 470 $request->set_param( 'exclude', array( $id2 ) ); 471 $response = $this->server->dispatch( $request );471 $response = rest_get_server()->dispatch( $request ); 472 472 $data = $response->get_data(); 473 473 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 476 476 // fails on invalid id. 477 477 $request->set_param( 'exclude', array( 'invalid' ) ); 478 $response = $this->server->dispatch( $request );478 $response = rest_get_server()->dispatch( $request ); 479 479 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 480 480 } … … 491 491 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 492 492 $request->set_param( 'offset', 1 ); 493 $response = $this->server->dispatch( $request );493 $response = rest_get_server()->dispatch( $request ); 494 494 $this->assertCount( 3, $response->get_data() ); 495 495 // 'offset' works with 'per_page' 496 496 $request->set_param( 'per_page', 2 ); 497 $response = $this->server->dispatch( $request );497 $response = rest_get_server()->dispatch( $request ); 498 498 $this->assertCount( 2, $response->get_data() ); 499 499 // 'offset' takes priority over 'page' 500 500 $request->set_param( 'page', 3 ); 501 $response = $this->server->dispatch( $request );501 $response = rest_get_server()->dispatch( $request ); 502 502 $this->assertCount( 2, $response->get_data() ); 503 503 // 'offset' with invalid value errors. 504 504 $request->set_param( 'offset', 'moreplease' ); 505 $response = $this->server->dispatch( $request );505 $response = rest_get_server()->dispatch( $request ); 506 506 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 507 507 } … … 518 518 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 519 519 // order defaults to 'desc' 520 $response = $this->server->dispatch( $request );520 $response = rest_get_server()->dispatch( $request ); 521 521 $data = $response->get_data(); 522 522 $this->assertEquals( $id3, $data[0]['id'] ); 523 523 // order=>asc 524 524 $request->set_param( 'order', 'asc' ); 525 $response = $this->server->dispatch( $request );525 $response = rest_get_server()->dispatch( $request ); 526 526 $data = $response->get_data(); 527 527 $this->assertEquals( self::$approved_id, $data[0]['id'] ); 528 528 // order=>asc,id should fail 529 529 $request->set_param( 'order', 'asc,id' ); 530 $response = $this->server->dispatch( $request );530 $response = rest_get_server()->dispatch( $request ); 531 531 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 532 532 } … … 537 537 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 538 538 $request->set_param( 'post', $post_id ); 539 $response = $this->server->dispatch( $request );539 $response = rest_get_server()->dispatch( $request ); 540 540 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 401 ); 541 541 } … … 558 558 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 559 559 $request->set_param( 'author', self::$author_id ); 560 $response = $this->server->dispatch( $request );560 $response = rest_get_server()->dispatch( $request ); 561 561 $this->assertEquals( 200, $response->get_status() ); 562 562 $comments = $response->get_data(); … … 564 564 // Multiple authors are supported 565 565 $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) ); 566 $response = $this->server->dispatch( $request );566 $response = rest_get_server()->dispatch( $request ); 567 567 $this->assertEquals( 200, $response->get_status() ); 568 568 $comments = $response->get_data(); … … 570 570 // Invalid author param errors 571 571 $request->set_param( 'author', 'skippy' ); 572 $response = $this->server->dispatch( $request );572 $response = rest_get_server()->dispatch( $request ); 573 573 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 574 574 // Unavailable to unauthenticated; defaults to error 575 575 wp_set_current_user( 0 ); 576 576 $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) ); 577 $response = $this->server->dispatch( $request );577 $response = rest_get_server()->dispatch( $request ); 578 578 $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 ); 579 579 } … … 594 594 595 595 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 596 $response = $this->server->dispatch( $request );596 $response = rest_get_server()->dispatch( $request ); 597 597 $comments = $response->get_data(); 598 598 $this->assertCount( 4, $comments ); … … 601 601 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 602 602 $request->set_param( 'author_exclude', self::$author_id ); 603 $response = $this->server->dispatch( $request );603 $response = rest_get_server()->dispatch( $request ); 604 604 $this->assertEquals( 200, $response->get_status() ); 605 605 $comments = $response->get_data(); … … 608 608 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 609 609 $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) ); 610 $response = $this->server->dispatch( $request );610 $response = rest_get_server()->dispatch( $request ); 611 611 $this->assertEquals( 200, $response->get_status() ); 612 612 $comments = $response->get_data(); … … 615 615 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 616 616 $request->set_param( 'author_exclude', 'skippy' ); 617 $response = $this->server->dispatch( $request );617 $response = rest_get_server()->dispatch( $request ); 618 618 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 619 619 // Unavailable to unauthenticated; defaults to error 620 620 wp_set_current_user( 0 ); 621 621 $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) ); 622 $response = $this->server->dispatch( $request );622 $response = rest_get_server()->dispatch( $request ); 623 623 $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 ); 624 624 } … … 637 637 // All comments in the database 638 638 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 639 $response = $this->server->dispatch( $request );639 $response = rest_get_server()->dispatch( $request ); 640 640 $this->assertCount( 5, $response->get_data() ); 641 641 // Limit to the parent 642 642 $request->set_param( 'parent', $parent_id ); 643 $response = $this->server->dispatch( $request );643 $response = rest_get_server()->dispatch( $request ); 644 644 $this->assertCount( 1, $response->get_data() ); 645 645 // Limit to two parents 646 646 $request->set_param( 'parent', array( $parent_id, $parent_id2 ) ); 647 $response = $this->server->dispatch( $request );647 $response = rest_get_server()->dispatch( $request ); 648 648 $this->assertCount( 2, $response->get_data() ); 649 649 // Invalid parent should error 650 650 $request->set_param( 'parent', 'invalid' ); 651 $response = $this->server->dispatch( $request );651 $response = rest_get_server()->dispatch( $request ); 652 652 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 653 653 } … … 666 666 // All comments in the database 667 667 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 668 $response = $this->server->dispatch( $request );668 $response = rest_get_server()->dispatch( $request ); 669 669 $this->assertCount( 5, $response->get_data() ); 670 670 // Exclude this particular parent 671 671 $request->set_param( 'parent_exclude', $parent_id ); 672 $response = $this->server->dispatch( $request );672 $response = rest_get_server()->dispatch( $request ); 673 673 $this->assertCount( 4, $response->get_data() ); 674 674 // Exclude both comment parents 675 675 $request->set_param( 'parent_exclude', array( $parent_id, $parent_id2 ) ); 676 $response = $this->server->dispatch( $request );676 $response = rest_get_server()->dispatch( $request ); 677 677 $this->assertCount( 3, $response->get_data() ); 678 678 // Invalid parent id should error 679 679 $request->set_param( 'parent_exclude', 'invalid' ); 680 $response = $this->server->dispatch( $request );680 $response = rest_get_server()->dispatch( $request ); 681 681 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 682 682 } … … 697 697 // 3 comments, plus 1 created in construct 698 698 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 699 $response = $this->server->dispatch( $request );699 $response = rest_get_server()->dispatch( $request ); 700 700 $this->assertCount( 4, $response->get_data() ); 701 701 // One matching comments 702 702 $request->set_param( 'search', 'foo' ); 703 $response = $this->server->dispatch( $request );703 $response = rest_get_server()->dispatch( $request ); 704 704 $data = $response->get_data(); 705 705 $this->assertCount( 1, $data ); … … 719 719 } 720 720 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 721 $response = $this->server->dispatch( $request );721 $response = rest_get_server()->dispatch( $request ); 722 722 $headers = $response->get_headers(); 723 723 $this->assertEquals( 50, $headers['X-WP-Total'] ); … … 739 739 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 740 740 $request->set_param( 'page', 3 ); 741 $response = $this->server->dispatch( $request );741 $response = rest_get_server()->dispatch( $request ); 742 742 $headers = $response->get_headers(); 743 743 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 758 758 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 759 759 $request->set_param( 'page', 6 ); 760 $response = $this->server->dispatch( $request );760 $response = rest_get_server()->dispatch( $request ); 761 761 $headers = $response->get_headers(); 762 762 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 772 772 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 773 773 $request->set_param( 'page', 8 ); 774 $response = $this->server->dispatch( $request );774 $response = rest_get_server()->dispatch( $request ); 775 775 $headers = $response->get_headers(); 776 776 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 789 789 $request->set_param( 'after', rand_str() ); 790 790 $request->set_param( 'before', rand_str() ); 791 $response = $this->server->dispatch( $request );791 $response = rest_get_server()->dispatch( $request ); 792 792 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 793 793 } … … 816 816 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 817 817 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 818 $response = $this->server->dispatch( $request );818 $response = rest_get_server()->dispatch( $request ); 819 819 $data = $response->get_data(); 820 820 $this->assertCount( 1, $data ); … … 825 825 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 826 826 827 $response = $this->server->dispatch( $request );827 $response = rest_get_server()->dispatch( $request ); 828 828 $this->assertEquals( 200, $response->get_status() ); 829 829 … … 841 841 ); 842 842 843 $response = $this->server->dispatch( $request );843 $response = rest_get_server()->dispatch( $request ); 844 844 $this->assertEquals( 200, $response->get_status() ); 845 845 … … 851 851 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 852 852 853 $response = $this->server->dispatch( $request );853 $response = rest_get_server()->dispatch( $request ); 854 854 855 855 $data = $response->get_data(); … … 869 869 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 870 870 871 $response = $this->server->dispatch( $request );871 $response = rest_get_server()->dispatch( $request ); 872 872 $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 ); 873 873 } … … 877 877 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', self::$approved_id ) ); 878 878 $request->set_param( 'context', 'edit' ); 879 $response = $this->server->dispatch( $request );879 $response = rest_get_server()->dispatch( $request ); 880 880 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 881 881 } … … 891 891 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id ); 892 892 893 $response = $this->server->dispatch( $request );893 $response = rest_get_server()->dispatch( $request ); 894 894 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); 895 895 } … … 905 905 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id ); 906 906 907 $response = $this->server->dispatch( $request );907 $response = rest_get_server()->dispatch( $request ); 908 908 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); 909 909 } … … 914 914 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 915 915 916 $response = $this->server->dispatch( $request );916 $response = rest_get_server()->dispatch( $request ); 917 917 $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); 918 918 } … … 923 923 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 924 924 925 $response = $this->server->dispatch( $request );925 $response = rest_get_server()->dispatch( $request ); 926 926 $this->assertEquals( 200, $response->get_status() ); 927 927 } … … 946 946 947 947 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) ); 948 $response = $this->server->dispatch( $request );948 $response = rest_get_server()->dispatch( $request ); 949 949 $this->assertEquals( 200, $response->get_status() ); 950 950 $this->assertArrayHasKey( 'children', $response->get_links() ); … … 961 961 962 962 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) ); 963 $response = $this->server->dispatch( $request );963 $response = rest_get_server()->dispatch( $request ); 964 964 $this->assertEquals( 200, $response->get_status() ); 965 965 $this->assertArrayNotHasKey( 'children', $response->get_links() ); … … 974 974 $password_comment = $this->factory->comment->create( $args ); 975 975 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) ); 976 $response = $this->server->dispatch( $request );976 $response = rest_get_server()->dispatch( $request ); 977 977 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); 978 978 } … … 993 993 $request->set_param( 'password', 'toomanysecrets' ); 994 994 995 $response = $this->server->dispatch( $request );995 $response = rest_get_server()->dispatch( $request ); 996 996 $this->assertEquals( 200, $response->get_status() ); 997 997 } … … 1013 1013 $request->set_body( wp_json_encode( $params ) ); 1014 1014 1015 $response = $this->server->dispatch( $request );1015 $response = rest_get_server()->dispatch( $request ); 1016 1016 $this->assertEquals( 201, $response->get_status() ); 1017 1017 … … 1084 1084 $request->set_param( 'date_gmt', $params['date_gmt'] ); 1085 1085 } 1086 $response = $this->server->dispatch( $request );1086 $response = rest_get_server()->dispatch( $request ); 1087 1087 1088 1088 update_option( 'timezone_string', '' ); … … 1118 1118 $request->set_body( wp_json_encode( $params ) ); 1119 1119 1120 $response = $this->server->dispatch( $request );1120 $response = rest_get_server()->dispatch( $request ); 1121 1121 $this->assertEquals( 201, $response->get_status() ); 1122 1122 … … 1143 1143 $request->set_body( wp_json_encode( $params ) ); 1144 1144 1145 $response = $this->server->dispatch( $request );1145 $response = rest_get_server()->dispatch( $request ); 1146 1146 1147 1147 $this->assertErrorResponse( 'test_rest_premade_error', $response, 418 ); … … 1166 1166 $request->set_body( wp_json_encode( $params ) ); 1167 1167 1168 $response = $this->server->dispatch( $request );1168 $response = rest_get_server()->dispatch( $request ); 1169 1169 1170 1170 $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 ); … … 1186 1186 $request->set_body( wp_json_encode( $params ) ); 1187 1187 1188 $response = $this->server->dispatch( $request );1188 $response = rest_get_server()->dispatch( $request ); 1189 1189 1190 1190 $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 ); … … 1205 1205 $request->set_body( wp_json_encode( $params ) ); 1206 1206 1207 $response = $this->server->dispatch( $request );1207 $response = rest_get_server()->dispatch( $request ); 1208 1208 $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 ); 1209 1209 } … … 1224 1224 $request->set_body( wp_json_encode( $params ) ); 1225 1225 1226 $response = $this->server->dispatch( $request );1226 $response = rest_get_server()->dispatch( $request ); 1227 1227 $this->assertErrorResponse( 'rest_comment_author_data_required', $response, 400 ); 1228 1228 } … … 1241 1241 $request->add_header( 'content-type', 'application/json' ); 1242 1242 $request->set_body( wp_json_encode( $params ) ); 1243 $response = $this->server->dispatch( $request );1243 $response = rest_get_server()->dispatch( $request ); 1244 1244 1245 1245 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1263 1263 $request->set_body( wp_json_encode( $params ) ); 1264 1264 1265 $response = $this->server->dispatch( $request );1265 $response = rest_get_server()->dispatch( $request ); 1266 1266 $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); 1267 1267 1268 1268 $params['content'] = ''; 1269 1269 $request->set_body( wp_json_encode( $params ) ); 1270 $response = $this->server->dispatch( $request );1270 $response = rest_get_server()->dispatch( $request ); 1271 1271 $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); 1272 1272 } … … 1288 1288 $request->set_body( wp_json_encode( $params ) ); 1289 1289 1290 $response = $this->server->dispatch( $request );1290 $response = rest_get_server()->dispatch( $request ); 1291 1291 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1292 1292 } … … 1314 1314 $request->add_header( 'content-type', 'application/json' ); 1315 1315 $request->set_body( wp_json_encode( $params ) ); 1316 $response = $this->server->dispatch( $request );1316 $response = rest_get_server()->dispatch( $request ); 1317 1317 $this->assertEquals( 201, $response->get_status() ); 1318 1318 … … 1340 1340 $request->set_body( wp_json_encode( $params ) ); 1341 1341 1342 $response = $this->server->dispatch( $request );1342 $response = rest_get_server()->dispatch( $request ); 1343 1343 $this->assertEquals( 201, $response->get_status() ); 1344 1344 … … 1351 1351 $collection = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 1352 1352 $collection->set_param( 'post', $post_id ); 1353 $collection_response = $this->server->dispatch( $collection );1353 $collection_response = rest_get_server()->dispatch( $collection ); 1354 1354 $collection_data = $collection_response->get_data(); 1355 1355 $this->assertEquals( $comment_id, $collection_data[0]['id'] ); … … 1378 1378 $request->set_body( wp_json_encode( $params ) ); 1379 1379 1380 $response = $this->server->dispatch( $request );1380 $response = rest_get_server()->dispatch( $request ); 1381 1381 $this->assertErrorResponse( 'rest_invalid_comment_type', $response, 400 ); 1382 1382 } … … 1400 1400 $request->set_body( wp_json_encode( $params ) ); 1401 1401 1402 $response = $this->server->dispatch( $request );1402 $response = rest_get_server()->dispatch( $request ); 1403 1403 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1404 1404 } … … 1426 1426 $request->add_header( 'content-type', 'application/json' ); 1427 1427 $request->set_body( wp_json_encode( $params ) ); 1428 $response = $this->server->dispatch( $request );1428 $response = rest_get_server()->dispatch( $request ); 1429 1429 1430 1430 $this->assertEquals( 201, $response->get_status() ); … … 1455 1455 $request->add_header( 'content-type', 'application/json' ); 1456 1456 $request->set_body( wp_json_encode( $params ) ); 1457 $response = $this->server->dispatch( $request );1457 $response = rest_get_server()->dispatch( $request ); 1458 1458 1459 1459 $this->assertEquals( 201, $response->get_status() ); … … 1480 1480 $request->add_header( 'content-type', 'application/json' ); 1481 1481 $request->set_body( wp_json_encode( $params ) ); 1482 $response = $this->server->dispatch( $request );1482 $response = rest_get_server()->dispatch( $request ); 1483 1483 1484 1484 $this->assertErrorResponse( 'rest_comment_invalid_author', $response, 403 ); … … 1500 1500 $request->add_header( 'content-type', 'application/json' ); 1501 1501 $request->set_body( wp_json_encode( $params ) ); 1502 $response = $this->server->dispatch( $request );1502 $response = rest_get_server()->dispatch( $request ); 1503 1503 1504 1504 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1521 1521 $request->add_header( 'content-type', 'application/json' ); 1522 1522 $request->set_body( wp_json_encode( $params ) ); 1523 $response = $this->server->dispatch( $request );1523 $response = rest_get_server()->dispatch( $request ); 1524 1524 1525 1525 $this->assertErrorResponse( 'rest_comment_invalid_status', $response, 403 ); … … 1545 1545 $request->set_body( wp_json_encode( $params ) ); 1546 1546 1547 $response = $this->server->dispatch( $request );1547 $response = rest_get_server()->dispatch( $request ); 1548 1548 $this->assertEquals( 201, $response->get_status() ); 1549 1549 … … 1570 1570 $request->set_body( wp_json_encode( $params ) ); 1571 1571 1572 $response = $this->server->dispatch( $request );1572 $response = rest_get_server()->dispatch( $request ); 1573 1573 $this->assertEquals( 201, $response->get_status() ); 1574 1574 … … 1594 1594 $request->add_header( 'content-type', 'application/json' ); 1595 1595 $request->set_body( wp_json_encode( $params ) ); 1596 $response = $this->server->dispatch( $request );1596 $response = rest_get_server()->dispatch( $request ); 1597 1597 $data = $response->get_data(); 1598 1598 $new_comment = get_comment( $data['id'] ); … … 1616 1616 $request->set_body( wp_json_encode( $params ) ); 1617 1617 1618 $response = $this->server->dispatch( $request );1618 $response = rest_get_server()->dispatch( $request ); 1619 1619 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1620 1620 } … … 1633 1633 $request->add_header( 'content-type', 'application/json' ); 1634 1634 $request->set_body( wp_json_encode( $params ) ); 1635 $response = $this->server->dispatch( $request );1635 $response = rest_get_server()->dispatch( $request ); 1636 1636 $this->assertErrorResponse( 'rest_comment_invalid_author_ip', $response, 403 ); 1637 1637 } … … 1650 1650 $request->add_header( 'content-type', 'application/json' ); 1651 1651 $request->set_body( wp_json_encode( $params ) ); 1652 $response = $this->server->dispatch( $request );1652 $response = rest_get_server()->dispatch( $request ); 1653 1653 $data = $response->get_data(); 1654 1654 $new_comment = get_comment( $data['id'] ); … … 1670 1670 $request->set_body( wp_json_encode( $params ) ); 1671 1671 1672 $response = $this->server->dispatch( $request );1672 $response = rest_get_server()->dispatch( $request ); 1673 1673 1674 1674 $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 ); … … 1689 1689 $request->set_body( wp_json_encode( $params ) ); 1690 1690 1691 $response = $this->server->dispatch( $request );1691 $response = rest_get_server()->dispatch( $request ); 1692 1692 $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 ); 1693 1693 } … … 1709 1709 $request->set_body( wp_json_encode( $params ) ); 1710 1710 1711 $response = $this->server->dispatch( $request );1711 $response = rest_get_server()->dispatch( $request ); 1712 1712 $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 ); 1713 1713 } … … 1728 1728 $request->set_body( wp_json_encode( $params ) ); 1729 1729 1730 $response = $this->server->dispatch( $request );1730 $response = rest_get_server()->dispatch( $request ); 1731 1731 1732 1732 $this->assertErrorResponse( 'rest_comment_draft_post', $response, 403 ); … … 1748 1748 $request->set_body( wp_json_encode( $params ) ); 1749 1749 1750 $response = $this->server->dispatch( $request );1750 $response = rest_get_server()->dispatch( $request ); 1751 1751 1752 1752 $this->assertErrorResponse( 'rest_comment_trash_post', $response, 403 ); … … 1768 1768 $request->set_body( wp_json_encode( $params ) ); 1769 1769 1770 $response = $this->server->dispatch( $request );1770 $response = rest_get_server()->dispatch( $request ); 1771 1771 1772 1772 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 ); … … 1788 1788 $request->set_body( wp_json_encode( $params ) ); 1789 1789 1790 $response = $this->server->dispatch( $request );1790 $response = rest_get_server()->dispatch( $request ); 1791 1791 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 ); 1792 1792 } … … 1813 1813 $request->add_header( 'content-type', 'application/json' ); 1814 1814 $request->set_body( wp_json_encode( $params ) ); 1815 $response = $this->server->dispatch( $request );1815 $response = rest_get_server()->dispatch( $request ); 1816 1816 1817 1817 $this->assertEquals( 409, $response->get_status() ); … … 1833 1833 $request->add_header( 'content-type', 'application/json' ); 1834 1834 $request->set_body( wp_json_encode( $params ) ); 1835 $response = $this->server->dispatch( $request );1835 $response = rest_get_server()->dispatch( $request ); 1836 1836 1837 1837 $this->assertEquals( 403, $response->get_status() ); … … 1844 1844 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1845 1845 $request->set_param( 'post', self::$post_id ); 1846 $response = $this->server->dispatch( $request );1846 $response = rest_get_server()->dispatch( $request ); 1847 1847 $this->assertEquals( 401, $response->get_status() ); 1848 1848 $data = $response->get_data(); … … 1863 1863 $request->set_body( wp_json_encode( $params ) ); 1864 1864 1865 $response = $this->server->dispatch( $request );1865 $response = rest_get_server()->dispatch( $request ); 1866 1866 $this->assertErrorResponse( 'rest_comment_author_invalid', $response, 400 ); 1867 1867 } … … 1881 1881 $request->set_body( wp_json_encode( $params ) ); 1882 1882 1883 $response = $this->server->dispatch( $request );1883 $response = rest_get_server()->dispatch( $request ); 1884 1884 1885 1885 $result = $response->get_data(); … … 1905 1905 $request->set_body( wp_json_encode( $params ) ); 1906 1906 1907 $response = $this->server->dispatch( $request );1907 $response = rest_get_server()->dispatch( $request ); 1908 1908 $this->assertEquals( 201, $response->get_status() ); 1909 1909 … … 1920 1920 $request->set_body( wp_json_encode( $params ) ); 1921 1921 1922 $response = $this->server->dispatch( $request );1922 $response = rest_get_server()->dispatch( $request ); 1923 1923 $this->assertEquals( 400, $response->get_status() ); 1924 1924 } … … 1944 1944 $request->set_body( wp_json_encode( $params ) ); 1945 1945 1946 $response = $this->server->dispatch( $request );1946 $response = rest_get_server()->dispatch( $request ); 1947 1947 1948 1948 remove_filter( 'rest_allow_anonymous_comments', array( $this, 'anonymous_comments_callback_null' ), 10, 2 ); … … 1969 1969 $request->add_header( 'content-type', 'application/json' ); 1970 1970 $request->set_body( wp_json_encode( $params ) ); 1971 $response = $this->server->dispatch( $request );1971 $response = rest_get_server()->dispatch( $request ); 1972 1972 1973 1973 $this->assertErrorResponse( 'comment_author_column_length', $response, 400 ); … … 1992 1992 $request->add_header( 'content-type', 'application/json' ); 1993 1993 $request->set_body( wp_json_encode( $params ) ); 1994 $response = $this->server->dispatch( $request );1994 $response = rest_get_server()->dispatch( $request ); 1995 1995 1996 1996 $this->assertErrorResponse( 'comment_author_email_column_length', $response, 400 ); … … 2015 2015 $request->add_header( 'content-type', 'application/json' ); 2016 2016 $request->set_body( wp_json_encode( $params ) ); 2017 $response = $this->server->dispatch( $request );2017 $response = rest_get_server()->dispatch( $request ); 2018 2018 2019 2019 $this->assertErrorResponse( 'comment_author_url_column_length', $response, 400 ); … … 2038 2038 $request->add_header( 'content-type', 'application/json' ); 2039 2039 $request->set_body( wp_json_encode( $params ) ); 2040 $response = $this->server->dispatch( $request );2040 $response = rest_get_server()->dispatch( $request ); 2041 2041 2042 2042 $this->assertErrorResponse( 'comment_content_column_length', $response, 400 ); … … 2057 2057 $request->add_header( 'content-type', 'application/json' ); 2058 2058 $request->set_body( wp_json_encode( $params ) ); 2059 $response = $this->server->dispatch( $request );2059 $response = rest_get_server()->dispatch( $request ); 2060 2060 2061 2061 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 ); … … 2077 2077 $request->add_header( 'content-type', 'application/json' ); 2078 2078 $request->set_body( wp_json_encode( $params ) ); 2079 $response = $this->server->dispatch( $request );2079 $response = rest_get_server()->dispatch( $request ); 2080 2080 $this->assertEquals( 201, $response->get_status() ); 2081 2081 } … … 2100 2100 $request->set_body( wp_json_encode( $params ) ); 2101 2101 2102 $response = $this->server->dispatch( $request );2102 $response = rest_get_server()->dispatch( $request ); 2103 2103 $this->assertEquals( 200, $response->get_status() ); 2104 2104 … … 2133 2133 $request->set_param( 'date_gmt', $params['date_gmt'] ); 2134 2134 } 2135 $response = $this->server->dispatch( $request );2135 $response = rest_get_server()->dispatch( $request ); 2136 2136 2137 2137 update_option( 'timezone_string', '' ); … … 2159 2159 2160 2160 // Sending a request without content is fine. 2161 $response = $this->server->dispatch( $request );2161 $response = rest_get_server()->dispatch( $request ); 2162 2162 $this->assertEquals( 200, $response->get_status() ); 2163 2163 … … 2165 2165 $request->set_param( 'author_email', 'yetanother@email.com' ); 2166 2166 $request->set_param( 'content', '' ); 2167 $response = $this->server->dispatch( $request );2167 $response = rest_get_server()->dispatch( $request ); 2168 2168 $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); 2169 2169 } … … 2178 2178 // Run twice to make sure that the update still succeeds even if no DB 2179 2179 // rows are updated. 2180 $response = $this->server->dispatch( $request );2181 $this->assertEquals( 200, $response->get_status() ); 2182 2183 $response = $this->server->dispatch( $request );2180 $response = rest_get_server()->dispatch( $request ); 2181 $this->assertEquals( 200, $response->get_status() ); 2182 2183 $response = rest_get_server()->dispatch( $request ); 2184 2184 $this->assertEquals( 200, $response->get_status() ); 2185 2185 } … … 2202 2202 $request->set_body( wp_json_encode( $params ) ); 2203 2203 2204 $response = $this->server->dispatch( $request );2204 $response = rest_get_server()->dispatch( $request ); 2205 2205 $this->assertEquals( 200, $response->get_status() ); 2206 2206 … … 2229 2229 $request->set_body( wp_json_encode( $params ) ); 2230 2230 2231 $response = $this->server->dispatch( $request );2231 $response = rest_get_server()->dispatch( $request ); 2232 2232 $this->assertEquals( 200, $response->get_status() ); 2233 2233 … … 2250 2250 $request->set_body( wp_json_encode( $params ) ); 2251 2251 2252 $response = $this->server->dispatch( $request );2252 $response = rest_get_server()->dispatch( $request ); 2253 2253 $this->assertEquals( 200, $response->get_status() ); 2254 2254 … … 2273 2273 $request->set_body( wp_json_encode( $params ) ); 2274 2274 2275 $response = $this->server->dispatch( $request );2275 $response = rest_get_server()->dispatch( $request ); 2276 2276 $this->assertEquals( 200, $response->get_status() ); 2277 2277 } … … 2292 2292 $request->set_body( wp_json_encode( $params ) ); 2293 2293 2294 $response = $this->server->dispatch( $request );2294 $response = rest_get_server()->dispatch( $request ); 2295 2295 $this->assertEquals( 200, $response->get_status() ); 2296 2296 } … … 2310 2310 $request->set_body( wp_json_encode( $params ) ); 2311 2311 2312 $response = $this->server->dispatch( $request );2312 $response = rest_get_server()->dispatch( $request ); 2313 2313 $this->assertEquals( 200, $response->get_status() ); 2314 2314 } … … 2329 2329 $request->set_body( wp_json_encode( $params ) ); 2330 2330 2331 $response = $this->server->dispatch( $request );2331 $response = rest_get_server()->dispatch( $request ); 2332 2332 $this->assertEquals( 200, $response->get_status() ); 2333 2333 } … … 2346 2346 $request->add_header( 'content-type', 'application/json' ); 2347 2347 $request->set_body( wp_json_encode( $params ) ); 2348 $response = $this->server->dispatch( $request );2348 $response = rest_get_server()->dispatch( $request ); 2349 2349 2350 2350 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2363 2363 $request->set_body( wp_json_encode( $params ) ); 2364 2364 2365 $response = $this->server->dispatch( $request );2365 $response = rest_get_server()->dispatch( $request ); 2366 2366 $this->assertErrorResponse( 'rest_comment_invalid_type', $response, 404 ); 2367 2367 } … … 2379 2379 $request->set_body( wp_json_encode( $params ) ); 2380 2380 2381 $response = $this->server->dispatch( $request );2381 $response = rest_get_server()->dispatch( $request ); 2382 2382 2383 2383 $this->assertEquals( 200, $response->get_status() ); … … 2400 2400 $request->set_body( wp_json_encode( $params ) ); 2401 2401 2402 $response = $this->server->dispatch( $request );2402 $response = rest_get_server()->dispatch( $request ); 2403 2403 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 2404 2404 } … … 2416 2416 $request->set_body( wp_json_encode( $params ) ); 2417 2417 2418 $response = $this->server->dispatch( $request );2418 $response = rest_get_server()->dispatch( $request ); 2419 2419 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 2420 2420 } … … 2430 2430 $request->set_body( wp_json_encode( $params ) ); 2431 2431 2432 $response = $this->server->dispatch( $request );2432 $response = rest_get_server()->dispatch( $request ); 2433 2433 $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 ); 2434 2434 } … … 2440 2440 $request->set_param( 'post', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 2441 2441 2442 $response = $this->server->dispatch( $request );2442 $response = rest_get_server()->dispatch( $request ); 2443 2443 $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 ); 2444 2444 } … … 2454 2454 $request->set_body( wp_json_encode( $params ) ); 2455 2455 2456 $response = $this->server->dispatch( $request );2456 $response = rest_get_server()->dispatch( $request ); 2457 2457 $this->assertErrorResponse( 'rest_cannot_edit', $response, 401 ); 2458 2458 } … … 2476 2476 $request->set_body( wp_json_encode( $params ) ); 2477 2477 2478 $response = $this->server->dispatch( $request );2478 $response = rest_get_server()->dispatch( $request ); 2479 2479 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); 2480 2480 } … … 2500 2500 // Check if comment 1 does not have the child link. 2501 2501 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) ); 2502 $response = $this->server->dispatch( $request );2502 $response = rest_get_server()->dispatch( $request ); 2503 2503 $this->assertEquals( 200, $response->get_status() ); 2504 2504 $this->assertArrayNotHasKey( 'children', $response->get_links() ); … … 2508 2508 $request->set_param( 'parent', $comment_id_1 ); 2509 2509 $request->set_param( 'content', rand_str() ); 2510 $response = $this->server->dispatch( $request );2510 $response = rest_get_server()->dispatch( $request ); 2511 2511 $this->assertEquals( 200, $response->get_status() ); 2512 2512 2513 2513 // Check if comment 1 now has the child link. 2514 2514 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) ); 2515 $response = $this->server->dispatch( $request );2515 $response = rest_get_server()->dispatch( $request ); 2516 2516 $this->assertEquals( 200, $response->get_status() ); 2517 2517 $this->assertArrayHasKey( 'children', $response->get_links() ); … … 2532 2532 $request->add_header( 'content-type', 'application/json' ); 2533 2533 $request->set_body( wp_json_encode( $params ) ); 2534 $response = $this->server->dispatch( $request );2534 $response = rest_get_server()->dispatch( $request ); 2535 2535 2536 2536 $this->assertErrorResponse( 'comment_author_column_length', $response, 400 ); … … 2551 2551 $request->add_header( 'content-type', 'application/json' ); 2552 2552 $request->set_body( wp_json_encode( $params ) ); 2553 $response = $this->server->dispatch( $request );2553 $response = rest_get_server()->dispatch( $request ); 2554 2554 2555 2555 $this->assertErrorResponse( 'comment_author_email_column_length', $response, 400 ); … … 2570 2570 $request->add_header( 'content-type', 'application/json' ); 2571 2571 $request->set_body( wp_json_encode( $params ) ); 2572 $response = $this->server->dispatch( $request );2572 $response = rest_get_server()->dispatch( $request ); 2573 2573 2574 2574 $this->assertErrorResponse( 'comment_author_url_column_length', $response, 400 ); … … 2588 2588 $request->add_header( 'content-type', 'application/json' ); 2589 2589 $request->set_body( wp_json_encode( $params ) ); 2590 $response = $this->server->dispatch( $request );2590 $response = rest_get_server()->dispatch( $request ); 2591 2591 2592 2592 $this->assertErrorResponse( 'comment_content_column_length', $response, 400 ); … … 2601 2601 $request->set_param( $name, $value ); 2602 2602 } 2603 $response = $this->server->dispatch( $request );2603 $response = rest_get_server()->dispatch( $request ); 2604 2604 $this->assertEquals( 201, $response->get_status() ); 2605 2605 $actual_output = $response->get_data(); … … 2627 2627 // See https://core.trac.wordpress.org/ticket/38700 2628 2628 $request->set_param( 'author_ip', '127.0.0.2' ); 2629 $response = $this->server->dispatch( $request );2629 $response = rest_get_server()->dispatch( $request ); 2630 2630 $this->assertEquals( 200, $response->get_status() ); 2631 2631 $actual_output = $response->get_data(); … … 2751 2751 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 2752 2752 $request->set_param( 'force', 'false' ); 2753 $response = $this->server->dispatch( $request );2753 $response = rest_get_server()->dispatch( $request ); 2754 2754 $this->assertEquals( 200, $response->get_status() ); 2755 2755 … … 2771 2771 $request['force'] = true; 2772 2772 2773 $response = $this->server->dispatch( $request );2773 $response = rest_get_server()->dispatch( $request ); 2774 2774 $this->assertEquals( 200, $response->get_status() ); 2775 2775 $data = $response->get_data(); … … 2789 2789 ); 2790 2790 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 2791 $response = $this->server->dispatch( $request );2791 $response = rest_get_server()->dispatch( $request ); 2792 2792 $this->assertEquals( 200, $response->get_status() ); 2793 2793 $data = $response->get_data(); 2794 $response = $this->server->dispatch( $request );2794 $response = rest_get_server()->dispatch( $request ); 2795 2795 $this->assertErrorResponse( 'rest_already_trashed', $response, 410 ); 2796 2796 } … … 2801 2801 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) ); 2802 2802 2803 $response = $this->server->dispatch( $request );2803 $response = rest_get_server()->dispatch( $request ); 2804 2804 $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 ); 2805 2805 } … … 2810 2810 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2811 2811 2812 $response = $this->server->dispatch( $request );2812 $response = rest_get_server()->dispatch( $request ); 2813 2813 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); 2814 2814 } … … 2834 2834 2835 2835 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%s', $child_comment ) ); 2836 $response = $this->server->dispatch( $request );2836 $response = rest_get_server()->dispatch( $request ); 2837 2837 $this->assertEquals( 200, $response->get_status() ); 2838 2838 2839 2839 // Verify children link is gone. 2840 2840 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $comment_id_1 ) ); 2841 $response = $this->server->dispatch( $request );2841 $response = rest_get_server()->dispatch( $request ); 2842 2842 $this->assertEquals( 200, $response->get_status() ); 2843 2843 $this->assertArrayNotHasKey( 'children', $response->get_links() ); … … 2846 2846 public function test_get_item_schema() { 2847 2847 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' ); 2848 $response = $this->server->dispatch( $request );2848 $response = rest_get_server()->dispatch( $request ); 2849 2849 $data = $response->get_data(); 2850 2850 $properties = $data['schema']['properties']; … … 2878 2878 update_option( 'show_avatars', false ); 2879 2879 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2880 $response = $this->server->dispatch( $request );2880 $response = rest_get_server()->dispatch( $request ); 2881 2881 $data = $response->get_data(); 2882 2882 $properties = $data['schema']['properties']; … … 2904 2904 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' ); 2905 2905 2906 $response = $this->server->dispatch( $request );2906 $response = rest_get_server()->dispatch( $request ); 2907 2907 $data = $response->get_data(); 2908 2908 … … 2912 2912 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id ); 2913 2913 2914 $response = $this->server->dispatch( $request );2914 $response = rest_get_server()->dispatch( $request ); 2915 2915 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 2916 2916 … … 2924 2924 2925 2925 wp_set_current_user( 1 ); 2926 $this->server->dispatch( $request );2926 rest_get_server()->dispatch( $request ); 2927 2927 $this->assertEquals( 123, get_comment_meta( self::$approved_id, 'my_custom_int', true ) ); 2928 2928 … … 2937 2937 ); 2938 2938 2939 $response = $this->server->dispatch( $request );2939 $response = rest_get_server()->dispatch( $request ); 2940 2940 2941 2941 $this->assertEquals( 123, $response->data['my_custom_int'] ); … … 2972 2972 ); 2973 2973 2974 $response = $this->server->dispatch( $request );2974 $response = rest_get_server()->dispatch( $request ); 2975 2975 2976 2976 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); -
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r42343 r42724 38 38 39 39 public function test_register_routes() { 40 $routes = $this->server->get_routes();40 $routes = rest_get_server()->get_routes(); 41 41 $this->assertArrayHasKey( '/wp/v2/pages', $routes ); 42 42 $this->assertCount( 2, $routes['/wp/v2/pages'] ); … … 48 48 // Collection 49 49 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); 50 $response = $this->server->dispatch( $request );50 $response = rest_get_server()->dispatch( $request ); 51 51 $data = $response->get_data(); 52 52 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 55 55 $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 56 56 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages/' . $page_id ); 57 $response = $this->server->dispatch( $request );57 $response = rest_get_server()->dispatch( $request ); 58 58 $data = $response->get_data(); 59 59 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 63 63 public function test_registered_query_params() { 64 64 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); 65 $response = $this->server->dispatch( $request );65 $response = rest_get_server()->dispatch( $request ); 66 66 $data = $response->get_data(); 67 67 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 105 105 ); 106 106 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 107 $response = $this->server->dispatch( $request );107 $response = rest_get_server()->dispatch( $request ); 108 108 $data = $response->get_data(); 109 109 $this->assertEquals( 1, count( $data ) ); … … 127 127 // No parent 128 128 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 129 $response = $this->server->dispatch( $request );129 $response = rest_get_server()->dispatch( $request ); 130 130 $data = $response->get_data(); 131 131 $this->assertEquals( 2, count( $data ) ); 132 132 // Filter to parent 133 133 $request->set_param( 'parent', $id1 ); 134 $response = $this->server->dispatch( $request );134 $response = rest_get_server()->dispatch( $request ); 135 135 $data = $response->get_data(); 136 136 $this->assertEquals( 1, count( $data ) ); … … 138 138 // Invalid parent should fail 139 139 $request->set_param( 'parent', 'some-slug' ); 140 $response = $this->server->dispatch( $request );140 $response = rest_get_server()->dispatch( $request ); 141 141 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 142 142 } … … 171 171 // No parent 172 172 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 173 $response = $this->server->dispatch( $request );173 $response = rest_get_server()->dispatch( $request ); 174 174 $data = $response->get_data(); 175 175 $this->assertEquals( 4, count( $data ) ); 176 176 // Filter to parents 177 177 $request->set_param( 'parent', array( $id1, $id3 ) ); 178 $response = $this->server->dispatch( $request );178 $response = rest_get_server()->dispatch( $request ); 179 179 $data = $response->get_data(); 180 180 $this->assertEquals( 2, count( $data ) ); … … 198 198 // No parent 199 199 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 200 $response = $this->server->dispatch( $request );200 $response = rest_get_server()->dispatch( $request ); 201 201 $data = $response->get_data(); 202 202 $this->assertEquals( 2, count( $data ) ); 203 203 // Filter to parent 204 204 $request->set_param( 'parent_exclude', $id1 ); 205 $response = $this->server->dispatch( $request );205 $response = rest_get_server()->dispatch( $request ); 206 206 $data = $response->get_data(); 207 207 $this->assertEquals( 1, count( $data ) ); … … 209 209 // Invalid parent_exclude should error 210 210 $request->set_param( 'parent_exclude', 'some-slug' ); 211 $response = $this->server->dispatch( $request );211 $response = rest_get_server()->dispatch( $request ); 212 212 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 213 213 } … … 243 243 // No parent 244 244 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 245 $response = $this->server->dispatch( $request );245 $response = rest_get_server()->dispatch( $request ); 246 246 $data = $response->get_data(); 247 247 $this->assertEqualSets( array( $id1, $id2, $id3, $id4 ), wp_list_pluck( $data, 'id' ) ); 248 248 // Filter to menu_order 249 249 $request->set_param( 'menu_order', 1 ); 250 $response = $this->server->dispatch( $request );250 $response = rest_get_server()->dispatch( $request ); 251 251 $data = $response->get_data(); 252 252 $this->assertEqualSets( array( $id4 ), wp_list_pluck( $data, 'id' ) ); … … 255 255 $request->set_param( 'order', 'asc' ); 256 256 $request->set_param( 'orderby', 'menu_order' ); 257 $response = $this->server->dispatch( $request );257 $response = rest_get_server()->dispatch( $request ); 258 258 $data = $response->get_data(); 259 259 $this->assertEquals( $id1, $data[0]['id'] ); … … 264 264 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 265 265 $request->set_param( 'menu_order', 'top-first' ); 266 $response = $this->server->dispatch( $request );266 $response = rest_get_server()->dispatch( $request ); 267 267 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 268 268 } … … 271 271 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 272 272 $request->set_param( 'per_page', 0 ); 273 $response = $this->server->dispatch( $request );273 $response = rest_get_server()->dispatch( $request ); 274 274 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 275 275 $data = $response->get_data(); … … 278 278 $this->assertContains( 'per_page must be between 1 (inclusive) and 100 (inclusive)', $first_error ); 279 279 $request->set_param( 'per_page', 101 ); 280 $response = $this->server->dispatch( $request );280 $response = rest_get_server()->dispatch( $request ); 281 281 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 282 282 $data = $response->get_data(); … … 302 302 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 303 303 $request->set_param( 'status', 'draft' ); 304 $response = $this->server->dispatch( $request );304 $response = rest_get_server()->dispatch( $request ); 305 305 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 306 306 307 307 // But they are accessible to authorized users 308 308 wp_set_current_user( self::$editor_id ); 309 $response = $this->server->dispatch( $request );309 $response = rest_get_server()->dispatch( $request ); 310 310 $data = $response->get_data(); 311 311 $this->assertCount( 1, $data ); … … 317 317 $request->set_param( 'after', rand_str() ); 318 318 $request->set_param( 'before', rand_str() ); 319 $response = $this->server->dispatch( $request );319 $response = rest_get_server()->dispatch( $request ); 320 320 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 321 321 } … … 343 343 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 344 344 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 345 $response = $this->server->dispatch( $request );345 $response = rest_get_server()->dispatch( $request ); 346 346 $data = $response->get_data(); 347 347 $this->assertCount( 1, $data ); … … 356 356 $post_id = $this->factory->post->create(); 357 357 $request = new WP_REST_Request( 'GET', '/wp/v2/pages/' . $post_id ); 358 $response = $this->server->dispatch( $request );358 $response = rest_get_server()->dispatch( $request ); 359 359 $this->assertEquals( 404, $response->get_status() ); 360 360 } … … 374 374 ); 375 375 $request->set_body_params( $params ); 376 $response = $this->server->dispatch( $request );376 $response = rest_get_server()->dispatch( $request ); 377 377 378 378 $data = $response->get_data(); … … 397 397 ); 398 398 $request->set_body_params( $params ); 399 $response = $this->server->dispatch( $request );399 $response = rest_get_server()->dispatch( $request ); 400 400 401 401 $this->assertEquals( 201, $response->get_status() ); … … 420 420 ); 421 421 $request->set_body_params( $params ); 422 $response = $this->server->dispatch( $request );422 $response = rest_get_server()->dispatch( $request ); 423 423 424 424 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 400 ); … … 440 440 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/pages/%d', $page_id ) ); 441 441 $request->set_param( 'force', 'false' ); 442 $response = $this->server->dispatch( $request );442 $response = rest_get_server()->dispatch( $request ); 443 443 444 444 $this->assertEquals( 200, $response->get_status() ); … … 466 466 ) 467 467 ); 468 $response = $this->server->dispatch( $request );468 $response = rest_get_server()->dispatch( $request ); 469 469 470 470 $this->assertEquals( 200, $response->get_status() ); … … 498 498 ) 499 499 ); 500 $response = $this->server->dispatch( $request );500 $response = rest_get_server()->dispatch( $request ); 501 501 502 502 $new_data = $response->get_data(); … … 522 522 ) 523 523 ); 524 $response = $this->server->dispatch( $request );524 $response = rest_get_server()->dispatch( $request ); 525 525 526 526 $new_data = $response->get_data(); … … 546 546 ) 547 547 ); 548 $response = $this->server->dispatch( $request );548 $response = rest_get_server()->dispatch( $request ); 549 549 $new_data = $response->get_data(); 550 550 $this->assertEquals( $page_id1, $new_data['parent'] ); … … 570 570 ) 571 571 ); 572 $response = $this->server->dispatch( $request );572 $response = rest_get_server()->dispatch( $request ); 573 573 $new_data = $response->get_data(); 574 574 $this->assertEquals( 0, $new_data['parent'] ); … … 584 584 585 585 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 586 $response = $this->server->dispatch( $request );586 $response = rest_get_server()->dispatch( $request ); 587 587 588 588 $data = $response->get_data(); … … 606 606 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 607 607 $request->set_param( 'password', '$inthebananastand' ); 608 $response = $this->server->dispatch( $request );608 $response = rest_get_server()->dispatch( $request ); 609 609 610 610 $data = $response->get_data(); … … 626 626 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 627 627 $request->set_param( 'password', 'wrongpassword' ); 628 $response = $this->server->dispatch( $request );628 $response = rest_get_server()->dispatch( $request ); 629 629 630 630 $this->assertErrorResponse( 'rest_post_incorrect_password', $response, 403 ); … … 641 641 ); 642 642 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 643 $response = $this->server->dispatch( $request );643 $response = rest_get_server()->dispatch( $request ); 644 644 $data = $response->get_data(); 645 645 $this->assertEquals( '', $data['content']['rendered'] ); … … 651 651 public function test_get_item_schema() { 652 652 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); 653 $response = $this->server->dispatch( $request );653 $response = rest_get_server()->dispatch( $request ); 654 654 $data = $response->get_data(); 655 655 $properties = $data['schema']['properties']; -
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(); -
trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php
r42343 r42724 13 13 14 14 public function test_register_routes() { 15 $routes = $this->server->get_routes();15 $routes = rest_get_server()->get_routes(); 16 16 $this->assertArrayHasKey( '/wp/v2/statuses', $routes ); 17 17 $this->assertArrayHasKey( '/wp/v2/statuses/(?P<status>[\w-]+)', $routes ); … … 21 21 // Collection 22 22 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' ); 23 $response = $this->server->dispatch( $request );23 $response = rest_get_server()->dispatch( $request ); 24 24 $data = $response->get_data(); 25 25 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 27 27 // Single 28 28 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses/publish' ); 29 $response = $this->server->dispatch( $request );29 $response = rest_get_server()->dispatch( $request ); 30 30 $data = $response->get_data(); 31 31 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 35 35 public function test_get_items() { 36 36 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' ); 37 $response = $this->server->dispatch( $request );37 $response = rest_get_server()->dispatch( $request ); 38 38 39 39 $data = $response->get_data(); … … 48 48 49 49 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' ); 50 $response = $this->server->dispatch( $request );50 $response = rest_get_server()->dispatch( $request ); 51 51 52 52 $data = $response->get_data(); … … 67 67 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' ); 68 68 $request->set_param( 'context', 'edit' ); 69 $response = $this->server->dispatch( $request );69 $response = rest_get_server()->dispatch( $request ); 70 70 $this->assertErrorResponse( 'rest_cannot_view', $response, 401 ); 71 71 } … … 76 76 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/publish' ); 77 77 $request->set_param( 'context', 'edit' ); 78 $response = $this->server->dispatch( $request );78 $response = rest_get_server()->dispatch( $request ); 79 79 $this->check_post_status_object_response( $response ); 80 80 } … … 82 82 public function test_get_item_invalid_status() { 83 83 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/invalid' ); 84 $response = $this->server->dispatch( $request );84 $response = rest_get_server()->dispatch( $request ); 85 85 $this->assertErrorResponse( 'rest_status_invalid', $response, 404 ); 86 86 } … … 89 89 wp_set_current_user( 0 ); 90 90 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/draft' ); 91 $response = $this->server->dispatch( $request );91 $response = rest_get_server()->dispatch( $request ); 92 92 $this->assertErrorResponse( 'rest_cannot_read_status', $response, 401 ); 93 93 } … … 98 98 99 99 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/inherit' ); 100 $response = $this->server->dispatch( $request );100 $response = rest_get_server()->dispatch( $request ); 101 101 $this->assertErrorResponse( 'rest_cannot_read_status', $response, 403 ); 102 102 } … … 105 105 /** Post statuses can't be created */ 106 106 $request = new WP_REST_Request( 'POST', '/wp/v2/statuses' ); 107 $response = $this->server->dispatch( $request );107 $response = rest_get_server()->dispatch( $request ); 108 108 $this->assertEquals( 404, $response->get_status() ); 109 109 } … … 112 112 /** Post statuses can't be updated */ 113 113 $request = new WP_REST_Request( 'POST', '/wp/v2/statuses/draft' ); 114 $response = $this->server->dispatch( $request );114 $response = rest_get_server()->dispatch( $request ); 115 115 $this->assertEquals( 404, $response->get_status() ); 116 116 } … … 119 119 /** Post statuses can't be deleted */ 120 120 $request = new WP_REST_Request( 'DELETE', '/wp/v2/statuses/draft' ); 121 $response = $this->server->dispatch( $request );121 $response = rest_get_server()->dispatch( $request ); 122 122 $this->assertEquals( 404, $response->get_status() ); 123 123 } … … 134 134 public function test_get_item_schema() { 135 135 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' ); 136 $response = $this->server->dispatch( $request );136 $response = rest_get_server()->dispatch( $request ); 137 137 $data = $response->get_data(); 138 138 $properties = $data['schema']['properties']; … … 166 166 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' ); 167 167 168 $response = $this->server->dispatch( $request );168 $response = rest_get_server()->dispatch( $request ); 169 169 $data = $response->get_data(); 170 170 … … 174 174 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/publish' ); 175 175 176 $response = $this->server->dispatch( $request );176 $response = rest_get_server()->dispatch( $request ); 177 177 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 178 178 -
trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php
r42343 r42724 13 13 14 14 public function test_register_routes() { 15 $routes = $this->server->get_routes();15 $routes = rest_get_server()->get_routes(); 16 16 $this->assertArrayHasKey( '/wp/v2/types', $routes ); 17 17 $this->assertArrayHasKey( '/wp/v2/types/(?P<type>[\w-]+)', $routes ); … … 21 21 // Collection 22 22 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' ); 23 $response = $this->server->dispatch( $request );23 $response = rest_get_server()->dispatch( $request ); 24 24 $data = $response->get_data(); 25 25 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 27 27 // Single 28 28 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/post' ); 29 $response = $this->server->dispatch( $request );29 $response = rest_get_server()->dispatch( $request ); 30 30 $data = $response->get_data(); 31 31 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 35 35 public function test_get_items() { 36 36 $request = new WP_REST_Request( 'GET', '/wp/v2/types' ); 37 $response = $this->server->dispatch( $request );37 $response = rest_get_server()->dispatch( $request ); 38 38 39 39 $data = $response->get_data(); … … 51 51 $request = new WP_REST_Request( 'GET', '/wp/v2/types' ); 52 52 $request->set_param( 'context', 'edit' ); 53 $response = $this->server->dispatch( $request );53 $response = rest_get_server()->dispatch( $request ); 54 54 $this->assertErrorResponse( 'rest_cannot_view', $response, 401 ); 55 55 } … … 57 57 public function test_get_item() { 58 58 $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' ); 59 $response = $this->server->dispatch( $request );59 $response = rest_get_server()->dispatch( $request ); 60 60 $this->check_post_type_object_response( 'view', $response ); 61 61 $data = $response->get_data(); … … 65 65 public function test_get_item_page() { 66 66 $request = new WP_REST_Request( 'GET', '/wp/v2/types/page' ); 67 $response = $this->server->dispatch( $request );67 $response = rest_get_server()->dispatch( $request ); 68 68 $this->check_post_type_object_response( 'view', $response, 'page' ); 69 69 $data = $response->get_data(); … … 73 73 public function test_get_item_invalid_type() { 74 74 $request = new WP_REST_Request( 'GET', '/wp/v2/types/invalid' ); 75 $response = $this->server->dispatch( $request );75 $response = rest_get_server()->dispatch( $request ); 76 76 $this->assertErrorResponse( 'rest_type_invalid', $response, 404 ); 77 77 } … … 82 82 $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' ); 83 83 $request->set_param( 'context', 'edit' ); 84 $response = $this->server->dispatch( $request );84 $response = rest_get_server()->dispatch( $request ); 85 85 $this->check_post_type_object_response( 'edit', $response ); 86 86 } … … 90 90 $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' ); 91 91 $request->set_param( 'context', 'edit' ); 92 $response = $this->server->dispatch( $request );92 $response = rest_get_server()->dispatch( $request ); 93 93 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 94 94 } … … 97 97 /** Post types can't be created */ 98 98 $request = new WP_REST_Request( 'POST', '/wp/v2/types' ); 99 $response = $this->server->dispatch( $request );99 $response = rest_get_server()->dispatch( $request ); 100 100 $this->assertEquals( 404, $response->get_status() ); 101 101 } … … 104 104 /** Post types can't be updated */ 105 105 $request = new WP_REST_Request( 'POST', '/wp/v2/types/post' ); 106 $response = $this->server->dispatch( $request );106 $response = rest_get_server()->dispatch( $request ); 107 107 $this->assertEquals( 404, $response->get_status() ); 108 108 } … … 111 111 /** Post types can't be deleted */ 112 112 $request = new WP_REST_Request( 'DELETE', '/wp/v2/types/post' ); 113 $response = $this->server->dispatch( $request );113 $response = rest_get_server()->dispatch( $request ); 114 114 $this->assertEquals( 404, $response->get_status() ); 115 115 } … … 126 126 public function test_get_item_schema() { 127 127 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' ); 128 $response = $this->server->dispatch( $request );128 $response = rest_get_server()->dispatch( $request ); 129 129 $data = $response->get_data(); 130 130 $properties = $data['schema']['properties']; … … 160 160 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/schema' ); 161 161 162 $response = $this->server->dispatch( $request );162 $response = rest_get_server()->dispatch( $request ); 163 163 $data = $response->get_data(); 164 164 … … 168 168 $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' ); 169 169 170 $response = $this->server->dispatch( $request );170 $response = rest_get_server()->dispatch( $request ); 171 171 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 172 172 -
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