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 $response = $this->server->dispatch( $request );1818 $response = rest_get_server()->dispatch( $request ); 1819 1819 1820 1820 $data = $response->get_data(); … … 1840 1840 ); 1841 1841 $request->set_body_params( $params ); 1842 $response = $this->server->dispatch( $request );1842 $response = rest_get_server()->dispatch( $request ); 1843 1843 1844 1844 $data = $response->get_data(); … … 1864 1864 ); 1865 1865 $request->set_body_params( $params ); 1866 $response = $this->server->dispatch( $request );1866 $response = rest_get_server()->dispatch( $request ); 1867 1867 1868 1868 $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 ); … … 1884 1884 ); 1885 1885 $request->set_body_params( $params ); 1886 $response = $this->server->dispatch( $request );1886 $response = rest_get_server()->dispatch( $request ); 1887 1887 1888 1888 $this->assertErrorResponse( 'rest_cannot_publish', $response, 403 ); … … 1899 1899 ); 1900 1900 $request->set_body_params( $params ); 1901 $response = $this->server->dispatch( $request );1901 $response = rest_get_server()->dispatch( $request ); 1902 1902 1903 1903 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1914 1914 ); 1915 1915 $request->set_body_params( $params ); 1916 $response = $this->server->dispatch( $request );1916 $response = rest_get_server()->dispatch( $request ); 1917 1917 1918 1918 $data = $response->get_data(); … … 1932 1932 ); 1933 1933 $request->set_body_params( $params ); 1934 $response = $this->server->dispatch( $request );1934 $response = rest_get_server()->dispatch( $request ); 1935 1935 1936 1936 $data = $response->get_data(); … … 1950 1950 ); 1951 1951 $request->set_body_params( $params ); 1952 $response = $this->server->dispatch( $request );1952 $response = rest_get_server()->dispatch( $request ); 1953 1953 1954 1954 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1970 1970 ); 1971 1971 $request->set_body_params( $params ); 1972 $response = $this->server->dispatch( $request );1972 $response = rest_get_server()->dispatch( $request ); 1973 1973 $this->assertEquals( 201, $response->get_status() ); 1974 1974 … … 1996 1996 ); 1997 1997 $request->set_body_params( $params ); 1998 $response = $this->server->dispatch( $request );1998 $response = rest_get_server()->dispatch( $request ); 1999 1999 $data = $response->get_data(); 2000 2000 $new_post = get_post( $data['id'] ); … … 2009 2009 ); 2010 2010 $request->set_body_params( $params ); 2011 $response = $this->server->dispatch( $request );2011 $response = rest_get_server()->dispatch( $request ); 2012 2012 $data = $response->get_data(); 2013 2013 $this->assertEquals( 0, $data['featured_media'] ); … … 2025 2025 ); 2026 2026 $request->set_body_params( $params ); 2027 $response = $this->server->dispatch( $request );2027 $response = rest_get_server()->dispatch( $request ); 2028 2028 2029 2029 $this->assertErrorResponse( 'rest_invalid_author', $response, 400 ); … … 2040 2040 ); 2041 2041 $request->set_body_params( $params ); 2042 $response = $this->server->dispatch( $request );2042 $response = rest_get_server()->dispatch( $request ); 2043 2043 2044 2044 $this->assertErrorResponse( 'rest_cannot_edit_others', $response, 403 ); … … 2055 2055 ); 2056 2056 $request->set_body_params( $params ); 2057 $response = $this->server->dispatch( $request );2057 $response = rest_get_server()->dispatch( $request ); 2058 2058 2059 2059 $data = $response->get_data(); … … 2071 2071 ); 2072 2072 $request->set_body_params( $params ); 2073 $response = $this->server->dispatch( $request );2073 $response = rest_get_server()->dispatch( $request ); 2074 2074 2075 2075 $data = $response->get_data(); … … 2089 2089 ); 2090 2090 $request->set_body_params( $params ); 2091 $response = $this->server->dispatch( $request );2091 $response = rest_get_server()->dispatch( $request ); 2092 2092 2093 2093 $this->assertEquals( 201, $response->get_status() ); … … 2107 2107 ); 2108 2108 $request->set_body_params( $params ); 2109 $response = $this->server->dispatch( $request );2109 $response = rest_get_server()->dispatch( $request ); 2110 2110 2111 2111 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2122 2122 ); 2123 2123 $request->set_body_params( $params ); 2124 $response = $this->server->dispatch( $request );2124 $response = rest_get_server()->dispatch( $request ); 2125 2125 2126 2126 $data = $response->get_data(); … … 2141 2141 ); 2142 2142 $request->set_body_params( $params ); 2143 $response = $this->server->dispatch( $request );2143 $response = rest_get_server()->dispatch( $request ); 2144 2144 2145 2145 $data = $response->get_data(); … … 2169 2169 add_filter( 'query', array( $this, 'error_insert_query' ) ); 2170 2170 2171 $response = $this->server->dispatch( $request );2171 $response = rest_get_server()->dispatch( $request ); 2172 2172 remove_filter( 'query', array( $this, 'error_insert_query' ) ); 2173 2173 $wpdb->show_errors = true; … … 2186 2186 ); 2187 2187 $request->set_body_params( $params ); 2188 $response = $this->server->dispatch( $request );2188 $response = rest_get_server()->dispatch( $request ); 2189 2189 2190 2190 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2201 2201 ); 2202 2202 $request->set_body_params( $params ); 2203 $response = $this->server->dispatch( $request );2203 $response = rest_get_server()->dispatch( $request ); 2204 2204 2205 2205 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2216 2216 ); 2217 2217 $request->set_body_params( $params ); 2218 $response = $this->server->dispatch( $request );2218 $response = rest_get_server()->dispatch( $request ); 2219 2219 $new_data = $response->get_data(); 2220 2220 $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] ); … … 2234 2234 ); 2235 2235 $request->set_body_params( $params ); 2236 $response = $this->server->dispatch( $request );2236 $response = rest_get_server()->dispatch( $request ); 2237 2237 2238 2238 $data = $response->get_data(); … … 2251 2251 ); 2252 2252 $request->set_body_params( $params ); 2253 $response = $this->server->dispatch( $request );2253 $response = rest_get_server()->dispatch( $request ); 2254 2254 2255 2255 $data = $response->get_data(); … … 2269 2269 ); 2270 2270 $request->set_body_params( $params ); 2271 $response = $this->server->dispatch( $request );2271 $response = rest_get_server()->dispatch( $request ); 2272 2272 2273 2273 $data = $response->get_data(); … … 2293 2293 2294 2294 add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2295 $response = $this->server->dispatch( $request );2295 $response = rest_get_server()->dispatch( $request ); 2296 2296 remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2297 2297 … … 2313 2313 $params = $this->set_post_data(); 2314 2314 $request->set_body_params( $params ); 2315 $response = $this->server->dispatch( $request );2315 $response = rest_get_server()->dispatch( $request ); 2316 2316 2317 2317 $this->check_update_post_response( $response ); … … 2336 2336 // Run twice to make sure that the update still succeeds even if no DB 2337 2337 // rows are updated. 2338 $response = $this->server->dispatch( $request );2338 $response = rest_get_server()->dispatch( $request ); 2339 2339 $this->check_update_post_response( $response ); 2340 2340 2341 $response = $this->server->dispatch( $request );2341 $response = rest_get_server()->dispatch( $request ); 2342 2342 $this->check_update_post_response( $response ); 2343 2343 } … … 2350 2350 $params = $this->set_post_data(); 2351 2351 $request->set_body( wp_json_encode( $params ) ); 2352 $response = $this->server->dispatch( $request );2352 $response = rest_get_server()->dispatch( $request ); 2353 2353 2354 2354 $this->check_update_post_response( $response ); … … 2371 2371 $params = $this->set_raw_post_data(); 2372 2372 $request->set_body( wp_json_encode( $params ) ); 2373 $response = $this->server->dispatch( $request );2373 $response = rest_get_server()->dispatch( $request ); 2374 2374 2375 2375 $this->check_update_post_response( $response ); … … 2395 2395 unset( $params['status'] ); 2396 2396 $request->set_body_params( $params ); 2397 $response = $this->server->dispatch( $request );2397 $response = rest_get_server()->dispatch( $request ); 2398 2398 2399 2399 $this->check_update_post_response( $response ); … … 2411 2411 $params = $this->set_post_data(); 2412 2412 $request->set_body_params( $params ); 2413 $response = $this->server->dispatch( $request );2413 $response = rest_get_server()->dispatch( $request ); 2414 2414 2415 2415 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); … … 2427 2427 ); 2428 2428 $request->set_body_params( $params ); 2429 $response = $this->server->dispatch( $request );2429 $response = rest_get_server()->dispatch( $request ); 2430 2430 2431 2431 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); … … 2436 2436 2437 2437 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) ); 2438 $response = $this->server->dispatch( $request );2438 $response = rest_get_server()->dispatch( $request ); 2439 2439 2440 2440 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 2445 2445 2446 2446 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) ); 2447 $response = $this->server->dispatch( $request );2447 $response = rest_get_server()->dispatch( $request ); 2448 2448 2449 2449 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 2460 2460 ); 2461 2461 $request->set_body_params( $params ); 2462 $response = $this->server->dispatch( $request );2462 $response = rest_get_server()->dispatch( $request ); 2463 2463 2464 2464 $data = $response->get_data(); … … 2478 2478 ); 2479 2479 $request->set_body_params( $params ); 2480 $response = $this->server->dispatch( $request );2480 $response = rest_get_server()->dispatch( $request ); 2481 2481 2482 2482 $data = $response->get_data(); … … 2496 2496 ); 2497 2497 $request->set_body_params( $params ); 2498 $response = $this->server->dispatch( $request );2498 $response = rest_get_server()->dispatch( $request ); 2499 2499 2500 2500 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2516 2516 ); 2517 2517 $request->set_body_params( $params ); 2518 $response = $this->server->dispatch( $request );2518 $response = rest_get_server()->dispatch( $request ); 2519 2519 $this->assertEquals( 200, $response->get_status() ); 2520 2520 … … 2537 2537 ); 2538 2538 $request->set_body_params( $params ); 2539 $response = $this->server->dispatch( $request );2539 $response = rest_get_server()->dispatch( $request ); 2540 2540 2541 2541 // The readonly modified param should be ignored, request should be a success. … … 2567 2567 $request->set_param( 'date_gmt', $params['date_gmt'] ); 2568 2568 } 2569 $response = $this->server->dispatch( $request );2569 $response = rest_get_server()->dispatch( $request ); 2570 2570 2571 2571 update_option( 'timezone_string', '' ); … … 2594 2594 ); 2595 2595 $request->set_body_params( $params ); 2596 $response = $this->server->dispatch( $request );2596 $response = rest_get_server()->dispatch( $request ); 2597 2597 2598 2598 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2609 2609 ); 2610 2610 $request->set_body_params( $params ); 2611 $response = $this->server->dispatch( $request );2611 $response = rest_get_server()->dispatch( $request ); 2612 2612 2613 2613 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2642 2642 2643 2643 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2644 $response = $this->server->dispatch( $request );2644 $response = rest_get_server()->dispatch( $request ); 2645 2645 $this->assertEquals( 200, $response->get_status() ); 2646 2646 $data = $response->get_data(); … … 2651 2651 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2652 2652 $request->set_param( 'date', '2016-02-23T13:00:00' ); 2653 $response = $this->server->dispatch( $request );2653 $response = rest_get_server()->dispatch( $request ); 2654 2654 $this->assertEquals( 200, $response->get_status() ); 2655 2655 $data = $response->get_data(); … … 2675 2675 ); 2676 2676 $request->set_body_params( $params ); 2677 $response = $this->server->dispatch( $request );2677 $response = rest_get_server()->dispatch( $request ); 2678 2678 2679 2679 $new_data = $response->get_data(); … … 2693 2693 ); 2694 2694 $request->set_body_params( $params ); 2695 $response = $this->server->dispatch( $request );2695 $response = rest_get_server()->dispatch( $request ); 2696 2696 2697 2697 $new_data = $response->get_data(); … … 2711 2711 ); 2712 2712 $request->set_body_params( $params ); 2713 $response = $this->server->dispatch( $request );2713 $response = rest_get_server()->dispatch( $request ); 2714 2714 2715 2715 $new_data = $response->get_data(); … … 2726 2726 ); 2727 2727 $request->set_body_params( $params ); 2728 $response = $this->server->dispatch( $request );2728 $response = rest_get_server()->dispatch( $request ); 2729 2729 2730 2730 $new_data = $response->get_data(); … … 2744 2744 ); 2745 2745 2746 $response = $this->server->dispatch( $request );2746 $response = rest_get_server()->dispatch( $request ); 2747 2747 $new_data = $response->get_data(); 2748 2748 $this->assertEquals( 'An Excerpt', $new_data['excerpt']['raw'] ); … … 2759 2759 ); 2760 2760 2761 $response = $this->server->dispatch( $request );2761 $response = rest_get_server()->dispatch( $request ); 2762 2762 $new_data = $response->get_data(); 2763 2763 $this->assertEquals( '', $new_data['excerpt']['raw'] ); … … 2774 2774 ); 2775 2775 2776 $response = $this->server->dispatch( $request );2776 $response = rest_get_server()->dispatch( $request ); 2777 2777 $new_data = $response->get_data(); 2778 2778 $this->assertEquals( 'Some Content', $new_data['content']['raw'] ); … … 2789 2789 ); 2790 2790 2791 $response = $this->server->dispatch( $request );2791 $response = rest_get_server()->dispatch( $request ); 2792 2792 $new_data = $response->get_data(); 2793 2793 $this->assertEquals( '', $new_data['content']['raw'] ); … … 2810 2810 ); 2811 2811 $request->set_body_params( $params ); 2812 $response = $this->server->dispatch( $request );2812 $response = rest_get_server()->dispatch( $request ); 2813 2813 $data = $response->get_data(); 2814 2814 $this->assertEquals( '', $data['password'] ); … … 2826 2826 ); 2827 2827 $request->set_body_params( $params ); 2828 $response = $this->server->dispatch( $request );2828 $response = rest_get_server()->dispatch( $request ); 2829 2829 2830 2830 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2843 2843 ); 2844 2844 $request->set_body_params( $params ); 2845 $response = $this->server->dispatch( $request );2845 $response = rest_get_server()->dispatch( $request ); 2846 2846 2847 2847 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2865 2865 ); 2866 2866 $request->set_body_params( $params ); 2867 $response = $this->server->dispatch( $request );2867 $response = rest_get_server()->dispatch( $request ); 2868 2868 2869 2869 $this->assertErrorResponse( 'rest_invalid_field', $response, 400 ); … … 2880 2880 ); 2881 2881 $request->set_body_params( $params ); 2882 $response = $this->server->dispatch( $request );2882 $response = rest_get_server()->dispatch( $request ); 2883 2883 $new_data = $response->get_data(); 2884 2884 $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] ); … … 2900 2900 ); 2901 2901 $request->set_body_params( $params ); 2902 $response = $this->server->dispatch( $request );2902 $response = rest_get_server()->dispatch( $request ); 2903 2903 $new_data = $response->get_data(); 2904 2904 $this->assertEquals( array( $category['term_id'] ), $new_data['categories'] ); … … 2915 2915 unset( $args['rest_route'] ); 2916 2916 $request->set_query_params( $args ); 2917 $response = $this->server->dispatch( $request );2917 $response = rest_get_server()->dispatch( $request ); 2918 2918 $data = $response->get_data(); 2919 2919 $this->assertCount( 1, $data ); … … 2935 2935 ); 2936 2936 $request->set_body_params( $params ); 2937 $response = $this->server->dispatch( $request );2937 $response = rest_get_server()->dispatch( $request ); 2938 2938 $new_data = $response->get_data(); 2939 2939 $this->assertEquals( array(), $new_data['categories'] ); … … 2958 2958 2959 2959 add_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2960 $response = $this->server->dispatch( $request );2960 $response = rest_get_server()->dispatch( $request ); 2961 2961 remove_filter( 'map_meta_cap', array( $this, 'revoke_assign_term' ), 10, 4 ); 2962 2962 … … 2984 2984 ); 2985 2985 $request->set_body_params( $params ); 2986 $response = $this->server->dispatch( $request );2986 $response = rest_get_server()->dispatch( $request ); 2987 2987 2988 2988 $data = $response->get_data(); … … 3014 3014 ); 3015 3015 $request->set_body_params( $params ); 3016 $response = $this->server->dispatch( $request );3016 $response = rest_get_server()->dispatch( $request ); 3017 3017 3018 3018 $data = $response->get_data(); … … 3042 3042 ); 3043 3043 $request->set_body_params( $params ); 3044 $response = $this->server->dispatch( $request );3044 $response = rest_get_server()->dispatch( $request ); 3045 3045 3046 3046 $this->assertEquals( 200, $response->get_status() ); … … 3059 3059 $request->set_param( $name, $value ); 3060 3060 } 3061 $response = $this->server->dispatch( $request );3061 $response = rest_get_server()->dispatch( $request ); 3062 3062 $this->assertEquals( 201, $response->get_status() ); 3063 3063 $actual_output = $response->get_data(); … … 3082 3082 $request->set_param( $name, $value ); 3083 3083 } 3084 $response = $this->server->dispatch( $request );3084 $response = rest_get_server()->dispatch( $request ); 3085 3085 $this->assertEquals( 200, $response->get_status() ); 3086 3086 $actual_output = $response->get_data(); … … 3287 3287 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 3288 3288 $request->set_param( 'force', 'false' ); 3289 $response = $this->server->dispatch( $request );3289 $response = rest_get_server()->dispatch( $request ); 3290 3290 3291 3291 $this->assertEquals( 200, $response->get_status() ); … … 3301 3301 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 3302 3302 $request['force'] = true; 3303 $response = $this->server->dispatch( $request );3303 $response = rest_get_server()->dispatch( $request ); 3304 3304 3305 3305 $this->assertEquals( 200, $response->get_status() ); … … 3313 3313 wp_set_current_user( self::$editor_id ); 3314 3314 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 3315 $response = $this->server->dispatch( $request );3315 $response = rest_get_server()->dispatch( $request ); 3316 3316 $this->assertEquals( 200, $response->get_status() ); 3317 $response = $this->server->dispatch( $request );3317 $response = rest_get_server()->dispatch( $request ); 3318 3318 $this->assertErrorResponse( 'rest_already_trashed', $response, 410 ); 3319 3319 } … … 3323 3323 3324 3324 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 3325 $response = $this->server->dispatch( $request );3325 $response = rest_get_server()->dispatch( $request ); 3326 3326 3327 3327 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 3333 3333 3334 3334 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id ); 3335 $response = $this->server->dispatch( $request );3335 $response = rest_get_server()->dispatch( $request ); 3336 3336 3337 3337 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 3342 3342 3343 3343 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3344 $response = $this->server->dispatch( $request );3344 $response = rest_get_server()->dispatch( $request ); 3345 3345 3346 3346 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); … … 3356 3356 ); 3357 3357 create_initial_rest_routes(); 3358 $routes = $this->server->get_routes();3358 $routes = rest_get_server()->get_routes(); 3359 3359 $this->assertFalse( isset( $routes['/wp/v2/invalid-controller'] ) ); 3360 3360 _unregister_post_type( 'invalid-controller' ); … … 3364 3364 public function test_get_item_schema() { 3365 3365 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3366 $response = $this->server->dispatch( $request );3366 $response = rest_get_server()->dispatch( $request ); 3367 3367 $data = $response->get_data(); 3368 3368 $properties = $data['schema']['properties']; … … 3400 3400 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3401 3401 $request->set_param( 'context', 'view' ); 3402 $response = $this->server->dispatch( $request );3402 $response = rest_get_server()->dispatch( $request ); 3403 3403 $keys = array_keys( $response->get_data() ); 3404 3404 sort( $keys ); … … 3438 3438 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3439 3439 $request->set_param( 'context', 'edit' ); 3440 $response = $this->server->dispatch( $request );3440 $response = rest_get_server()->dispatch( $request ); 3441 3441 $keys = array_keys( $response->get_data() ); 3442 3442 sort( $keys ); … … 3475 3475 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3476 3476 $request->set_param( 'context', 'embed' ); 3477 $response = $this->server->dispatch( $request );3477 $response = rest_get_server()->dispatch( $request ); 3478 3478 $keys = array_keys( $response->get_data() ); 3479 3479 sort( $keys ); … … 3496 3496 public function test_status_array_enum_args() { 3497 3497 $request = new WP_REST_Request( 'GET', '/wp/v2' ); 3498 $response = $this->server->dispatch( $request );3498 $response = rest_get_server()->dispatch( $request ); 3499 3499 $data = $response->get_data(); 3500 3500 $list_posts_args = $data['routes']['/wp/v2/posts']['endpoints'][0]['args']; … … 3528 3528 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3529 3529 3530 $response = $this->server->dispatch( $request );3530 $response = rest_get_server()->dispatch( $request ); 3531 3531 $data = $response->get_data(); 3532 3532 … … 3540 3540 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3541 3541 3542 $response = $this->server->dispatch( $request );3542 $response = rest_get_server()->dispatch( $request ); 3543 3543 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 3544 3544 … … 3550 3550 ); 3551 3551 3552 $response = $this->server->dispatch( $request );3552 $response = rest_get_server()->dispatch( $request ); 3553 3553 $this->assertEquals( 123, get_post_meta( $post_id, 'my_custom_int', true ) ); 3554 3554 … … 3561 3561 ); 3562 3562 3563 $response = $this->server->dispatch( $request );3563 $response = rest_get_server()->dispatch( $request ); 3564 3564 3565 3565 $this->assertEquals( 123, $response->data['my_custom_int'] ); … … 3594 3594 ); 3595 3595 3596 $response = $this->server->dispatch( $request );3596 $response = rest_get_server()->dispatch( $request ); 3597 3597 3598 3598 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); -
trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php
r42343 r42724 68 68 69 69 public function test_register_routes() { 70 $routes = $this->server->get_routes();70 $routes = rest_get_server()->get_routes(); 71 71 $this->assertArrayHasKey( '/wp/v2/posts/(?P<parent>[\d]+)/revisions', $routes ); 72 72 $this->assertArrayHasKey( '/wp/v2/posts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)', $routes ); … … 78 78 // Collection 79 79 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 80 $response = $this->server->dispatch( $request );80 $response = rest_get_server()->dispatch( $request ); 81 81 $data = $response->get_data(); 82 82 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 84 84 // Single 85 85 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_1->ID ); 86 $response = $this->server->dispatch( $request );86 $response = rest_get_server()->dispatch( $request ); 87 87 $data = $response->get_data(); 88 88 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 93 93 wp_set_current_user( self::$editor_id ); 94 94 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 95 $response = $this->server->dispatch( $request );95 $response = rest_get_server()->dispatch( $request ); 96 96 $data = $response->get_data(); 97 97 $this->assertEquals( 200, $response->get_status() ); … … 109 109 wp_set_current_user( 0 ); 110 110 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 111 $response = $this->server->dispatch( $request );111 $response = rest_get_server()->dispatch( $request ); 112 112 113 113 $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); 114 114 wp_set_current_user( self::$contributor_id ); 115 $response = $this->server->dispatch( $request );115 $response = rest_get_server()->dispatch( $request ); 116 116 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); 117 117 } … … 120 120 wp_set_current_user( self::$editor_id ); 121 121 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' ); 122 $response = $this->server->dispatch( $request );122 $response = rest_get_server()->dispatch( $request ); 123 123 $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); 124 124 } … … 127 127 wp_set_current_user( self::$editor_id ); 128 128 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions' ); 129 $response = $this->server->dispatch( $request );129 $response = rest_get_server()->dispatch( $request ); 130 130 $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); 131 131 } … … 134 134 wp_set_current_user( self::$editor_id ); 135 135 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 136 $response = $this->server->dispatch( $request );136 $response = rest_get_server()->dispatch( $request ); 137 137 $this->assertEquals( 200, $response->get_status() ); 138 138 $this->check_get_revision_response( $response, $this->revision_1 ); … … 160 160 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 161 161 $request->set_param( 'context', 'embed' ); 162 $response = $this->server->dispatch( $request );162 $response = rest_get_server()->dispatch( $request ); 163 163 $fields = array( 164 164 'author', … … 178 178 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 179 179 180 $response = $this->server->dispatch( $request );180 $response = rest_get_server()->dispatch( $request ); 181 181 $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); 182 182 wp_set_current_user( self::$contributor_id ); 183 $response = $this->server->dispatch( $request );183 $response = rest_get_server()->dispatch( $request ); 184 184 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); 185 185 } … … 188 188 wp_set_current_user( self::$editor_id ); 189 189 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions/' . $this->revision_id1 ); 190 $response = $this->server->dispatch( $request );190 $response = rest_get_server()->dispatch( $request ); 191 191 $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); 192 192 } … … 195 195 wp_set_current_user( self::$editor_id ); 196 196 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions/' . $this->revision_id1 ); 197 $response = $this->server->dispatch( $request );197 $response = rest_get_server()->dispatch( $request ); 198 198 $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); 199 199 } … … 203 203 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 204 204 $request->set_param( 'force', true ); 205 $response = $this->server->dispatch( $request );205 $response = rest_get_server()->dispatch( $request ); 206 206 $this->assertEquals( 200, $response->get_status() ); 207 207 $this->assertNull( get_post( $this->revision_id1 ) ); … … 212 212 213 213 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 214 $response = $this->server->dispatch( $request );214 $response = rest_get_server()->dispatch( $request ); 215 215 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 216 216 217 217 $request->set_param( 'force', 'false' ); 218 $response = $this->server->dispatch( $request );218 $response = rest_get_server()->dispatch( $request ); 219 219 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 220 220 … … 226 226 wp_set_current_user( self::$contributor_id ); 227 227 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 228 $response = $this->server->dispatch( $request );228 $response = rest_get_server()->dispatch( $request ); 229 229 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); 230 230 } … … 233 233 wp_set_current_user( self::$editor_id ); 234 234 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 235 $response = $this->server->dispatch( $request );235 $response = rest_get_server()->dispatch( $request ); 236 236 $this->assertEquals( 200, $response->get_status() ); 237 237 $this->check_get_revision_response( $response, $this->revision_1 ); … … 240 240 public function test_get_item_schema() { 241 241 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 242 $response = $this->server->dispatch( $request );242 $response = rest_get_server()->dispatch( $request ); 243 243 $data = $response->get_data(); 244 244 $properties = $data['schema']['properties']; … … 260 260 public function test_create_item() { 261 261 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 262 $response = $this->server->dispatch( $request );262 $response = rest_get_server()->dispatch( $request ); 263 263 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 264 264 } … … 266 266 public function test_update_item() { 267 267 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 268 $response = $this->server->dispatch( $request );268 $response = rest_get_server()->dispatch( $request ); 269 269 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 270 270 } … … 289 289 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' ); 290 290 291 $response = $this->server->dispatch( $request );291 $response = rest_get_server()->dispatch( $request ); 292 292 $data = $response->get_data(); 293 293 … … 299 299 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 300 300 301 $response = $this->server->dispatch( $request );301 $response = rest_get_server()->dispatch( $request ); 302 302 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 303 303 … … 355 355 wp_set_current_user( self::$editor_id ); 356 356 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 ); 357 $this->server->dispatch( $request );357 rest_get_server()->dispatch( $request ); 358 358 359 359 $post = get_post(); -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r42343 r42724 21 21 /** @var WP_REST_Server $wp_rest_server */ 22 22 global $wp_rest_server; 23 $ this->server = $wp_rest_server = new Spy_REST_Server;24 do_action( 'rest_api_init' );23 $wp_rest_server = new Spy_REST_Server; 24 do_action( 'rest_api_init', $wp_rest_server ); 25 25 26 26 add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 ); … … 73 73 74 74 public function test_expected_routes_in_schema() { 75 $routes = $this->server->get_routes();75 $routes = rest_get_server()->get_routes(); 76 76 77 77 $this->assertTrue( is_array( $routes ), '`get_routes` should return an array.' ); … … 374 374 $request->set_query_params( $route['args'] ); 375 375 } 376 $response = $this->server->dispatch( $request );376 $response = rest_get_server()->dispatch( $request ); 377 377 $status = $response->get_status(); 378 378 $data = $response->get_data(); -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r42343 r42724 17 17 $GLOBALS['wp_rest_server'] = null; 18 18 add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); 19 $ this->server= rest_get_server();19 $GLOBALS['wp_rest_server'] = rest_get_server(); 20 20 remove_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); 21 21 } … … 46 46 $response->header( 'Multiple', 'yes', false ); 47 47 48 $envelope_response = $this->server->envelope_response( $response, false );48 $envelope_response = rest_get_server()->envelope_response( $response, false ); 49 49 50 50 // The envelope should still be a response, but with defaults. … … 76 76 77 77 $request = new WP_REST_Request( 'GET', '/test-ns/test' ); 78 $response = $this->server->dispatch( $request );78 $response = rest_get_server()->dispatch( $request ); 79 79 80 80 $this->assertEquals( 'bar', $request['foo'] ); … … 97 97 $request = new WP_REST_Request( 'GET', '/test-ns/test' ); 98 98 $request->set_query_params( array( 'foo' => 123 ) ); 99 $response = $this->server->dispatch( $request );99 $response = rest_get_server()->dispatch( $request ); 100 100 101 101 $this->assertEquals( '123', $request['foo'] ); … … 115 115 $request = new WP_REST_Request( 'GET', '/optional/test' ); 116 116 $request->set_query_params( array() ); 117 $response = $this->server->dispatch( $request );117 $response = rest_get_server()->dispatch( $request ); 118 118 $this->assertInstanceOf( 'WP_REST_Response', $response ); 119 119 $this->assertEquals( 200, $response->get_status() ); … … 134 134 ); 135 135 $request = new WP_REST_Request( 'GET', '/no-zero/test' ); 136 $this->server->dispatch( $request );136 rest_get_server()->dispatch( $request ); 137 137 $this->assertEquals( array( 'foo' => 'bar' ), $request->get_params() ); 138 138 } … … 146 146 ); 147 147 $request = new WP_REST_Request( 'HEAD', '/head-request/test' ); 148 $response = $this->server->dispatch( $request );148 $response = rest_get_server()->dispatch( $request ); 149 149 $this->assertEquals( 200, $response->get_status() ); 150 150 } … … 171 171 ); 172 172 $request = new WP_REST_Request( 'HEAD', '/head-request/test' ); 173 $response = $this->server->dispatch( $request );173 $response = rest_get_server()->dispatch( $request ); 174 174 $this->assertEquals( 200, $response->get_status() ); 175 175 } … … 177 177 public function test_url_params_no_numeric_keys() { 178 178 179 $this->server->register_route(179 rest_get_server()->register_route( 180 180 'test', '/test/(?P<data>.*)', array( 181 181 array( … … 190 190 191 191 $request = new WP_REST_Request( 'GET', '/test/some-value' ); 192 $this->server->dispatch( $request );192 rest_get_server()->dispatch( $request ); 193 193 $this->assertEquals( array( 'data' => 'some-value' ), $request->get_params() ); 194 194 } … … 209 209 210 210 $request = new WP_REST_Request( 'GET', '/test-ns/test', array() ); 211 $result = $this->server->dispatch( $request );211 $result = rest_get_server()->dispatch( $request ); 212 212 213 213 $this->assertEquals( 403, $result->get_status() ); … … 234 234 wp_set_current_user( $editor ); 235 235 236 $result = $this->server->dispatch( $request );236 $result = rest_get_server()->dispatch( $request ); 237 237 238 238 $this->assertEquals( 200, $result->get_status() ); … … 255 255 $request = new WP_REST_Request( 'GET', '/test-ns/test', array() ); 256 256 257 $result = $this->server->dispatch( $request );258 $result = apply_filters( 'rest_post_dispatch', $result, $this->server, $request );257 $result = rest_get_server()->dispatch( $request ); 258 $result = apply_filters( 'rest_post_dispatch', $result, rest_get_server(), $request ); 259 259 260 260 $this->assertFalse( $result->get_status() !== 200 ); … … 288 288 $request = new WP_REST_Request( 'GET', '/test-ns/test', array() ); 289 289 290 $result = $this->server->dispatch( $request );290 $result = rest_get_server()->dispatch( $request ); 291 291 292 292 $this->assertFalse( $result->get_status() !== 200 ); 293 293 294 $result = apply_filters( 'rest_post_dispatch', $result, $this->server, $request );294 $result = apply_filters( 'rest_post_dispatch', $result, rest_get_server(), $request ); 295 295 296 296 $sent_headers = $result->get_headers(); … … 323 323 $request = new WP_REST_Request( 'GET', '/test-ns/test', array() ); 324 324 325 $result = $this->server->dispatch( $request );326 $result = apply_filters( 'rest_post_dispatch', $result, $this->server, $request );325 $result = rest_get_server()->dispatch( $request ); 326 $result = apply_filters( 'rest_post_dispatch', $result, rest_get_server(), $request ); 327 327 328 328 $this->assertEquals( $result->get_status(), 403 ); … … 348 348 349 349 $request = new WP_REST_Request( 'OPTIONS', '/test-ns/test' ); 350 $response = $this->server->dispatch( $request );351 352 $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this->server, $request );350 $response = rest_get_server()->dispatch( $request ); 351 352 $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), rest_get_server(), $request ); 353 353 354 354 $headers = $result->get_headers(); … … 366 366 $error = new WP_Error( $code, $message ); 367 367 368 $response = $this->server->error_to_response( $error );368 $response = rest_get_server()->error_to_response( $error ); 369 369 $this->assertInstanceOf( 'WP_REST_Response', $response ); 370 370 … … 383 383 $error = new WP_Error( $code, $message, array( 'status' => 400 ) ); 384 384 385 $response = $this->server->error_to_response( $error );385 $response = rest_get_server()->error_to_response( $error ); 386 386 $this->assertInstanceOf( 'WP_REST_Response', $response ); 387 387 … … 402 402 $error->add( $code2, $message2, array( 'status' => 403 ) ); 403 403 404 $response = $this->server->error_to_response( $error );404 $response = rest_get_server()->error_to_response( $error ); 405 405 $this->assertInstanceOf( 'WP_REST_Response', $response ); 406 406 … … 421 421 ); 422 422 $expected = wp_json_encode( $data ); 423 $response = $this->server->json_error( 'wp-api-test-error', 'Message text' );423 $response = rest_get_server()->json_error( 'wp-api-test-error', 'Message text' ); 424 424 425 425 $this->assertEquals( $expected, $response ); … … 451 451 $response->add_link( 'alternate', 'http://example.org/', array( 'type' => 'application/xml' ) ); 452 452 453 $data = $this->server->response_to_data( $response, false );453 $data = rest_get_server()->response_to_data( $response, false ); 454 454 $this->assertArrayHasKey( '_links', $data ); 455 455 … … 468 468 public function test_link_embedding() { 469 469 // Register our testing route. 470 $this->server->register_route(470 rest_get_server()->register_route( 471 471 'test', '/test/embeddable', array( 472 472 'methods' => 'GET', … … 482 482 $response->add_link( 'alternate', rest_url( '/test/embeddable' ), array( 'embeddable' => true ) ); 483 483 484 $data = $this->server->response_to_data( $response, true );484 $data = rest_get_server()->response_to_data( $response, true ); 485 485 $this->assertArrayHasKey( '_embedded', $data ); 486 486 … … 501 501 $response->add_link( 'https://api.w.org/term', 'http://example.com/' ); 502 502 503 $data = $this->server->response_to_data( $response, false );503 $data = rest_get_server()->response_to_data( $response, false ); 504 504 $links = $data['_links']; 505 505 … … 514 514 add_filter( 'rest_response_link_curies', array( $this, 'add_custom_curie' ) ); 515 515 516 $data = $this->server->response_to_data( $response, false );516 $data = rest_get_server()->response_to_data( $response, false ); 517 517 $links = $data['_links']; 518 518 … … 541 541 public function test_link_embedding_self() { 542 542 // Register our testing route. 543 $this->server->register_route(543 rest_get_server()->register_route( 544 544 'test', '/test/embeddable', array( 545 545 'methods' => 'GET', … … 552 552 $response->add_link( 'self', rest_url( '/test/notembeddable' ), array( 'embeddable' => true ) ); 553 553 554 $data = $this->server->response_to_data( $response, true );554 $data = rest_get_server()->response_to_data( $response, true ); 555 555 556 556 $this->assertArrayNotHasKey( '_embedded', $data ); … … 562 562 public function test_link_embedding_params() { 563 563 // Register our testing route. 564 $this->server->register_route(564 rest_get_server()->register_route( 565 565 'test', '/test/embeddable', array( 566 566 'methods' => 'GET', … … 574 574 $response->add_link( 'alternate', $url, array( 'embeddable' => true ) ); 575 575 576 $data = $this->server->response_to_data( $response, true );576 $data = rest_get_server()->response_to_data( $response, true ); 577 577 578 578 $this->assertArrayHasKey( '_embedded', $data ); … … 588 588 public function test_link_embedding_error() { 589 589 // Register our testing route. 590 $this->server->register_route(590 rest_get_server()->register_route( 591 591 'test', '/test/embeddable', array( 592 592 'methods' => 'GET', … … 600 600 $response->add_link( 'up', $url, array( 'embeddable' => true ) ); 601 601 602 $data = $this->server->response_to_data( $response, true );602 $data = rest_get_server()->response_to_data( $response, true ); 603 603 604 604 $this->assertArrayHasKey( '_embedded', $data ); … … 622 622 'untouched' => 'data', 623 623 ); 624 $result = $this->server->embed_links( $data );624 $result = rest_get_server()->embed_links( $data ); 625 625 626 626 $this->assertArrayNotHasKey( '_links', $data ); … … 651 651 $response->remove_link( 'self' ); 652 652 653 $data = $this->server->response_to_data( $response, false );653 $data = rest_get_server()->response_to_data( $response, false ); 654 654 $this->assertArrayHasKey( '_links', $data ); 655 655 … … 670 670 $response->remove_link( 'self', 'https://example.com/' ); 671 671 672 $data = $this->server->response_to_data( $response, false );672 $data = rest_get_server()->response_to_data( $response, false ); 673 673 $this->assertArrayHasKey( '_links', $data ); 674 674 … … 790 790 $request = new WP_REST_Request( 'GET', '/', array() ); 791 791 792 $result = $this->server->serve_request( '/' );793 $headers = $this->server->sent_headers;792 $result = rest_get_server()->serve_request( '/' ); 793 $headers = rest_get_server()->sent_headers; 794 794 795 795 $this->assertEquals( 'noindex', $headers['X-Robots-Tag'] ); … … 802 802 public function test_rest_enable_filter_is_deprecated() { 803 803 add_filter( 'rest_enabled', '__return_false' ); 804 $this->server->serve_request( '/' );804 rest_get_server()->serve_request( '/' ); 805 805 remove_filter( 'rest_enabled', '__return_false' ); 806 806 807 $result = json_decode( $this->server->sent_body );807 $result = json_decode( rest_get_server()->sent_body ); 808 808 809 809 $this->assertObjectNotHasAttribute( 'code', $result ); … … 815 815 $request = new WP_REST_Request( 'GET', '/', array() ); 816 816 817 $result = $this->server->serve_request( '/' );818 $headers = $this->server->sent_headers;817 $result = rest_get_server()->serve_request( '/' ); 818 $headers = rest_get_server()->sent_headers; 819 819 820 820 $this->assertEquals( '<' . esc_url_raw( $api_root ) . '>; rel="https://api.w.org/"', $headers['Link'] ); … … 826 826 wp_set_current_user( $editor ); 827 827 828 $result = $this->server->serve_request( '/' );829 $headers = $this->server->sent_headers;828 $result = rest_get_server()->serve_request( '/' ); 829 $headers = rest_get_server()->sent_headers; 830 830 831 831 foreach ( wp_get_nocache_headers() as $header => $value ) { … … 846 846 $request = new WP_REST_Request( 'GET', '/', array() ); 847 847 848 $result = $this->server->serve_request( '/' );849 $headers = $this->server->sent_headers;848 $result = rest_get_server()->serve_request( '/' ); 849 $headers = rest_get_server()->sent_headers; 850 850 851 851 foreach ( wp_get_nocache_headers() as $header => $value ) { … … 856 856 public function test_serve_request_url_params_are_unslashed() { 857 857 858 $this->server->register_route(858 rest_get_server()->register_route( 859 859 'test', '/test/(?P<data>.*)', array( 860 860 array( … … 868 868 ); 869 869 870 $result = $this->server->serve_request( '/test/data\\with\\slashes' );871 $url_params = $this->server->last_request->get_url_params();870 $result = rest_get_server()->serve_request( '/test/data\\with\\slashes' ); 871 $url_params = rest_get_server()->last_request->get_url_params(); 872 872 $this->assertEquals( 'data\\with\\slashes', $url_params['data'] ); 873 873 } … … 875 875 public function test_serve_request_query_params_are_unslashed() { 876 876 877 $this->server->register_route(877 rest_get_server()->register_route( 878 878 'test', '/test', array( 879 879 array( … … 894 894 ); 895 895 896 $result = $this->server->serve_request( '/test' );897 $query_params = $this->server->last_request->get_query_params();896 $result = rest_get_server()->serve_request( '/test' ); 897 $query_params = rest_get_server()->last_request->get_query_params(); 898 898 $this->assertEquals( 'data\\with\\slashes', $query_params['data'] ); 899 899 } … … 901 901 public function test_serve_request_body_params_are_unslashed() { 902 902 903 $this->server->register_route(903 rest_get_server()->register_route( 904 904 'test', '/test', array( 905 905 array( … … 920 920 ); 921 921 922 $result = $this->server->serve_request( '/test/data' );923 924 $body_params = $this->server->last_request->get_body_params();922 $result = rest_get_server()->serve_request( '/test/data' ); 923 924 $body_params = rest_get_server()->last_request->get_body_params(); 925 925 $this->assertEquals( 'data\\with\\slashes', $body_params['data'] ); 926 926 } … … 928 928 public function test_serve_request_json_params_are_unslashed() { 929 929 930 $this->server->register_route(930 rest_get_server()->register_route( 931 931 'test', '/test', array( 932 932 array( … … 947 947 ); 948 948 949 $result = $this->server->serve_request( '/test' );950 $json_params = $this->server->last_request->get_json_params();949 $result = rest_get_server()->serve_request( '/test' ); 950 $json_params = rest_get_server()->last_request->get_json_params(); 951 951 $this->assertEquals( 'data\\with\\slashes', $json_params['data'] ); 952 952 } … … 954 954 public function test_serve_request_file_params_are_unslashed() { 955 955 956 $this->server->register_route(956 rest_get_server()->register_route( 957 957 'test', '/test', array( 958 958 array( … … 973 973 ); 974 974 975 $result = $this->server->serve_request( '/test/data\\with\\slashes' );976 $file_params = $this->server->last_request->get_file_params();975 $result = rest_get_server()->serve_request( '/test/data\\with\\slashes' ); 976 $file_params = rest_get_server()->last_request->get_file_params(); 977 977 $this->assertEquals( 'data\\with\\slashes', $file_params['data']['name'] ); 978 978 } … … 980 980 public function test_serve_request_headers_are_unslashed() { 981 981 982 $this->server->register_route(982 rest_get_server()->register_route( 983 983 'test', '/test', array( 984 984 array( … … 995 995 $_SERVER['HTTP_X_MY_HEADER'] = wp_slash( 'data\\with\\slashes' ); 996 996 997 $result = $this->server->serve_request( '/test/data\\with\\slashes' );998 $this->assertEquals( 'data\\with\\slashes', $this->server->last_request->get_header( 'x_my_header' ) );997 $result = rest_get_server()->serve_request( '/test/data\\with\\slashes' ); 998 $this->assertEquals( 'data\\with\\slashes', rest_get_server()->last_request->get_header( 'x_my_header' ) ); 999 999 } 1000 1000 … … 1079 1079 ) 1080 1080 ); 1081 $response = $this->server->dispatch( $request );1081 $response = rest_get_server()->dispatch( $request ); 1082 1082 1083 1083 $this->assertEquals( 200, $response->get_status() ); … … 1138 1138 protected function helper_make_request_and_return_headers_for_rest_send_refreshed_nonce_tests() { 1139 1139 $request = new WP_REST_Request( 'GET', '/', array() ); 1140 $result = $this->server->serve_request( '/' );1141 1142 return $this->server->sent_headers;1140 $result = rest_get_server()->serve_request( '/' ); 1141 1142 return rest_get_server()->sent_headers; 1143 1143 } 1144 1144 } -
trunk/tests/phpunit/tests/rest-api/rest-settings-controller.php
r42423 r42724 40 40 41 41 public function test_register_routes() { 42 $routes = $this->server->get_routes();42 $routes = rest_get_server()->get_routes(); 43 43 $this->assertArrayHasKey( '/wp/v2/settings', $routes ); 44 44 } … … 48 48 wp_set_current_user( self::$administrator ); 49 49 $request = new WP_REST_Request( 'GET', '/wp/v2/settings/title' ); 50 $response = $this->server->dispatch( $request );50 $response = rest_get_server()->dispatch( $request ); 51 51 $this->assertEquals( 404, $response->get_status() ); 52 52 } … … 57 57 public function test_get_item_is_not_public_not_authenticated() { 58 58 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 59 $response = $this->server->dispatch( $request );59 $response = rest_get_server()->dispatch( $request ); 60 60 $this->assertEquals( 401, $response->get_status() ); 61 61 } … … 64 64 wp_set_current_user( self::$author ); 65 65 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 66 $response = $this->server->dispatch( $request );66 $response = rest_get_server()->dispatch( $request ); 67 67 $this->assertEquals( 403, $response->get_status() ); 68 68 } … … 71 71 wp_set_current_user( self::$administrator ); 72 72 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 73 $response = $this->server->dispatch( $request );73 $response = rest_get_server()->dispatch( $request ); 74 74 $data = $response->get_data(); 75 75 $actual = array_keys( $data ); … … 108 108 update_option( 'posts_per_page', 'invalid_number' ); // this is cast to (int) 1 109 109 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 110 $response = $this->server->dispatch( $request );110 $response = rest_get_server()->dispatch( $request ); 111 111 $data = $response->get_data(); 112 112 … … 132 132 133 133 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 134 $response = $this->server->dispatch( $request );134 $response = rest_get_server()->dispatch( $request ); 135 135 $data = $response->get_data(); 136 136 … … 142 142 143 143 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 144 $response = $this->server->dispatch( $request );144 $response = rest_get_server()->dispatch( $request ); 145 145 $data = $response->get_data(); 146 146 $this->assertEquals( 'validvalue2', $data['mycustomsettinginrest'] ); … … 169 169 update_option( 'mycustomsetting', array( '1', '2' ) ); 170 170 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 171 $response = $this->server->dispatch( $request );171 $response = rest_get_server()->dispatch( $request ); 172 172 $data = $response->get_data(); 173 173 $this->assertEquals( array( 1, 2 ), $data['mycustomsetting'] ); … … 176 176 update_option( 'mycustomsetting', array() ); 177 177 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 178 $response = $this->server->dispatch( $request );178 $response = rest_get_server()->dispatch( $request ); 179 179 $data = $response->get_data(); 180 180 $this->assertEquals( array(), $data['mycustomsetting'] ); … … 183 183 update_option( 'mycustomsetting', array( array( 1 ) ) ); 184 184 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 185 $response = $this->server->dispatch( $request );185 $response = rest_get_server()->dispatch( $request ); 186 186 $data = $response->get_data(); 187 187 $this->assertEquals( null, $data['mycustomsetting'] ); … … 190 190 delete_option( 'mycustomsetting' ); 191 191 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 192 $response = $this->server->dispatch( $request );192 $response = rest_get_server()->dispatch( $request ); 193 193 $data = $response->get_data(); 194 194 $this->assertEquals( null, $data['mycustomsetting'] ); … … 217 217 218 218 // We have to re-register the route, as the args changes based off registered settings. 219 $this->server->override_by_default = true;219 rest_get_server()->override_by_default = true; 220 220 $this->endpoint->register_routes(); 221 221 … … 223 223 update_option( 'mycustomsetting', array( 'a' => '1' ) ); 224 224 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 225 $response = $this->server->dispatch( $request );225 $response = rest_get_server()->dispatch( $request ); 226 226 $data = $response->get_data(); 227 227 $this->assertEquals( array( 'a' => 1 ), $data['mycustomsetting'] ); … … 230 230 update_option( 'mycustomsetting', array() ); 231 231 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 232 $response = $this->server->dispatch( $request );232 $response = rest_get_server()->dispatch( $request ); 233 233 $data = $response->get_data(); 234 234 $this->assertEquals( array(), $data['mycustomsetting'] ); … … 242 242 ); 243 243 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 244 $response = $this->server->dispatch( $request );244 $response = rest_get_server()->dispatch( $request ); 245 245 $data = $response->get_data(); 246 246 $this->assertEquals( null, $data['mycustomsetting'] ); … … 284 284 285 285 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 286 $response = $this->server->dispatch( $request );286 $response = rest_get_server()->dispatch( $request ); 287 287 $data = $response->get_data(); 288 288 … … 318 318 319 319 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 320 $response = $this->server->dispatch( $request );320 $response = rest_get_server()->dispatch( $request ); 321 321 $data = $response->get_data(); 322 322 $this->assertEquals( null, $data['mycustomsettinginrest'] ); … … 342 342 343 343 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 344 $response = $this->server->dispatch( $request );344 $response = rest_get_server()->dispatch( $request ); 345 345 $data = $response->get_data(); 346 346 $this->assertEquals( null, $data['mycustomsettinginrest'] ); … … 356 356 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 357 357 $request->set_param( 'title', 'The new title!' ); 358 $response = $this->server->dispatch( $request );358 $response = rest_get_server()->dispatch( $request ); 359 359 $data = $response->get_data(); 360 360 … … 389 389 390 390 // We have to re-register the route, as the args changes based off registered settings. 391 $this->server->override_by_default = true;391 rest_get_server()->override_by_default = true; 392 392 $this->endpoint->register_routes(); 393 393 wp_set_current_user( self::$administrator ); … … 395 395 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 396 396 $request->set_param( 'mycustomsetting', array( '1', '2' ) ); 397 $response = $this->server->dispatch( $request );397 $response = rest_get_server()->dispatch( $request ); 398 398 $data = $response->get_data(); 399 399 $this->assertEquals( array( 1, 2 ), $data['mycustomsetting'] ); … … 403 403 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 404 404 $request->set_param( 'mycustomsetting', array() ); 405 $response = $this->server->dispatch( $request );405 $response = rest_get_server()->dispatch( $request ); 406 406 $data = $response->get_data(); 407 407 $this->assertEquals( array(), $data['mycustomsetting'] ); … … 411 411 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 412 412 $request->set_param( 'mycustomsetting', array( 'invalid' ) ); 413 $response = $this->server->dispatch( $request );413 $response = rest_get_server()->dispatch( $request ); 414 414 415 415 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 440 440 441 441 // We have to re-register the route, as the args changes based off registered settings. 442 $this->server->override_by_default = true;442 rest_get_server()->override_by_default = true; 443 443 $this->endpoint->register_routes(); 444 444 wp_set_current_user( self::$administrator ); … … 453 453 ) 454 454 ); 455 $response = $this->server->dispatch( $request );455 $response = rest_get_server()->dispatch( $request ); 456 456 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 457 457 } … … 475 475 476 476 // We have to re-register the route, as the args changes based off registered settings. 477 $this->server->override_by_default = true;477 rest_get_server()->override_by_default = true; 478 478 $this->endpoint->register_routes(); 479 479 wp_set_current_user( self::$administrator ); … … 481 481 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 482 482 $request->set_param( 'mycustomsetting', array( 'a' => 1 ) ); 483 $response = $this->server->dispatch( $request );483 $response = rest_get_server()->dispatch( $request ); 484 484 $data = $response->get_data(); 485 485 $this->assertEquals( array( 'a' => 1 ), $data['mycustomsetting'] ); … … 489 489 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 490 490 $request->set_param( 'mycustomsetting', array() ); 491 $response = $this->server->dispatch( $request );491 $response = rest_get_server()->dispatch( $request ); 492 492 $data = $response->get_data(); 493 493 $this->assertEquals( array(), $data['mycustomsetting'] ); … … 502 502 ) 503 503 ); 504 $response = $this->server->dispatch( $request );504 $response = rest_get_server()->dispatch( $request ); 505 505 506 506 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 509 509 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 510 510 $request->set_param( 'mycustomsetting', array( 'a' => 'invalid' ) ); 511 $response = $this->server->dispatch( $request );511 $response = rest_get_server()->dispatch( $request ); 512 512 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 513 513 unregister_setting( 'somegroup', 'mycustomsetting' ); … … 520 520 $request->set_param( 'title', 'The old title!' ); 521 521 $request->set_param( 'description', 'The old description!' ); 522 $response = $this->server->dispatch( $request );522 $response = rest_get_server()->dispatch( $request ); 523 523 $data = $response->get_data(); 524 524 $this->assertEquals( 200, $response->get_status() ); … … 533 533 $request->set_param( 'title', 'The new title!' ); 534 534 $request->set_param( 'description', 'The new description!' ); 535 $response = $this->server->dispatch( $request );535 $response = rest_get_server()->dispatch( $request ); 536 536 $data = $response->get_data(); 537 537 … … 549 549 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 550 550 $request->set_param( 'title', array( 'rendered' => 'This should fail.' ) ); 551 $response = $this->server->dispatch( $request );551 $response = rest_get_server()->dispatch( $request ); 552 552 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 553 553 } … … 557 557 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 558 558 $request->set_param( 'posts_per_page', 11 ); 559 $response = $this->server->dispatch( $request );559 $response = rest_get_server()->dispatch( $request ); 560 560 $this->assertEquals( 200, $response->get_status() ); 561 561 } … … 565 565 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 566 566 $request->set_param( 'posts_per_page', 10.5 ); 567 $response = $this->server->dispatch( $request );567 $response = rest_get_server()->dispatch( $request ); 568 568 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 569 569 } … … 578 578 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 579 579 $request->set_param( 'posts_per_page', null ); 580 $response = $this->server->dispatch( $request );580 $response = rest_get_server()->dispatch( $request ); 581 581 $data = $response->get_data(); 582 582 … … 591 591 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 592 592 $request->set_param( 'default_ping_status', 'open&closed' ); 593 $response = $this->server->dispatch( $request );593 $response = rest_get_server()->dispatch( $request ); 594 594 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 595 595 } … … 609 609 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 610 610 $request->set_param( 'mycustomsetting', null ); 611 $response = $this->server->dispatch( $request );611 $response = rest_get_server()->dispatch( $request ); 612 612 613 613 $this->assertErrorResponse( 'rest_invalid_stored_value', $response, 500 ); … … 617 617 /** Settings can't be deleted */ 618 618 $request = new WP_REST_Request( 'DELETE', '/wp/v2/settings/title' ); 619 $response = $this->server->dispatch( $request );619 $response = rest_get_server()->dispatch( $request ); 620 620 $this->assertEquals( 404, $response->get_status() ); 621 621 } -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r42343 r42724 51 51 52 52 public function test_register_routes() { 53 $routes = $this->server->get_routes();53 $routes = rest_get_server()->get_routes(); 54 54 $this->assertArrayHasKey( '/wp/v2/tags', $routes ); 55 55 $this->assertArrayHasKey( '/wp/v2/tags/(?P<id>[\d]+)', $routes ); … … 59 59 // Collection 60 60 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 61 $response = $this->server->dispatch( $request );61 $response = rest_get_server()->dispatch( $request ); 62 62 $data = $response->get_data(); 63 63 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 66 66 $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); 67 67 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags/' . $tag1 ); 68 $response = $this->server->dispatch( $request );68 $response = rest_get_server()->dispatch( $request ); 69 69 $data = $response->get_data(); 70 70 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 74 74 public function test_registered_query_params() { 75 75 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 76 $response = $this->server->dispatch( $request );76 $response = rest_get_server()->dispatch( $request ); 77 77 $data = $response->get_data(); 78 78 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 99 99 $this->factory->tag->create(); 100 100 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 101 $response = $this->server->dispatch( $request );101 $response = rest_get_server()->dispatch( $request ); 102 102 $this->check_get_taxonomy_terms_response( $response ); 103 103 } … … 107 107 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 108 108 $request->set_param( 'context', 'edit' ); 109 $response = $this->server->dispatch( $request );109 $response = rest_get_server()->dispatch( $request ); 110 110 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 111 111 } … … 118 118 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 119 119 $request->set_param( 'hide_empty', true ); 120 $response = $this->server->dispatch( $request );120 $response = rest_get_server()->dispatch( $request ); 121 121 $data = $response->get_data(); 122 122 $this->assertEquals( 2, count( $data ) ); … … 125 125 // invalid value should fail 126 126 $request->set_param( 'hide_empty', 'nothanks' ); 127 $response = $this->server->dispatch( $request );127 $response = rest_get_server()->dispatch( $request ); 128 128 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 129 129 } … … 136 136 // Orderby=>asc 137 137 $request->set_param( 'include', array( $id3, $id1 ) ); 138 $response = $this->server->dispatch( $request );138 $response = rest_get_server()->dispatch( $request ); 139 139 $data = $response->get_data(); 140 140 $this->assertEquals( 2, count( $data ) ); … … 142 142 // Orderby=>include 143 143 $request->set_param( 'orderby', 'include' ); 144 $response = $this->server->dispatch( $request );144 $response = rest_get_server()->dispatch( $request ); 145 145 $data = $response->get_data(); 146 146 $this->assertEquals( 2, count( $data ) ); … … 148 148 // Include invalid value shoud fail 149 149 $request->set_param( 'include', array( 'myterm' ) ); 150 $response = $this->server->dispatch( $request );150 $response = rest_get_server()->dispatch( $request ); 151 151 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 152 152 } … … 156 156 $id2 = $this->factory->tag->create(); 157 157 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 158 $response = $this->server->dispatch( $request );158 $response = rest_get_server()->dispatch( $request ); 159 159 $data = $response->get_data(); 160 160 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 161 161 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 162 162 $request->set_param( 'exclude', array( $id2 ) ); 163 $response = $this->server->dispatch( $request );163 $response = rest_get_server()->dispatch( $request ); 164 164 $data = $response->get_data(); 165 165 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 167 167 // Invalid exclude value should fail 168 168 $request->set_param( 'exclude', array( 'invalid' ) ); 169 $response = $this->server->dispatch( $request );169 $response = rest_get_server()->dispatch( $request ); 170 170 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 171 171 } … … 178 178 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 179 179 $request->set_param( 'offset', 1 ); 180 $response = $this->server->dispatch( $request );180 $response = rest_get_server()->dispatch( $request ); 181 181 $this->assertCount( 3, $response->get_data() ); 182 182 // 'offset' works with 'per_page' 183 183 $request->set_param( 'per_page', 2 ); 184 $response = $this->server->dispatch( $request );184 $response = rest_get_server()->dispatch( $request ); 185 185 $this->assertCount( 2, $response->get_data() ); 186 186 // 'offset' takes priority over 'page' 187 187 $request->set_param( 'page', 3 ); 188 $response = $this->server->dispatch( $request );188 $response = rest_get_server()->dispatch( $request ); 189 189 $this->assertCount( 2, $response->get_data() ); 190 190 // 'offset' invalid value shoudl fail 191 191 $request->set_param( 'offset', 'moreplease' ); 192 $response = $this->server->dispatch( $request );192 $response = rest_get_server()->dispatch( $request ); 193 193 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 194 194 } … … 208 208 $request->set_param( 'order', 'desc' ); 209 209 $request->set_param( 'per_page', 1 ); 210 $response = $this->server->dispatch( $request );210 $response = rest_get_server()->dispatch( $request ); 211 211 $this->assertEquals( 200, $response->get_status() ); 212 212 $data = $response->get_data(); … … 217 217 $request->set_param( 'order', 'asc' ); 218 218 $request->set_param( 'per_page', 2 ); 219 $response = $this->server->dispatch( $request );219 $response = rest_get_server()->dispatch( $request ); 220 220 $this->assertEquals( 200, $response->get_status() ); 221 221 $data = $response->get_data(); … … 224 224 // Invalid orderby should fail. 225 225 $request->set_param( 'orderby', 'invalid' ); 226 $response = $this->server->dispatch( $request );226 $response = rest_get_server()->dispatch( $request ); 227 227 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 228 228 } … … 234 234 // defaults to orderby=name, order=asc 235 235 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 236 $response = $this->server->dispatch( $request );236 $response = rest_get_server()->dispatch( $request ); 237 237 $this->assertEquals( 200, $response->get_status() ); 238 238 $data = $response->get_data(); … … 243 243 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 244 244 $request->set_param( 'orderby', 'id' ); 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(); … … 253 253 $request->set_param( 'orderby', 'id' ); 254 254 $request->set_param( 'order', 'desc' ); 255 $response = $this->server->dispatch( $request );255 $response = rest_get_server()->dispatch( $request ); 256 256 $data = $response->get_data(); 257 257 $this->assertEquals( 200, $response->get_status() ); … … 269 269 $request->set_param( 'orderby', 'include_slugs' ); 270 270 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 271 $response = $this->server->dispatch( $request );271 $response = rest_get_server()->dispatch( $request ); 272 272 $data = $response->get_data(); 273 273 $this->assertEquals( 200, $response->get_status() ); … … 286 286 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 287 287 $request->set_param( 'post', $post_id ); 288 $response = $this->server->dispatch( $request );288 $response = rest_get_server()->dispatch( $request ); 289 289 $this->assertEquals( 200, $response->get_status() ); 290 290 … … 296 296 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 297 297 $request->set_param( 'post', 'invalid-post' ); 298 $response = $this->server->dispatch( $request );298 $response = rest_get_server()->dispatch( $request ); 299 299 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 300 300 } … … 318 318 $request->set_param( 'per_page', 15 ); 319 319 $request->set_param( 'orderby', 'id' ); 320 $response = $this->server->dispatch( $request );320 $response = rest_get_server()->dispatch( $request ); 321 321 $tags = $response->get_data(); 322 322 … … 332 332 $request->set_param( 'per_page', 15 ); 333 333 $request->set_param( 'orderby', 'id' ); 334 $response = $this->server->dispatch( $request );334 $response = rest_get_server()->dispatch( $request ); 335 335 $tags = $response->get_data(); 336 336 … … 346 346 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 347 347 $request->set_param( 'post', $post_id ); 348 $response = $this->server->dispatch( $request );348 $response = rest_get_server()->dispatch( $request ); 349 349 $this->assertEquals( 200, $response->get_status() ); 350 350 … … 380 380 $request = new WP_REST_Request( 'GET', '/wp/v2/batman' ); 381 381 $request->set_param( 'post', $post_id ); 382 $response = $this->server->dispatch( $request );382 $response = rest_get_server()->dispatch( $request ); 383 383 $this->assertEquals( 200, $response->get_status() ); 384 384 … … 397 397 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 398 398 $request->set_param( 'search', 'App' ); 399 $response = $this->server->dispatch( $request );399 $response = rest_get_server()->dispatch( $request ); 400 400 $this->assertEquals( 200, $response->get_status() ); 401 401 $data = $response->get_data(); … … 404 404 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 405 405 $request->set_param( 'search', 'Garbage' ); 406 $response = $this->server->dispatch( $request );406 $response = rest_get_server()->dispatch( $request ); 407 407 $this->assertEquals( 200, $response->get_status() ); 408 408 $data = $response->get_data(); … … 415 415 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 416 416 $request->set_param( 'slug', 'apple' ); 417 $response = $this->server->dispatch( $request );417 $response = rest_get_server()->dispatch( $request ); 418 418 $this->assertEquals( 200, $response->get_status() ); 419 419 $data = $response->get_data(); … … 435 435 ) 436 436 ); 437 $response = $this->server->dispatch( $request );437 $response = rest_get_server()->dispatch( $request ); 438 438 $this->assertEquals( 200, $response->get_status() ); 439 439 $data = $response->get_data(); … … 450 450 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 451 451 $request->set_param( 'slug', 'taco,burrito, enchilada' ); 452 $response = $this->server->dispatch( $request );452 $response = rest_get_server()->dispatch( $request ); 453 453 $this->assertEquals( 200, $response->get_status() ); 454 454 $data = $response->get_data(); … … 474 474 475 475 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' ); 476 $response = $this->server->dispatch( $request );476 $response = rest_get_server()->dispatch( $request ); 477 477 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 478 478 } … … 488 488 } 489 489 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 490 $response = $this->server->dispatch( $request );490 $response = rest_get_server()->dispatch( $request ); 491 491 $headers = $response->get_headers(); 492 492 $this->assertEquals( 50, $headers['X-WP-Total'] ); … … 507 507 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 508 508 $request->set_param( 'page', 3 ); 509 $response = $this->server->dispatch( $request );509 $response = rest_get_server()->dispatch( $request ); 510 510 $headers = $response->get_headers(); 511 511 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 526 526 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 527 527 $request->set_param( 'page', 6 ); 528 $response = $this->server->dispatch( $request );528 $response = rest_get_server()->dispatch( $request ); 529 529 $headers = $response->get_headers(); 530 530 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 540 540 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 541 541 $request->set_param( 'page', 8 ); 542 $response = $this->server->dispatch( $request );542 $response = rest_get_server()->dispatch( $request ); 543 543 $headers = $response->get_headers(); 544 544 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 556 556 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 557 557 $request->set_param( 'context', 'banana' ); 558 $response = $this->server->dispatch( $request );558 $response = rest_get_server()->dispatch( $request ); 559 559 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 560 560 } … … 563 563 $id = $this->factory->tag->create(); 564 564 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 565 $response = $this->server->dispatch( $request );565 $response = rest_get_server()->dispatch( $request ); 566 566 $this->check_get_taxonomy_term_response( $response, $id ); 567 567 } … … 569 569 public function test_get_term_invalid_term() { 570 570 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 571 $response = $this->server->dispatch( $request );571 $response = rest_get_server()->dispatch( $request ); 572 572 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 573 573 } … … 578 578 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 579 579 $request->set_param( 'context', 'edit' ); 580 $response = $this->server->dispatch( $request );580 $response = rest_get_server()->dispatch( $request ); 581 581 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 582 582 } … … 592 592 593 593 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 ); 594 $response = $this->server->dispatch( $request );594 $response = rest_get_server()->dispatch( $request ); 595 595 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 596 596 } … … 605 605 ); 606 606 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term1 ); 607 $response = $this->server->dispatch( $request );607 $response = rest_get_server()->dispatch( $request ); 608 608 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 609 609 } … … 615 615 $request->set_param( 'description', 'This term is so awesome.' ); 616 616 $request->set_param( 'slug', 'so-awesome' ); 617 $response = $this->server->dispatch( $request );617 $response = rest_get_server()->dispatch( $request ); 618 618 $this->assertEquals( 201, $response->get_status() ); 619 619 $headers = $response->get_headers(); … … 629 629 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 630 630 $request->set_param( 'name', 'Incorrect permissions' ); 631 $response = $this->server->dispatch( $request );631 $response = rest_get_server()->dispatch( $request ); 632 632 $this->assertErrorResponse( 'rest_cannot_create', $response, 403 ); 633 633 } … … 636 636 wp_set_current_user( self::$administrator ); 637 637 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 638 $response = $this->server->dispatch( $request );638 $response = rest_get_server()->dispatch( $request ); 639 639 $this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 ); 640 640 } … … 646 646 $request->set_param( 'name', 'My Awesome Term' ); 647 647 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 648 $response = $this->server->dispatch( $request );648 $response = rest_get_server()->dispatch( $request ); 649 649 $this->assertErrorResponse( 'rest_taxonomy_not_hierarchical', $response, 400 ); 650 650 } … … 662 662 $request->set_param( 'description', 'New Description' ); 663 663 $request->set_param( 'slug', 'new-slug' ); 664 $response = $this->server->dispatch( $request );664 $response = rest_get_server()->dispatch( $request ); 665 665 $this->assertEquals( 200, $response->get_status() ); 666 666 $data = $response->get_data(); … … 676 676 $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id ); 677 677 678 $response = $this->server->dispatch( $request );678 $response = rest_get_server()->dispatch( $request ); 679 679 $this->assertEquals( 200, $response->get_status() ); 680 680 $request->set_param( 'slug', $term->slug ); … … 682 682 // Run twice to make sure that the update still succeeds even if no DB 683 683 // rows are updated. 684 $response = $this->server->dispatch( $request );685 $this->assertEquals( 200, $response->get_status() ); 686 687 $response = $this->server->dispatch( $request );684 $response = rest_get_server()->dispatch( $request ); 685 $this->assertEquals( 200, $response->get_status() ); 686 687 $response = rest_get_server()->dispatch( $request ); 688 688 $this->assertEquals( 200, $response->get_status() ); 689 689 } … … 693 693 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 694 694 $request->set_param( 'name', 'Invalid Term' ); 695 $response = $this->server->dispatch( $request );695 $response = rest_get_server()->dispatch( $request ); 696 696 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 697 697 } … … 702 702 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 703 703 $request->set_param( 'name', 'Incorrect permissions' ); 704 $response = $this->server->dispatch( $request );704 $response = rest_get_server()->dispatch( $request ); 705 705 $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); 706 706 } … … 716 716 717 717 add_filter( 'map_meta_cap', array( $this, 'grant_edit_term' ), 10, 2 ); 718 $response = $this->server->dispatch( $request );718 $response = rest_get_server()->dispatch( $request ); 719 719 remove_filter( 'user_has_cap', array( $this, 'grant_edit_term' ), 10, 2 ); 720 720 … … 741 741 742 742 add_filter( 'map_meta_cap', array( $this, 'revoke_edit_term' ), 10, 2 ); 743 $response = $this->server->dispatch( $request );743 $response = rest_get_server()->dispatch( $request ); 744 744 remove_filter( 'user_has_cap', array( $this, 'revoke_edit_term' ), 10, 2 ); 745 745 … … 760 760 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 761 761 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 762 $response = $this->server->dispatch( $request );762 $response = rest_get_server()->dispatch( $request ); 763 763 $this->assertErrorResponse( 'rest_taxonomy_not_hierarchical', $response, 400 ); 764 764 } … … 770 770 $request->set_param( $name, $value ); 771 771 } 772 $response = $this->server->dispatch( $request );772 $response = rest_get_server()->dispatch( $request ); 773 773 $this->assertEquals( 201, $response->get_status() ); 774 774 $actual_output = $response->get_data(); … … 788 788 $request->set_param( $name, $value ); 789 789 } 790 $response = $this->server->dispatch( $request );790 $response = rest_get_server()->dispatch( $request ); 791 791 $this->assertEquals( 200, $response->get_status() ); 792 792 $actual_output = $response->get_data(); … … 876 876 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 877 877 $request->set_param( 'force', true ); 878 $response = $this->server->dispatch( $request );878 $response = rest_get_server()->dispatch( $request ); 879 879 $this->assertEquals( 200, $response->get_status() ); 880 880 $data = $response->get_data(); … … 888 888 889 889 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 890 $response = $this->server->dispatch( $request );890 $response = rest_get_server()->dispatch( $request ); 891 891 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 892 892 893 893 $request->set_param( 'force', 'false' ); 894 $response = $this->server->dispatch( $request );894 $response = rest_get_server()->dispatch( $request ); 895 895 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 896 896 } … … 899 899 wp_set_current_user( self::$administrator ); 900 900 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 901 $response = $this->server->dispatch( $request );901 $response = rest_get_server()->dispatch( $request ); 902 902 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 903 903 } … … 907 907 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 908 908 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 909 $response = $this->server->dispatch( $request );909 $response = rest_get_server()->dispatch( $request ); 910 910 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); 911 911 } … … 921 921 922 922 add_filter( 'map_meta_cap', array( $this, 'grant_delete_term' ), 10, 2 ); 923 $response = $this->server->dispatch( $request );923 $response = rest_get_server()->dispatch( $request ); 924 924 remove_filter( 'map_meta_cap', array( $this, 'grant_delete_term' ), 10, 2 ); 925 925 … … 947 947 948 948 add_filter( 'map_meta_cap', array( $this, 'revoke_delete_term' ), 10, 2 ); 949 $response = $this->server->dispatch( $request );949 $response = rest_get_server()->dispatch( $request ); 950 950 remove_filter( 'map_meta_cap', array( $this, 'revoke_delete_term' ), 10, 2 ); 951 951 … … 963 963 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 964 964 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term->term_id ); 965 $response = $this->server->dispatch( $request );965 $response = rest_get_server()->dispatch( $request ); 966 966 $data = $response->get_data(); 967 967 … … 971 971 public function test_get_item_schema() { 972 972 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 973 $response = $this->server->dispatch( $request );973 $response = rest_get_server()->dispatch( $request ); 974 974 $data = $response->get_data(); 975 975 $properties = $data['schema']['properties']; … … 988 988 public function test_get_item_schema_non_hierarchical() { 989 989 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 990 $response = $this->server->dispatch( $request );990 $response = rest_get_server()->dispatch( $request ); 991 991 $data = $response->get_data(); 992 992 $properties = $data['schema']['properties']; … … 1013 1013 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 1014 1014 1015 $response = $this->server->dispatch( $request );1015 $response = rest_get_server()->dispatch( $request ); 1016 1016 $data = $response->get_data(); 1017 1017 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 1021 1021 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $tag_id ); 1022 1022 1023 $response = $this->server->dispatch( $request );1023 $response = rest_get_server()->dispatch( $request ); 1024 1024 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 1025 1025 … … 1054 1054 ); 1055 1055 1056 $response = $this->server->dispatch( $request );1056 $response = rest_get_server()->dispatch( $request ); 1057 1057 1058 1058 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1074 1074 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 1075 1075 $request->set_param( 'post', $p ); 1076 $response = $this->server->dispatch( $request );1076 $response = rest_get_server()->dispatch( $request ); 1077 1077 $found_1 = wp_list_pluck( $response->data, 'id' ); 1078 1078 … … 1083 1083 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 1084 1084 $request->set_param( 'post', $p ); 1085 $response = $this->server->dispatch( $request );1085 $response = rest_get_server()->dispatch( $request ); 1086 1086 $found_2 = wp_list_pluck( $response->data, 'id' ); 1087 1087 -
trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
r42423 r42724 27 27 28 28 public function test_register_routes() { 29 $routes = $this->server->get_routes();29 $routes = rest_get_server()->get_routes(); 30 30 31 31 $this->assertArrayHasKey( '/wp/v2/taxonomies', $routes ); … … 36 36 // Collection 37 37 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies' ); 38 $response = $this->server->dispatch( $request );38 $response = rest_get_server()->dispatch( $request ); 39 39 $data = $response->get_data(); 40 40 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 42 42 // Single 43 43 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies/post_tag' ); 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'] ); … … 50 50 public function test_get_items() { 51 51 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' ); 52 $response = $this->server->dispatch( $request );52 $response = rest_get_server()->dispatch( $request ); 53 53 $data = $response->get_data(); 54 54 $taxonomies = $this->get_public_taxonomies( get_taxonomies( '', 'objects' ) ); … … 67 67 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' ); 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 } … … 74 74 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' ); 75 75 $request->set_param( 'type', 'post' ); 76 $response = $this->server->dispatch( $request );76 $response = rest_get_server()->dispatch( $request ); 77 77 $this->check_taxonomies_for_type_response( 'post', $response ); 78 78 } … … 81 81 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' ); 82 82 $request->set_param( 'type', 'wingding' ); 83 $response = $this->server->dispatch( $request );83 $response = rest_get_server()->dispatch( $request ); 84 84 $this->assertEquals( 200, $response->get_status() ); 85 85 $data = $response->get_data(); … … 89 89 public function test_get_item() { 90 90 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' ); 91 $response = $this->server->dispatch( $request );91 $response = rest_get_server()->dispatch( $request ); 92 92 $this->check_taxonomy_object_response( 'view', $response ); 93 93 } … … 98 98 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' ); 99 99 $request->set_param( 'context', 'edit' ); 100 $response = $this->server->dispatch( $request );100 $response = rest_get_server()->dispatch( $request ); 101 101 $this->check_taxonomy_object_response( 'edit', $response ); 102 102 } … … 106 106 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' ); 107 107 $request->set_param( 'context', 'edit' ); 108 $response = $this->server->dispatch( $request );108 $response = rest_get_server()->dispatch( $request ); 109 109 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 110 110 } … … 112 112 public function test_get_invalid_taxonomy() { 113 113 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/invalid' ); 114 $response = $this->server->dispatch( $request );114 $response = rest_get_server()->dispatch( $request ); 115 115 $this->assertErrorResponse( 'rest_taxonomy_invalid', $response, 404 ); 116 116 } … … 120 120 121 121 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/api-private' ); 122 $response = $this->server->dispatch( $request );122 $response = rest_get_server()->dispatch( $request ); 123 123 $this->assertErrorResponse( 'rest_forbidden', $response, 401 ); 124 124 } … … 129 129 130 130 $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/api-private' ); 131 $response = $this->server->dispatch( $request );131 $response = rest_get_server()->dispatch( $request ); 132 132 $this->assertErrorResponse( 'rest_forbidden', $response, 403 ); 133 133 } … … 136 136 /** Taxonomies can't be created */ 137 137 $request = new WP_REST_Request( 'POST', '/wp/v2/taxonomies' ); 138 $response = $this->server->dispatch( $request );138 $response = rest_get_server()->dispatch( $request ); 139 139 $this->assertEquals( 404, $response->get_status() ); 140 140 } … … 143 143 /** Taxonomies can't be updated */ 144 144 $request = new WP_REST_Request( 'POST', '/wp/v2/taxonomies/category' ); 145 $response = $this->server->dispatch( $request );145 $response = rest_get_server()->dispatch( $request ); 146 146 $this->assertEquals( 404, $response->get_status() ); 147 147 } … … 150 150 /** Taxonomies can't be deleted */ 151 151 $request = new WP_REST_Request( 'DELETE', '/wp/v2/taxonomies/category' ); 152 $response = $this->server->dispatch( $request );152 $response = rest_get_server()->dispatch( $request ); 153 153 $this->assertEquals( 404, $response->get_status() ); 154 154 } … … 165 165 public function test_get_item_schema() { 166 166 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies' ); 167 $response = $this->server->dispatch( $request );167 $response = rest_get_server()->dispatch( $request ); 168 168 $data = $response->get_data(); 169 169 $properties = $data['schema']['properties']; -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r42343 r42724 124 124 125 125 public function test_register_routes() { 126 $routes = $this->server->get_routes();126 $routes = rest_get_server()->get_routes(); 127 127 128 128 $this->assertArrayHasKey( '/wp/v2/users', $routes ); … … 136 136 // Collection 137 137 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 138 $response = $this->server->dispatch( $request );138 $response = rest_get_server()->dispatch( $request ); 139 139 $data = $response->get_data(); 140 140 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 142 142 // Single 143 143 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user ); 144 $response = $this->server->dispatch( $request );144 $response = rest_get_server()->dispatch( $request ); 145 145 $data = $response->get_data(); 146 146 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 150 150 public function test_registered_query_params() { 151 151 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 152 $response = $this->server->dispatch( $request );152 $response = rest_get_server()->dispatch( $request ); 153 153 $data = $response->get_data(); 154 154 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 176 176 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 177 177 $request->set_param( 'context', 'view' ); 178 $response = $this->server->dispatch( $request );178 $response = rest_get_server()->dispatch( $request ); 179 179 180 180 $this->assertEquals( 200, $response->get_status() ); … … 191 191 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 192 192 $request->set_param( 'context', 'edit' ); 193 $response = $this->server->dispatch( $request );193 $response = rest_get_server()->dispatch( $request ); 194 194 195 195 $this->assertEquals( 200, $response->get_status() ); … … 205 205 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 206 206 $request->set_param( 'context', 'edit' ); 207 $response = $this->server->dispatch( $request );207 $response = rest_get_server()->dispatch( $request ); 208 208 209 209 $this->assertEquals( 401, $response->get_status() ); … … 213 213 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 214 214 $request->set_param( 'context', 'edit' ); 215 $response = $this->server->dispatch( $request );215 $response = rest_get_server()->dispatch( $request ); 216 216 217 217 $this->assertEquals( 403, $response->get_status() ); … … 220 220 public function test_get_items_unauthenticated_includes_authors_of_post_types_shown_in_rest() { 221 221 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 222 $response = $this->server->dispatch( $request );222 $response = rest_get_server()->dispatch( $request ); 223 223 $users = $response->get_data(); 224 224 … … 251 251 public function test_get_items_unauthenticated_does_not_include_authors_of_post_types_not_shown_in_rest() { 252 252 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 253 $response = $this->server->dispatch( $request );253 $response = rest_get_server()->dispatch( $request ); 254 254 $users = $response->get_data(); 255 255 $user_ids = wp_list_pluck( $users, 'id' ); … … 261 261 public function test_get_items_unauthenticated_does_not_include_users_without_published_posts() { 262 262 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 263 $response = $this->server->dispatch( $request );263 $response = rest_get_server()->dispatch( $request ); 264 264 $users = $response->get_data(); 265 265 $user_ids = wp_list_pluck( $users, 'id' ); … … 279 279 } 280 280 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 281 $response = $this->server->dispatch( $request );281 $response = rest_get_server()->dispatch( $request ); 282 282 $headers = $response->get_headers(); 283 283 $this->assertEquals( 53, $headers['X-WP-Total'] ); … … 298 298 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 299 299 $request->set_param( 'page', 3 ); 300 $response = $this->server->dispatch( $request );300 $response = rest_get_server()->dispatch( $request ); 301 301 $headers = $response->get_headers(); 302 302 $this->assertEquals( 54, $headers['X-WP-Total'] ); … … 317 317 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 318 318 $request->set_param( 'page', 6 ); 319 $response = $this->server->dispatch( $request );319 $response = rest_get_server()->dispatch( $request ); 320 320 $headers = $response->get_headers(); 321 321 $this->assertEquals( 54, $headers['X-WP-Total'] ); … … 331 331 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 332 332 $request->set_param( 'page', 8 ); 333 $response = $this->server->dispatch( $request );333 $response = rest_get_server()->dispatch( $request ); 334 334 $headers = $response->get_headers(); 335 335 $this->assertEquals( 54, $headers['X-WP-Total'] ); … … 350 350 } 351 351 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 352 $response = $this->server->dispatch( $request );352 $response = rest_get_server()->dispatch( $request ); 353 353 $this->assertEquals( 10, count( $response->get_data() ) ); 354 354 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 355 355 $request->set_param( 'per_page', 5 ); 356 $response = $this->server->dispatch( $request );356 $response = rest_get_server()->dispatch( $request ); 357 357 $this->assertEquals( 5, count( $response->get_data() ) ); 358 358 } … … 366 366 $request->set_param( 'per_page', 5 ); 367 367 $request->set_param( 'page', 2 ); 368 $response = $this->server->dispatch( $request );368 $response = rest_get_server()->dispatch( $request ); 369 369 $this->assertEquals( 5, count( $response->get_data() ) ); 370 370 $prev_link = add_query_arg( … … 387 387 $request->set_param( 'order', 'desc' ); 388 388 $request->set_param( 'per_page', 1 ); 389 $response = $this->server->dispatch( $request );389 $response = rest_get_server()->dispatch( $request ); 390 390 $data = $response->get_data(); 391 391 $this->assertEquals( $high_id, $data[0]['id'] ); … … 394 394 $request->set_param( 'order', 'asc' ); 395 395 $request->set_param( 'per_page', 1 ); 396 $response = $this->server->dispatch( $request );396 $response = rest_get_server()->dispatch( $request ); 397 397 $data = $response->get_data(); 398 398 $this->assertEquals( $low_id, $data[0]['id'] ); … … 410 410 $request->set_param( 'per_page', 1 ); 411 411 $request->set_param( 'include', array( $low_id, $high_id ) ); 412 $response = $this->server->dispatch( $request );412 $response = rest_get_server()->dispatch( $request ); 413 413 $data = $response->get_data(); 414 414 … … 420 420 $request->set_param( 'per_page', 1 ); 421 421 $request->set_param( 'include', array( $low_id, $high_id ) ); 422 $response = $this->server->dispatch( $request );422 $response = rest_get_server()->dispatch( $request ); 423 423 $data = $response->get_data(); 424 424 $this->assertEquals( $low_id, $data[0]['id'] ); … … 436 436 $request->set_param( 'per_page', 1 ); 437 437 $request->set_param( 'include', array( $low_id, $high_id ) ); 438 $response = $this->server->dispatch( $request );438 $response = rest_get_server()->dispatch( $request ); 439 439 $data = $response->get_data(); 440 440 … … 446 446 $request->set_param( 'per_page', 1 ); 447 447 $request->set_param( 'include', array( $low_id, $high_id ) ); 448 $response = $this->server->dispatch( $request );448 $response = rest_get_server()->dispatch( $request ); 449 449 $data = $response->get_data(); 450 450 $this->assertEquals( $low_id, $data[0]['id'] ); … … 461 461 $request->set_param( 'orderby', 'include_slugs' ); 462 462 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 463 $response = $this->server->dispatch( $request );463 $response = rest_get_server()->dispatch( $request ); 464 464 $data = $response->get_data(); 465 465 … … 480 480 $request->set_param( 'per_page', 1 ); 481 481 $request->set_param( 'include', array( $low_id, $high_id ) ); 482 $response = $this->server->dispatch( $request );482 $response = rest_get_server()->dispatch( $request ); 483 483 $data = $response->get_data(); 484 484 $this->assertEquals( $high_id, $data[0]['id'] ); … … 489 489 $request->set_param( 'per_page', 1 ); 490 490 $request->set_param( 'include', array( $low_id, $high_id ) ); 491 $response = $this->server->dispatch( $request );491 $response = rest_get_server()->dispatch( $request ); 492 492 $data = $response->get_data(); 493 493 $this->assertEquals( $low_id, $data[0]['id'] ); … … 498 498 $request->set_param( 'orderby', 'email' ); 499 499 $request->set_param( 'order', 'desc' ); 500 $response = $this->server->dispatch( $request );500 $response = rest_get_server()->dispatch( $request ); 501 501 $this->assertErrorResponse( 'rest_forbidden_orderby', $response, 401 ); 502 502 } … … 506 506 $request->set_param( 'orderby', 'registered_date' ); 507 507 $request->set_param( 'order', 'desc' ); 508 $response = $this->server->dispatch( $request );508 $response = rest_get_server()->dispatch( $request ); 509 509 $this->assertErrorResponse( 'rest_forbidden_orderby', $response, 401 ); 510 510 } … … 513 513 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 514 514 $request->set_param( 'order', 'asc,id' ); 515 $response = $this->server->dispatch( $request );515 $response = rest_get_server()->dispatch( $request ); 516 516 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 517 517 } … … 520 520 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 521 521 $request->set_param( 'orderby', 'invalid' ); 522 $response = $this->server->dispatch( $request );522 $response = rest_get_server()->dispatch( $request ); 523 523 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 524 524 } … … 530 530 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 531 531 $request->set_param( 'offset', 1 ); 532 $response = $this->server->dispatch( $request );532 $response = rest_get_server()->dispatch( $request ); 533 533 $this->assertCount( 9, $response->get_data() ); 534 534 // 'offset' works with 'per_page' 535 535 $request->set_param( 'per_page', 2 ); 536 $response = $this->server->dispatch( $request );536 $response = rest_get_server()->dispatch( $request ); 537 537 $this->assertCount( 2, $response->get_data() ); 538 538 // 'offset' takes priority over 'page' 539 539 $request->set_param( 'page', 3 ); 540 $response = $this->server->dispatch( $request );540 $response = rest_get_server()->dispatch( $request ); 541 541 $this->assertCount( 2, $response->get_data() ); 542 542 // 'offset' invalid value should error 543 543 $request->set_param( 'offset', 'moreplease' ); 544 $response = $this->server->dispatch( $request );544 $response = rest_get_server()->dispatch( $request ); 545 545 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 546 546 } … … 554 554 // Orderby=>asc 555 555 $request->set_param( 'include', array( $id3, $id1 ) ); 556 $response = $this->server->dispatch( $request );556 $response = rest_get_server()->dispatch( $request ); 557 557 $data = $response->get_data(); 558 558 $this->assertEquals( 2, count( $data ) ); … … 560 560 // Orderby=>include 561 561 $request->set_param( 'orderby', 'include' ); 562 $response = $this->server->dispatch( $request );562 $response = rest_get_server()->dispatch( $request ); 563 563 $data = $response->get_data(); 564 564 $this->assertEquals( 2, count( $data ) ); … … 566 566 // Invalid include should fail 567 567 $request->set_param( 'include', 'invalid' ); 568 $response = $this->server->dispatch( $request );568 $response = rest_get_server()->dispatch( $request ); 569 569 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 570 570 // No privileges 571 571 $request->set_param( 'include', array( $id3, $id1 ) ); 572 572 wp_set_current_user( 0 ); 573 $response = $this->server->dispatch( $request );573 $response = rest_get_server()->dispatch( $request ); 574 574 $data = $response->get_data(); 575 575 $this->assertEquals( 0, count( $data ) ); … … 583 583 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 584 584 $request->set_param( 'per_page', 20 ); // there are >10 users at this point 585 $response = $this->server->dispatch( $request );585 $response = rest_get_server()->dispatch( $request ); 586 586 $data = $response->get_data(); 587 587 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 588 588 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 589 589 $request->set_param( 'exclude', array( $id2 ) ); 590 $response = $this->server->dispatch( $request );590 $response = rest_get_server()->dispatch( $request ); 591 591 $data = $response->get_data(); 592 592 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 594 594 // Invalid exlude value should error. 595 595 $request->set_param( 'exclude', 'none-of-those-please' ); 596 $response = $this->server->dispatch( $request );596 $response = rest_get_server()->dispatch( $request ); 597 597 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 598 598 } … … 602 602 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 603 603 $request->set_param( 'search', 'yololololo' ); 604 $response = $this->server->dispatch( $request );604 $response = rest_get_server()->dispatch( $request ); 605 605 $this->assertEquals( 0, count( $response->get_data() ) ); 606 606 $yolo_id = $this->factory->user->create( array( 'display_name' => 'yololololo' ) ); 607 607 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 608 608 $request->set_param( 'search', 'yololololo' ); 609 $response = $this->server->dispatch( $request );609 $response = rest_get_server()->dispatch( $request ); 610 610 $this->assertEquals( 1, count( $response->get_data() ) ); 611 611 // default to wildcard search … … 618 618 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 619 619 $request->set_param( 'search', 'ada' ); 620 $response = $this->server->dispatch( $request );620 $response = rest_get_server()->dispatch( $request ); 621 621 $data = $response->get_data(); 622 622 $this->assertEquals( 1, count( $data ) ); … … 640 640 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 641 641 $request->set_param( 'slug', 'foo' ); 642 $response = $this->server->dispatch( $request );642 $response = rest_get_server()->dispatch( $request ); 643 643 $data = $response->get_data(); 644 644 $this->assertEquals( 1, count( $data ) ); … … 682 682 $request->set_param( 'orderby', 'slug' ); 683 683 $request->set_param( 'order', 'asc' ); 684 $response = $this->server->dispatch( $request );684 $response = rest_get_server()->dispatch( $request ); 685 685 $this->assertEquals( 200, $response->get_status() ); 686 686 $data = $response->get_data(); … … 719 719 $request->set_param( 'orderby', 'slug' ); 720 720 $request->set_param( 'order', 'desc' ); 721 $response = $this->server->dispatch( $request );721 $response = rest_get_server()->dispatch( $request ); 722 722 $this->assertEquals( 200, $response->get_status() ); 723 723 $data = $response->get_data(); … … 743 743 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 744 744 $request->set_param( 'roles', 'author,subscriber' ); 745 $response = $this->server->dispatch( $request );745 $response = rest_get_server()->dispatch( $request ); 746 746 $data = $response->get_data(); 747 747 $this->assertEquals( 2, count( $data ) ); … … 749 749 $this->assertEquals( $yolo, $data[1]['id'] ); 750 750 $request->set_param( 'roles', 'author' ); 751 $response = $this->server->dispatch( $request );751 $response = rest_get_server()->dispatch( $request ); 752 752 $data = $response->get_data(); 753 753 $this->assertEquals( 1, count( $data ) ); … … 755 755 wp_set_current_user( 0 ); 756 756 $request->set_param( 'roles', 'author' ); 757 $response = $this->server->dispatch( $request );757 $response = rest_get_server()->dispatch( $request ); 758 758 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); 759 759 wp_set_current_user( self::$editor ); 760 760 $request->set_param( 'roles', 'author' ); 761 $response = $this->server->dispatch( $request );761 $response = rest_get_server()->dispatch( $request ); 762 762 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 ); 763 763 } … … 773 773 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 774 774 $request->set_param( 'roles', 'ilovesteak,author' ); 775 $response = $this->server->dispatch( $request );775 $response = rest_get_server()->dispatch( $request ); 776 776 $data = $response->get_data(); 777 777 $this->assertEquals( 1, count( $data ) ); … … 779 779 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 780 780 $request->set_param( 'roles', 'steakisgood' ); 781 $response = $this->server->dispatch( $request );781 $response = rest_get_server()->dispatch( $request ); 782 782 $data = $response->get_data(); 783 783 $this->assertEquals( 0, count( $data ) ); … … 791 791 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $user_id ) ); 792 792 793 $response = $this->server->dispatch( $request );793 $response = rest_get_server()->dispatch( $request ); 794 794 $this->check_get_user_response( $response, 'embed' ); 795 795 } … … 809 809 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$editor ) ); 810 810 811 $response = $this->server->dispatch( $request );811 $response = rest_get_server()->dispatch( $request ); 812 812 813 813 $data = $response->get_data(); … … 827 827 wp_set_current_user( self::$user ); 828 828 $request = new WP_REST_Request( 'GET', '/wp/v2/users/100' ); 829 $response = $this->server->dispatch( $request );829 $response = rest_get_server()->dispatch( $request ); 830 830 831 831 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); … … 846 846 $request = new WP_REST_Request( 'GET', '/wp/v2/users/' . $lolz ); 847 847 $request->set_param( 'context', 'edit' ); 848 $response = $this->server->dispatch( $request );848 $response = rest_get_server()->dispatch( $request ); 849 849 850 850 if ( is_multisite() ) { … … 861 861 wp_set_current_user( self::$editor ); 862 862 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$user ) ); 863 $response = $this->server->dispatch( $request );863 $response = rest_get_server()->dispatch( $request ); 864 864 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 ); 865 865 } … … 867 867 public function test_can_get_item_author_of_rest_true_public_true_unauthenticated() { 868 868 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) ); 869 $response = $this->server->dispatch( $request );869 $response = rest_get_server()->dispatch( $request ); 870 870 $this->assertEquals( 200, $response->get_status() ); 871 871 } … … 874 874 wp_set_current_user( self::$editor ); 875 875 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) ); 876 $response = $this->server->dispatch( $request );876 $response = rest_get_server()->dispatch( $request ); 877 877 $this->assertEquals( 200, $response->get_status() ); 878 878 } … … 880 880 public function test_can_get_item_author_of_rest_true_public_false() { 881 881 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_false'] ) ); 882 $response = $this->server->dispatch( $request );882 $response = rest_get_server()->dispatch( $request ); 883 883 $this->assertEquals( 200, $response->get_status() ); 884 884 } … … 886 886 public function test_cannot_get_item_author_of_rest_false_public_true_unauthenticated() { 887 887 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) ); 888 $response = $this->server->dispatch( $request );888 $response = rest_get_server()->dispatch( $request ); 889 889 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); 890 890 } … … 893 893 wp_set_current_user( self::$editor ); 894 894 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) ); 895 $response = $this->server->dispatch( $request );895 $response = rest_get_server()->dispatch( $request ); 896 896 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 ); 897 897 } … … 899 899 public function test_cannot_get_item_author_of_rest_false_public_false() { 900 900 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_false'] ) ); 901 $response = $this->server->dispatch( $request );901 $response = rest_get_server()->dispatch( $request ); 902 902 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); 903 903 } … … 905 905 public function test_can_get_item_author_of_post() { 906 906 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$editor ) ); 907 $response = $this->server->dispatch( $request );907 $response = rest_get_server()->dispatch( $request ); 908 908 $this->assertEquals( 200, $response->get_status() ); 909 909 } … … 911 911 public function test_cannot_get_item_author_of_draft() { 912 912 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$draft_editor ) ); 913 $response = $this->server->dispatch( $request );913 $response = rest_get_server()->dispatch( $request ); 914 914 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); 915 915 } … … 928 928 wp_set_current_user( 0 ); 929 929 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); 930 $response = $this->server->dispatch( $request );930 $response = rest_get_server()->dispatch( $request ); 931 931 $this->check_get_user_response( $response, 'embed' ); 932 932 } … … 940 940 wp_set_current_user( 0 ); 941 941 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); 942 $response = $this->server->dispatch( $request );942 $response = rest_get_server()->dispatch( $request ); 943 943 $this->assertEquals( 401, $response->get_status() ); 944 944 $this->post_id = $this->factory->post->create( … … 948 948 ) 949 949 ); 950 $response = $this->server->dispatch( $request );950 $response = rest_get_server()->dispatch( $request ); 951 951 $this->check_get_user_response( $response, 'embed' ); 952 952 } … … 959 959 $request->set_param( 'context', 'edit' ); 960 960 961 $response = $this->server->dispatch( $request );961 $response = rest_get_server()->dispatch( $request ); 962 962 $this->check_get_user_response( $response, 'edit' ); 963 963 } … … 977 977 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); 978 978 $request->set_param( 'context', 'edit' ); 979 $response = $this->server->dispatch( $request );979 $response = rest_get_server()->dispatch( $request ); 980 980 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); 981 981 } … … 986 986 $request = new WP_REST_Request( 'GET', '/wp/v2/users/me' ); 987 987 988 $response = $this->server->dispatch( $request );988 $response = rest_get_server()->dispatch( $request ); 989 989 $this->assertEquals( 200, $response->get_status() ); 990 990 $this->check_get_user_response( $response, 'view' ); … … 1000 1000 wp_set_current_user( 0 ); 1001 1001 $request = new WP_REST_Request( 'GET', '/wp/v2/users/me' ); 1002 $response = $this->server->dispatch( $request );1002 $response = rest_get_server()->dispatch( $request ); 1003 1003 1004 1004 $this->assertErrorResponse( 'rest_not_logged_in', $response, 401 ); … … 1025 1025 $request->set_body_params( $params ); 1026 1026 1027 $response = $this->server->dispatch( $request );1027 $response = rest_get_server()->dispatch( $request ); 1028 1028 $data = $response->get_data(); 1029 1029 $this->assertEquals( 'http://example.com', $data['url'] ); … … 1057 1057 $request->set_body_params( $params ); 1058 1058 1059 $response = $this->server->dispatch( $request );1059 $response = rest_get_server()->dispatch( $request ); 1060 1060 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1061 1061 … … 1101 1101 $request->set_body_params( $params ); 1102 1102 1103 $response = $this->server->dispatch( $request );1103 $response = rest_get_server()->dispatch( $request ); 1104 1104 1105 1105 remove_filter( 'illegal_user_logins', array( $this, 'get_illegal_user_logins' ) ); … … 1131 1131 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1132 1132 $request->set_body_params( $params ); 1133 $response = $this->server->dispatch( $request );1133 $response = rest_get_server()->dispatch( $request ); 1134 1134 $data = $response->get_data(); 1135 1135 $user_id = $data['id']; … … 1162 1162 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1163 1163 $request->set_body_params( $params ); 1164 $response = $this->server->dispatch( $request );1164 $response = rest_get_server()->dispatch( $request ); 1165 1165 $this->assertErrorResponse( 'user_cannot_be_added', $response ); 1166 1166 } … … 1185 1185 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1186 1186 $request->set_body_params( $params ); 1187 $response = $this->server->dispatch( $request );1187 $response = rest_get_server()->dispatch( $request ); 1188 1188 $data = $response->get_data(); 1189 1189 $user_id = $data['id']; … … 1215 1215 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1216 1216 $request->set_body_params( $params ); 1217 $response = $this->server->dispatch( $request );1217 $response = rest_get_server()->dispatch( $request ); 1218 1218 $data = $response->get_data(); 1219 1219 $user_id = $data['id']; … … 1224 1224 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1225 1225 $request->set_body_params( $params ); 1226 $switched_response = $this->server->dispatch( $request );1226 $switched_response = rest_get_server()->dispatch( $request ); 1227 1227 1228 1228 restore_current_blog(); … … 1260 1260 $request->set_body( wp_json_encode( $params ) ); 1261 1261 1262 $response = $this->server->dispatch( $request );1262 $response = rest_get_server()->dispatch( $request ); 1263 1263 $this->check_add_edit_user_response( $response ); 1264 1264 } … … 1276 1276 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1277 1277 $request->set_body_params( $params ); 1278 $response = $this->server->dispatch( $request );1278 $response = rest_get_server()->dispatch( $request ); 1279 1279 1280 1280 $this->assertErrorResponse( 'rest_cannot_create_user', $response, 403 ); … … 1295 1295 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1296 1296 $request->set_body_params( $params ); 1297 $response = $this->server->dispatch( $request );1297 $response = rest_get_server()->dispatch( $request ); 1298 1298 1299 1299 $this->assertErrorResponse( 'rest_user_exists', $response, 400 ); … … 1313 1313 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1314 1314 $request->set_body_params( $params ); 1315 $response = $this->server->dispatch( $request );1315 $response = rest_get_server()->dispatch( $request ); 1316 1316 1317 1317 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 1332 1332 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1333 1333 $request->set_body_params( $params ); 1334 $response = $this->server->dispatch( $request );1334 $response = rest_get_server()->dispatch( $request ); 1335 1335 1336 1336 $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 ); … … 1364 1364 $request->set_body_params( $_POST ); 1365 1365 1366 $response = $this->server->dispatch( $request );1366 $response = rest_get_server()->dispatch( $request ); 1367 1367 $this->check_add_edit_user_response( $response, true ); 1368 1368 … … 1392 1392 // Run twice to make sure that the update still succeeds even if no DB 1393 1393 // rows are updated. 1394 $response = $this->server->dispatch( $request );1394 $response = rest_get_server()->dispatch( $request ); 1395 1395 $this->assertEquals( 200, $response->get_status() ); 1396 1396 1397 $response = $this->server->dispatch( $request );1397 $response = rest_get_server()->dispatch( $request ); 1398 1398 $this->assertEquals( 200, $response->get_status() ); 1399 1399 } … … 1417 1417 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user2 ); 1418 1418 $request->set_param( 'email', 'testjson@example.com' ); 1419 $response = $this->server->dispatch( $request );1419 $response = rest_get_server()->dispatch( $request ); 1420 1420 $this->assertInstanceOf( 'WP_Error', $response->as_error() ); 1421 1421 $this->assertEquals( 'rest_user_invalid_email', $response->as_error()->get_error_code() ); … … 1434 1434 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user1 ); 1435 1435 $request->set_param( 'locale', 'klingon' ); 1436 $response = $this->server->dispatch( $request );1436 $response = rest_get_server()->dispatch( $request ); 1437 1437 $this->assertInstanceOf( 'WP_Error', $response->as_error() ); 1438 1438 $this->assertEquals( 'rest_invalid_param', $response->as_error()->get_error_code() ); … … 1451 1451 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user_id ); 1452 1452 $request->set_param( 'locale', 'en_US' ); 1453 $response = $this->server->dispatch( $request );1453 $response = rest_get_server()->dispatch( $request ); 1454 1454 $this->check_add_edit_user_response( $response, true ); 1455 1455 … … 1474 1474 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user_id ); 1475 1475 $request->set_param( 'locale', '' ); 1476 $response = $this->server->dispatch( $request );1476 $response = rest_get_server()->dispatch( $request ); 1477 1477 $this->check_add_edit_user_response( $response, true ); 1478 1478 … … 1501 1501 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user2 ); 1502 1502 $request->set_param( 'username', 'test_json_user' ); 1503 $response = $this->server->dispatch( $request );1503 $response = rest_get_server()->dispatch( $request ); 1504 1504 $this->assertInstanceOf( 'WP_Error', $response->as_error() ); 1505 1505 $this->assertEquals( 'rest_user_invalid_argument', $response->as_error()->get_error_code() ); … … 1524 1524 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user2 ); 1525 1525 $request->set_param( 'slug', 'test_json_user' ); 1526 $response = $this->server->dispatch( $request );1526 $response = rest_get_server()->dispatch( $request ); 1527 1527 $this->assertInstanceOf( 'WP_Error', $response->as_error() ); 1528 1528 $this->assertEquals( 'rest_user_invalid_slug', $response->as_error()->get_error_code() ); … … 1556 1556 $request->set_body( wp_json_encode( $params ) ); 1557 1557 1558 $response = $this->server->dispatch( $request );1558 $response = rest_get_server()->dispatch( $request ); 1559 1559 $this->check_add_edit_user_response( $response, true ); 1560 1560 … … 1580 1580 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); 1581 1581 $request->set_param( 'roles', array( 'editor' ) ); 1582 $response = $this->server->dispatch( $request );1582 $response = rest_get_server()->dispatch( $request ); 1583 1583 1584 1584 $new_data = $response->get_data(); … … 1600 1600 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); 1601 1601 $request->set_param( 'roles', 'author,editor' ); 1602 $response = $this->server->dispatch( $request );1602 $response = rest_get_server()->dispatch( $request ); 1603 1603 1604 1604 $new_data = $response->get_data(); … … 1617 1617 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) ); 1618 1618 $request->set_param( 'roles', array( 'administrator' ) ); 1619 $response = $this->server->dispatch( $request );1619 $response = rest_get_server()->dispatch( $request ); 1620 1620 1621 1621 $this->assertErrorResponse( 'rest_cannot_edit_roles', $response, 403 ); … … 1626 1626 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 1627 1627 $request->set_param( 'roles', array( 'administrator' ) ); 1628 $response = $this->server->dispatch( $request );1628 $response = rest_get_server()->dispatch( $request ); 1629 1629 1630 1630 $this->assertErrorResponse( 'rest_cannot_edit_roles', $response, 403 ); … … 1644 1644 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); 1645 1645 $request->set_param( 'roles', array( 'editor' ) ); 1646 $response = $this->server->dispatch( $request );1646 $response = rest_get_server()->dispatch( $request ); 1647 1647 1648 1648 $this->assertErrorResponse( 'rest_user_invalid_role', $response, 403 ); … … 1654 1654 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 1655 1655 $request->set_param( 'roles', array( 'editor' ) ); 1656 $response = $this->server->dispatch( $request );1656 $response = rest_get_server()->dispatch( $request ); 1657 1657 1658 1658 $this->assertErrorResponse( 'rest_user_invalid_role', $response, 403 ); … … 1675 1675 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); 1676 1676 $request->set_param( 'roles', array( 'editor' ) ); 1677 $response = $this->server->dispatch( $request );1677 $response = rest_get_server()->dispatch( $request ); 1678 1678 1679 1679 $new_data = $response->get_data(); … … 1689 1689 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 1690 1690 $request->set_param( 'roles', array( 'editor' ) ); 1691 $response = $this->server->dispatch( $request );1691 $response = rest_get_server()->dispatch( $request ); 1692 1692 1693 1693 $new_data = $response->get_data(); … … 1703 1703 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) ); 1704 1704 $request->set_param( 'roles', array( 'BeSharp' ) ); 1705 $response = $this->server->dispatch( $request );1705 $response = rest_get_server()->dispatch( $request ); 1706 1706 1707 1707 $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 ); … … 1713 1713 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 1714 1714 $request->set_param( 'roles', array( 'BeSharp' ) ); 1715 $response = $this->server->dispatch( $request );1715 $response = rest_get_server()->dispatch( $request ); 1716 1716 1717 1717 $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 ); … … 1734 1734 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1735 1735 $request->set_body_params( $params ); 1736 $response = $this->server->dispatch( $request );1736 $response = rest_get_server()->dispatch( $request ); 1737 1737 1738 1738 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); … … 1741 1741 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1742 1742 $request->set_body_params( $params ); 1743 $response = $this->server->dispatch( $request );1743 $response = rest_get_server()->dispatch( $request ); 1744 1744 1745 1745 $this->assertErrorResponse( 'rest_user_invalid_argument', $response, 400 ); … … 1760 1760 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1761 1761 $request->set_body_params( $params ); 1762 $response = $this->server->dispatch( $request );1762 $response = rest_get_server()->dispatch( $request ); 1763 1763 1764 1764 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); … … 1778 1778 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); 1779 1779 $request->set_param( 'roles', array( 'editor' ) ); 1780 $response = $this->server->dispatch( $request );1780 $response = rest_get_server()->dispatch( $request ); 1781 1781 $this->assertErrorResponse( 'rest_cannot_edit_roles', $response, 403 ); 1782 1782 } … … 1795 1795 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); 1796 1796 $request->set_param( 'roles', array( 'editor' ) ); 1797 $response = $this->server->dispatch( $request );1797 $response = rest_get_server()->dispatch( $request ); 1798 1798 $this->assertEquals( 200, $response->get_status() ); 1799 1799 … … 1816 1816 $request->set_param( 'roles', array( 'editor' ) ); 1817 1817 $request->set_param( 'name', 'Short-Lived User' ); 1818 $response = $this->server->dispatch( $request );1818 $response = rest_get_server()->dispatch( $request ); 1819 1819 1820 1820 if ( is_multisite() ) { … … 1840 1840 1841 1841 $request->set_param( 'password', 'no\\backslashes\\allowed' ); 1842 $response = $this->server->dispatch( $request );1842 $response = rest_get_server()->dispatch( $request ); 1843 1843 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1844 1844 1845 1845 $request->set_param( 'password', '' ); 1846 $response = $this->server->dispatch( $request );1846 $response = rest_get_server()->dispatch( $request ); 1847 1847 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1848 1848 } … … 1859 1859 } 1860 1860 $request->set_param( 'email', 'cbg@androidsdungeon.com' ); 1861 $response = $this->server->dispatch( $request );1861 $response = rest_get_server()->dispatch( $request ); 1862 1862 $this->assertEquals( 201, $response->get_status() ); 1863 1863 $actual_output = $response->get_data(); … … 1893 1893 } 1894 1894 } 1895 $response = $this->server->dispatch( $request );1895 $response = rest_get_server()->dispatch( $request ); 1896 1896 $this->assertEquals( 200, $response->get_status() ); 1897 1897 $actual_output = $response->get_data(); … … 2060 2060 $request->set_param( 'force', true ); 2061 2061 $request->set_param( 'reassign', false ); 2062 $response = $this->server->dispatch( $request );2062 $response = rest_get_server()->dispatch( $request ); 2063 2063 2064 2064 // Not implemented in multisite. … … 2084 2084 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2085 2085 $request->set_param( 'reassign', false ); 2086 $response = $this->server->dispatch( $request );2086 $response = rest_get_server()->dispatch( $request ); 2087 2087 2088 2088 // Not implemented in multisite. … … 2095 2095 2096 2096 $request->set_param( 'force', 'false' ); 2097 $response = $this->server->dispatch( $request );2097 $response = rest_get_server()->dispatch( $request ); 2098 2098 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 2099 2099 … … 2118 2118 $request['force'] = true; 2119 2119 $request->set_param( 'reassign', false ); 2120 $response = $this->server->dispatch( $request );2120 $response = rest_get_server()->dispatch( $request ); 2121 2121 2122 2122 // Not implemented in multisite. … … 2146 2146 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 2147 2147 $request->set_param( 'reassign', false ); 2148 $response = $this->server->dispatch( $request );2148 $response = rest_get_server()->dispatch( $request ); 2149 2149 2150 2150 // Not implemented in multisite. … … 2157 2157 2158 2158 $request->set_param( 'force', 'false' ); 2159 $response = $this->server->dispatch( $request );2159 $response = rest_get_server()->dispatch( $request ); 2160 2160 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 2161 2161 … … 2174 2174 $request['force'] = true; 2175 2175 $request->set_param( 'reassign', false ); 2176 $response = $this->server->dispatch( $request );2176 $response = rest_get_server()->dispatch( $request ); 2177 2177 2178 2178 $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 ); … … 2181 2181 $request['force'] = true; 2182 2182 $request->set_param( 'reassign', false ); 2183 $response = $this->server->dispatch( $request );2183 $response = rest_get_server()->dispatch( $request ); 2184 2184 2185 2185 $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 ); … … 2193 2193 $request['force'] = true; 2194 2194 $request->set_param( 'reassign', false ); 2195 $response = $this->server->dispatch( $request );2195 $response = rest_get_server()->dispatch( $request ); 2196 2196 2197 2197 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); … … 2219 2219 $request['force'] = true; 2220 2220 $request->set_param( 'reassign', $reassign_id ); 2221 $response = $this->server->dispatch( $request );2221 $response = rest_get_server()->dispatch( $request ); 2222 2222 2223 2223 // Not implemented in multisite. … … 2243 2243 $request['force'] = true; 2244 2244 $request->set_param( 'reassign', 100 ); 2245 $response = $this->server->dispatch( $request );2245 $response = rest_get_server()->dispatch( $request ); 2246 2246 2247 2247 // Not implemented in multisite. … … 2263 2263 $request['force'] = true; 2264 2264 $request->set_param( 'reassign', 'null' ); 2265 $response = $this->server->dispatch( $request );2265 $response = rest_get_server()->dispatch( $request ); 2266 2266 2267 2267 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2283 2283 $request['force'] = true; 2284 2284 $request->set_param( 'reassign', false ); 2285 $response = $this->server->dispatch( $request );2285 $response = rest_get_server()->dispatch( $request ); 2286 2286 2287 2287 // Not implemented in multisite. … … 2310 2310 $request['force'] = true; 2311 2311 $request->set_param( 'reassign', 'false' ); 2312 $response = $this->server->dispatch( $request );2312 $response = rest_get_server()->dispatch( $request ); 2313 2313 2314 2314 // Not implemented in multisite. … … 2337 2337 $request['force'] = true; 2338 2338 $request->set_param( 'reassign', '' ); 2339 $response = $this->server->dispatch( $request );2339 $response = rest_get_server()->dispatch( $request ); 2340 2340 2341 2341 // Not implemented in multisite. … … 2364 2364 $request['force'] = true; 2365 2365 $request->set_param( 'reassign', 0 ); 2366 $response = $this->server->dispatch( $request );2366 $response = rest_get_server()->dispatch( $request ); 2367 2367 2368 2368 // Not implemented in multisite. … … 2378 2378 public function test_get_item_schema() { 2379 2379 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2380 $response = $this->server->dispatch( $request );2380 $response = rest_get_server()->dispatch( $request ); 2381 2381 $data = $response->get_data(); 2382 2382 $properties = $data['schema']['properties']; … … 2408 2408 update_option( 'show_avatars', false ); 2409 2409 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2410 $response = $this->server->dispatch( $request );2410 $response = rest_get_server()->dispatch( $request ); 2411 2411 $data = $response->get_data(); 2412 2412 $properties = $data['schema']['properties']; … … 2434 2434 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2435 2435 2436 $response = $this->server->dispatch( $request );2436 $response = rest_get_server()->dispatch( $request ); 2437 2437 $data = $response->get_data(); 2438 2438 … … 2448 2448 $request = new WP_REST_Request( 'GET', '/wp/v2/users/1' ); 2449 2449 2450 $response = $this->server->dispatch( $request );2450 $response = rest_get_server()->dispatch( $request ); 2451 2451 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 2452 2452 … … 2458 2458 ); 2459 2459 2460 $response = $this->server->dispatch( $request );2460 $response = rest_get_server()->dispatch( $request ); 2461 2461 $this->assertEquals( 123, get_user_meta( 1, 'my_custom_int', true ) ); 2462 2462 … … 2471 2471 ); 2472 2472 2473 $response = $this->server->dispatch( $request );2473 $response = rest_get_server()->dispatch( $request ); 2474 2474 2475 2475 $this->assertEquals( 123, $response->data['my_custom_int'] ); … … 2509 2509 ); 2510 2510 2511 $response = $this->server->dispatch( $request );2511 $response = rest_get_server()->dispatch( $request ); 2512 2512 2513 2513 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); … … 2533 2533 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $user_id ) ); 2534 2534 2535 $response = $this->server->dispatch( $request );2535 $response = rest_get_server()->dispatch( $request ); 2536 2536 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); 2537 2537 } … … 2553 2553 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $user_id ) ); 2554 2554 2555 $response = $this->server->dispatch( $request );2555 $response = rest_get_server()->dispatch( $request ); 2556 2556 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); 2557 2557 } … … 2575 2575 $request->set_body_params( array( 'first_name' => 'New Name' ) ); 2576 2576 2577 $response = $this->server->dispatch( $request );2577 $response = rest_get_server()->dispatch( $request ); 2578 2578 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); 2579 2579 } … … 2597 2597 $request->set_body_params( array( 'first_name' => 'New Name' ) ); 2598 2598 2599 $response = $this->server->dispatch( $request );2599 $response = rest_get_server()->dispatch( $request ); 2600 2600 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); 2601 2601 } … … 2619 2619 $request->set_param( 'reassign', false ); 2620 2620 2621 $response = $this->server->dispatch( $request );2621 $response = rest_get_server()->dispatch( $request ); 2622 2622 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); 2623 2623 } … … 2641 2641 $request->set_param( 'reassign', false ); 2642 2642 2643 $response = $this->server->dispatch( $request );2643 $response = rest_get_server()->dispatch( $request ); 2644 2644 $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); 2645 2645 }
Note: See TracChangeset
for help on using the changeset viewer.