- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r46657 r47122 88 88 public static function disposition_provider() { 89 89 return array( 90 // Types 90 // Types. 91 91 array( 'attachment; filename="foo.jpg"', 'foo.jpg' ), 92 92 array( 'inline; filename="foo.jpg"', 'foo.jpg' ), 93 93 array( 'form-data; filename="foo.jpg"', 'foo.jpg' ), 94 94 95 // Formatting 95 // Formatting. 96 96 array( 'attachment; filename="foo.jpg"', 'foo.jpg' ), 97 97 array( 'attachment; filename=foo.jpg', 'foo.jpg' ), … … 104 104 array( 'attachment; filename = my foo picture.jpg', 'my foo picture.jpg' ), 105 105 106 // Extensions 106 // Extensions. 107 107 array( 'form-data; name="myfile"; filename="foo.jpg"', 'foo.jpg' ), 108 108 array( 'form-data; name="myfile"; filename="foo.jpg"; something="else"', 'foo.jpg' ), … … 110 110 array( 'form-data; name=myfile; filename=my foo.jpg; something=else', 'my foo.jpg' ), 111 111 112 // Invalid 112 // Invalid. 113 113 array( 'filename="foo.jpg"', null ), 114 114 array( 'filename-foo.jpg', null ), … … 128 128 129 129 public function test_context_param() { 130 // Collection 130 // Collection. 131 131 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' ); 132 132 $response = rest_get_server()->dispatch( $request ); … … 134 134 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 135 135 $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 136 // Single 136 // Single. 137 137 $attachment_id = $this->factory->attachment->create_object( 138 138 $this->test_file, … … 330 330 $data = $response->get_data(); 331 331 $this->assertEquals( $id1, $data[0]['id'] ); 332 // media_type=video332 // 'media_type' => 'video'. 333 333 $request->set_param( 'media_type', 'video' ); 334 334 $response = rest_get_server()->dispatch( $request ); 335 335 $this->assertCount( 0, $response->get_data() ); 336 // media_type=image336 // 'media_type' => 'image'. 337 337 $request->set_param( 'media_type', 'image' ); 338 338 $response = rest_get_server()->dispatch( $request ); … … 353 353 $data = $response->get_data(); 354 354 $this->assertEquals( $id1, $data[0]['id'] ); 355 // mime_type=image/png355 // 'mime_type' => 'image/png'. 356 356 $request->set_param( 'mime_type', 'image/png' ); 357 357 $response = rest_get_server()->dispatch( $request ); 358 358 $this->assertCount( 0, $response->get_data() ); 359 // mime_type=image/jpeg359 // 'mime_type' => 'image/jpeg'. 360 360 $request->set_param( 'mime_type', 'image/jpeg' ); 361 361 $response = rest_get_server()->dispatch( $request ); … … 382 382 ) 383 383 ); 384 // all attachments384 // All attachments. 385 385 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 386 386 $response = rest_get_server()->dispatch( $request ); 387 387 $this->assertEquals( 2, count( $response->get_data() ) ); 388 388 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 389 // attachments without a parent389 // Attachments without a parent. 390 390 $request->set_param( 'parent', 0 ); 391 391 $response = rest_get_server()->dispatch( $request ); … … 393 393 $this->assertEquals( 1, count( $data ) ); 394 394 $this->assertEquals( $attachment_id2, $data[0]['id'] ); 395 // attachments with parent=post_id395 // Attachments with parent=post_id. 396 396 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 397 397 $request->set_param( 'parent', $post_id ); … … 400 400 $this->assertEquals( 1, count( $data ) ); 401 401 $this->assertEquals( $attachment_id, $data[0]['id'] ); 402 // attachments with invalid parent402 // Attachments with invalid parent. 403 403 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 404 404 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); … … 428 428 429 429 public function test_get_items_private_status() { 430 // Logged out users can't make the request 430 // Logged out users can't make the request. 431 431 wp_set_current_user( 0 ); 432 432 $attachment_id1 = $this->factory->attachment->create_object( … … 443 443 $response = rest_get_server()->dispatch( $request ); 444 444 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 445 // Properly authorized users can make the request 445 // Properly authorized users can make the request. 446 446 wp_set_current_user( self::$editor_id ); 447 447 $response = rest_get_server()->dispatch( $request ); … … 452 452 453 453 public function test_get_items_multiple_statuses() { 454 // Logged out users can't make the request 454 // Logged out users can't make the request. 455 455 wp_set_current_user( 0 ); 456 456 $attachment_id1 = $this->factory->attachment->create_object( … … 476 476 $response = rest_get_server()->dispatch( $request ); 477 477 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 478 // Properly authorized users can make the request 478 // Properly authorized users can make the request. 479 479 wp_set_current_user( self::$editor_id ); 480 480 $response = rest_get_server()->dispatch( $request ); … … 969 969 970 970 public function verify_attachment_roundtrip( $input = array(), $expected_output = array() ) { 971 // Create the post 971 // Create the post. 972 972 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 973 973 $request->set_header( 'Content-Type', 'image/jpeg' ); … … 982 982 $actual_output = $response->get_data(); 983 983 984 // Remove <p class="attachment"> from rendered description 985 // see https://core.trac.wordpress.org/ticket/38679984 // Remove <p class="attachment"> from rendered description. 985 // See https://core.trac.wordpress.org/ticket/38679 986 986 $content = $actual_output['description']['rendered']; 987 987 $content = explode( "\n", trim( $content ) ); … … 991 991 } 992 992 993 // Compare expected API output to actual API output 993 // Compare expected API output to actual API output. 994 994 $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); 995 995 $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); … … 999 999 $this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) ); 1000 1000 1001 // Compare expected API output to WP internal values 1001 // Compare expected API output to WP internal values. 1002 1002 $post = get_post( $actual_output['id'] ); 1003 1003 $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); … … 1005 1005 $this->assertEquals( $expected_output['caption']['raw'], $post->post_excerpt ); 1006 1006 1007 // Update the post 1007 // Update the post. 1008 1008 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/media/%d', $actual_output['id'] ) ); 1009 1009 foreach ( $input as $name => $value ) { … … 1014 1014 $actual_output = $response->get_data(); 1015 1015 1016 // Remove <p class="attachment"> from rendered description 1017 // see https://core.trac.wordpress.org/ticket/386791016 // Remove <p class="attachment"> from rendered description. 1017 // See https://core.trac.wordpress.org/ticket/38679 1018 1018 $content = $actual_output['description']['rendered']; 1019 1019 $content = explode( "\n", trim( $content ) ); … … 1023 1023 } 1024 1024 1025 // Compare expected API output to actual API output 1025 // Compare expected API output to actual API output. 1026 1026 $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); 1027 1027 $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); … … 1031 1031 $this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) ); 1032 1032 1033 // Compare expected API output to WP internal values 1033 // Compare expected API output to WP internal values. 1034 1034 $post = get_post( $actual_output['id'] ); 1035 1035 $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); … … 1248 1248 ); 1249 1249 1250 // Attempt trashing 1250 // Attempt trashing. 1251 1251 $request = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id ); 1252 1252 $response = rest_get_server()->dispatch( $request ); … … 1257 1257 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1258 1258 1259 // Ensure the post still exists 1259 // Ensure the post still exists. 1260 1260 $post = get_post( $attachment_id ); 1261 1261 $this->assertNotEmpty( $post );
Note: See TracChangeset
for help on using the changeset viewer.