- Timestamp:
- 02/21/2018 04:24:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-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
Note: See TracChangeset
for help on using the changeset viewer.