- Timestamp:
- 02/12/2024 10:15:45 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r57380 r57603 1066 1066 $term = wp_get_post_terms( $attachment['id'], 'category' ); 1067 1067 $this->assertSame( $category['term_id'], $term[0]->term_id ); 1068 } 1069 1070 /** 1071 * @ticket 41692 1072 */ 1073 public function test_create_update_post_with_featured_media() { 1074 // Add support for thumbnails on all attachment types to avoid incorrect-usage notice. 1075 add_post_type_support( 'attachment', 'thumbnail' ); 1076 1077 wp_set_current_user( self::$editor_id ); 1078 1079 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 1080 $request->set_file_params( 1081 array( 1082 'file' => array( 1083 'file' => file_get_contents( self::$test_file ), 1084 'name' => 'canola.jpg', 1085 'size' => filesize( self::$test_file ), 1086 'tmp_name' => self::$test_file, 1087 ), 1088 ) 1089 ); 1090 $request->set_header( 'Content-MD5', md5_file( self::$test_file ) ); 1091 1092 $file = DIR_TESTDATA . '/images/canola.jpg'; 1093 $attachment_id = self::factory()->attachment->create_object( 1094 $file, 1095 0, 1096 array( 1097 'post_mime_type' => 'image/jpeg', 1098 'menu_order' => rand( 1, 100 ), 1099 ) 1100 ); 1101 1102 $request->set_param( 'featured_media', $attachment_id ); 1103 1104 $response = rest_get_server()->dispatch( $request ); 1105 $data = $response->get_data(); 1106 1107 $this->assertEquals( 201, $response->get_status() ); 1108 1109 $new_attachment = get_post( $data['id'] ); 1110 1111 $this->assertEquals( $attachment_id, (int) get_post_thumbnail_id( $new_attachment->ID ) ); 1112 $this->assertEquals( $attachment_id, $data['featured_media'] ); 1113 1114 $request = new WP_REST_Request( 'PUT', '/wp/v2/media/' . $new_attachment->ID ); 1115 $params = $this->set_post_data( 1116 array( 1117 'featured_media' => 0, 1118 ) 1119 ); 1120 $request->set_body_params( $params ); 1121 $response = rest_get_server()->dispatch( $request ); 1122 $this->assertEquals( 200, $response->get_status() ); 1123 $data = $response->get_data(); 1124 $this->assertEquals( 0, $data['featured_media'] ); 1125 $this->assertEquals( 0, (int) get_post_thumbnail_id( $new_attachment->ID ) ); 1126 1127 $request = new WP_REST_Request( 'PUT', '/wp/v2/media/' . $new_attachment->ID ); 1128 $params = $this->set_post_data( 1129 array( 1130 'featured_media' => $attachment_id, 1131 ) 1132 ); 1133 $request->set_body_params( $params ); 1134 $response = rest_get_server()->dispatch( $request ); 1135 $this->assertEquals( 200, $response->get_status() ); 1136 $data = $response->get_data(); 1137 $this->assertEquals( $attachment_id, $data['featured_media'] ); 1138 $this->assertEquals( $attachment_id, (int) get_post_thumbnail_id( $new_attachment->ID ) ); 1068 1139 } 1069 1140 … … 1577 1648 $data = $response->get_data(); 1578 1649 $properties = $data['schema']['properties']; 1579 $this->assertCount( 2 7, $properties );1650 $this->assertCount( 28, $properties ); 1580 1651 $this->assertArrayHasKey( 'author', $properties ); 1581 1652 $this->assertArrayHasKey( 'alt_text', $properties ); … … 1611 1682 $this->assertArrayHasKey( 'type', $properties ); 1612 1683 $this->assertArrayHasKey( 'missing_image_sizes', $properties ); 1684 $this->assertArrayHasKey( 'featured_media', $properties ); 1613 1685 } 1614 1686
Note: See TracChangeset
for help on using the changeset viewer.