- Timestamp:
- 09/06/2022 09:11:41 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r54041 r54085 2263 2263 ); 2264 2264 } 2265 2266 /**2267 * @ticket 554432268 */2269 public function test_image_sources_to_rest_response() {2270 2271 $attachment_id = self::factory()->attachment->create_upload_object( $this->test_file );2272 $metadata = wp_get_attachment_metadata( $attachment_id );2273 $request = new WP_REST_Request();2274 $request['id'] = $attachment_id;2275 $controller = new WP_REST_Attachments_Controller( 'attachment' );2276 $response = $controller->get_item( $request );2277 2278 $this->assertNotWPError( $response );2279 2280 $data = $response->get_data();2281 $mime_types = array(2282 'image/jpeg',2283 );2284 2285 if ( wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {2286 array_push( $mime_types, 'image/webp' );2287 }2288 2289 foreach ( $data['media_details']['sizes'] as $size_name => $properties ) {2290 if ( ! isset( $metadata['sizes'][ $size_name ]['sources'] ) ) {2291 continue;2292 }2293 2294 $this->assertArrayHasKey( 'sources', $properties );2295 $this->assertIsArray( $properties['sources'] );2296 2297 foreach ( $mime_types as $mime_type ) {2298 $this->assertArrayHasKey( $mime_type, $properties['sources'] );2299 $this->assertArrayHasKey( 'filesize', $properties['sources'][ $mime_type ] );2300 $this->assertArrayHasKey( 'file', $properties['sources'][ $mime_type ] );2301 $this->assertArrayHasKey( 'source_url', $properties['sources'][ $mime_type ] );2302 $this->assertNotFalse( filter_var( $properties['sources'][ $mime_type ]['source_url'], FILTER_VALIDATE_URL ) );2303 }2304 }2305 $this->assertArrayNotHasKey( 'sources', $data['media_details'] );2306 }2307 2265 }
Note: See TracChangeset
for help on using the changeset viewer.