Changeset 59381 for branches/6.7/tests/phpunit/tests/media.php
- Timestamp:
- 11/11/2024 03:44:07 PM (3 weeks ago)
- Location:
- branches/6.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.7
- Property svn:mergeinfo changed
/trunk merged: 59379-59380
- Property svn:mergeinfo changed
-
branches/6.7/tests/phpunit/tests/media.php
r59247 r59381 6447 6447 6448 6448 /** 6449 * Ensure an HEIC image is converted to a JPEG. 6450 * 6451 * @ticket 62305 6452 * @ticket 62359 6453 * 6454 * @dataProvider data_image_converted_to_other_format_has_correct_filename 6455 * 6456 * @param bool $apply_big_image_size_threshold True if filter needs to apply, otherwise false. 6457 */ 6458 public function test_heic_image_upload_is_converted_to_jpeg( bool $apply_big_image_size_threshold ) { 6459 $temp_dir = get_temp_dir(); 6460 $file = $temp_dir . '/test-image.heic'; 6461 $scaled_suffix = $apply_big_image_size_threshold ? '-scaled' : ''; 6462 copy( DIR_TESTDATA . '/images/test-image.heic', $file ); 6463 6464 $editor = wp_get_image_editor( $file ); 6465 6466 // Skip if the editor does not support HEIC. 6467 if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/heic' ) ) { 6468 $this->markTestSkipped( 'HEIC is not supported by the selected image editor.' ); 6469 } 6470 6471 $attachment_id = self::factory()->attachment->create_object( 6472 array( 6473 'post_mime_type' => 'image/heic', 6474 'file' => $file, 6475 ) 6476 ); 6477 6478 if ( $apply_big_image_size_threshold ) { 6479 add_filter( 'big_image_size_threshold', array( $this, 'add_big_image_size_threshold' ) ); 6480 } 6481 6482 $image_meta = wp_generate_attachment_metadata( $attachment_id, $file ); 6483 6484 $this->assertStringEndsNotWith( '.heic', $image_meta['file'], 'The file extension is expected to change.' ); 6485 $this->assertSame( "test-image{$scaled_suffix}.jpg", basename( $image_meta['file'] ), "The file name is expected to be test-image{$scaled_suffix}.jpg" ); 6486 $this->assertSame( 'test-image.heic', $image_meta['original_image'], 'The original image name is expected to be stored in the meta data.' ); 6487 $this->assertSame( 'image/jpeg', wp_get_image_mime( $image_meta['file'] ), 'The image mime type is expected to be image/jpeg.' ); 6488 } 6489 6490 /** 6491 * Ensure a JPEG is converted to WebP when applied via a filter. 6492 * 6493 * @ticket 62305 6494 * @ticket 62359 6495 * 6496 * @dataProvider data_image_converted_to_other_format_has_correct_filename 6497 * 6498 * @param bool $apply_big_image_size_threshold True if filter needs to apply, otherwise false. 6499 */ 6500 public function test_jpeg_image_converts_to_webp_when_filtered( bool $apply_big_image_size_threshold ) { 6501 $temp_dir = get_temp_dir(); 6502 $file = $temp_dir . '/33772.jpg'; 6503 $scaled_suffix = $apply_big_image_size_threshold ? '-scaled' : ''; 6504 copy( DIR_TESTDATA . '/images/33772.jpg', $file ); 6505 6506 $editor = wp_get_image_editor( $file ); 6507 6508 // Skip if the editor does not support WebP. 6509 if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) { 6510 $this->markTestSkipped( 'WebP is not supported by the selected image editor.' ); 6511 } 6512 6513 $attachment_id = self::factory()->attachment->create_object( 6514 array( 6515 'post_mime_type' => 'image/jpeg', 6516 'file' => $file, 6517 ) 6518 ); 6519 6520 if ( $apply_big_image_size_threshold ) { 6521 add_filter( 'big_image_size_threshold', array( $this, 'add_big_image_size_threshold' ) ); 6522 } 6523 6524 // Generate all sizes as WebP. 6525 add_filter( 'image_editor_output_format', array( $this, 'image_editor_output_webp' ) ); 6526 6527 $image_meta = wp_generate_attachment_metadata( $attachment_id, $file ); 6528 6529 $this->assertStringEndsNotWith( '.jpg', $image_meta['file'], 'The file extension is expected to change.' ); 6530 $this->assertSame( "33772{$scaled_suffix}.webp", basename( $image_meta['file'] ), "The file name is expected to be 33772{$scaled_suffix}.webp." ); 6531 $this->assertSame( '33772.jpg', $image_meta['original_image'], 'The original image name is expected to be stored in the meta data.' ); 6532 $this->assertSame( 'image/webp', wp_get_image_mime( $image_meta['file'] ), 'The image mime type is expected to be image/webp.' ); 6533 } 6534 6535 /** 6536 * Data provider for test_image_converted_to_other_format_has_correct_filename(). 6537 * 6538 * @return array[] 6539 */ 6540 public function data_image_converted_to_other_format_has_correct_filename() { 6541 return array( 6542 'do not scale image' => array( false ), 6543 'scale image' => array( true ), 6544 ); 6545 } 6546 6547 /** 6449 6548 * Helper method to keep track of the last context returned by the 'wp_get_attachment_image_context' filter. 6450 6549 *
Note: See TracChangeset
for help on using the changeset viewer.