Changeset 54226 for trunk/tests/phpunit/tests/media.php
- Timestamp:
- 09/19/2022 10:51:53 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/media.php
r54128 r54226 34 34 $GLOBALS['_wp_additional_image_sizes'] = array(); 35 35 36 $filename = DIR_TESTDATA . '/images/' . self::$large_filename; 37 add_filter( 'image_editor_output_format', '__return_empty_array' ); 36 $filename = DIR_TESTDATA . '/images/' . self::$large_filename; 38 37 self::$large_id = $factory->attachment->create_upload_object( $filename ); 39 38 … … 70 69 public static function wpTearDownAfterClass() { 71 70 $GLOBALS['_wp_additional_image_sizes'] = self::$_sizes; 72 remove_filter( 'image_editor_output_format', '__return_empty_array' );73 71 } 74 72 … … 3624 3622 remove_filter( 'wp_omit_loading_attr_threshold', '__return_null', 100 ); 3625 3623 } 3626 3627 /**3628 * Test the wp_default_image_output_mapping function.3629 *3630 * @ticket 554433631 */3632 public function test_wp_default_image_output_mapping() {3633 $mapping = wp_default_image_output_mapping( array(), 'test.jpg', 'image/jpeg', '' );3634 $this->assertSame( array( 'image/jpeg' => 'image/webp' ), $mapping );3635 }3636 3637 /**3638 * Test that wp_default_image_output_mapping doesn't overwrite existing mappings.3639 *3640 * @ticket 554433641 */3642 public function test_wp_default_image_output_mapping_existing() {3643 $mapping = array( 'mime/png' => 'mime/webp' );3644 $mapping = wp_default_image_output_mapping( $mapping, 'test.jpg', 'image/jpeg', '' );3645 $this->assertSame(3646 array(3647 'mime/png' => 'mime/webp',3648 'image/jpeg' => 'image/webp',3649 ),3650 $mapping3651 );3652 }3653 3654 /**3655 * Test that the image editor default output for JPEGs is WebP.3656 *3657 * @ticket 554433658 */3659 public function test_wp_image_editor_default_output_maps_to_webp() {3660 remove_filter( 'image_editor_output_format', '__return_empty_array' );3661 3662 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );3663 $this->assertNotWPError( $editor );3664 3665 $resized = $editor->resize( 100, 100, false );3666 $this->assertNotWPError( $resized );3667 3668 $saved = $editor->save();3669 $this->assertNotWPError( $saved );3670 3671 if ( $editor->supports_mime_type( 'image/webp' ) ) {3672 $this->assertSame( 'image/webp', $saved['mime-type'] );3673 $this->assertSame( 'canola-100x75-jpg.webp', $saved['file'] );3674 } else {3675 $this->assertSame( 'image/jpeg', $saved['mime-type'] );3676 $this->assertSame( 'canola-100x75.jpg', $saved['file'] );3677 }3678 }3679 3680 /**3681 * @ticket 565263682 * @dataProvider data_wp_default_image_output_mapping_size_filter3683 */3684 public function test_wp_default_image_output_mapping_size_filter( $size_name, $filter_callback, $expects_webp ) {3685 remove_all_filters( 'wp_image_sizes_with_additional_mime_type_support' );3686 if ( $filter_callback ) {3687 add_filter( 'wp_image_sizes_with_additional_mime_type_support', $filter_callback );3688 }3689 3690 $mapping = wp_default_image_output_mapping( array(), 'test.jpg', 'image/jpeg', $size_name );3691 if ( $expects_webp ) {3692 $this->assertSame( array( 'image/jpeg' => 'image/webp' ), $mapping );3693 } else {3694 $this->assertSame( array(), $mapping );3695 }3696 }3697 3698 public function data_wp_default_image_output_mapping_size_filter() {3699 return array(3700 'default size thumbnail' => array(3701 'thumbnail',3702 null,3703 true,3704 ),3705 'default size medium' => array(3706 'medium',3707 null,3708 true,3709 ),3710 'default size medium_large' => array(3711 'medium_large',3712 null,3713 true,3714 ),3715 'default size large' => array(3716 'large',3717 null,3718 true,3719 ),3720 'default size unset' => array(3721 'medium',3722 function( $enabled_sizes ) {3723 unset( $enabled_sizes['medium'] );3724 return $enabled_sizes;3725 },3726 false,3727 ),3728 'default size set to false' => array(3729 'medium',3730 function( $enabled_sizes ) {3731 $enabled_sizes['medium'] = false;3732 return $enabled_sizes;3733 },3734 false,3735 ),3736 'custom size' => array(3737 'custom',3738 null,3739 false,3740 ),3741 'custom size opted in' => array(3742 'custom',3743 function( $enabled_sizes ) {3744 $enabled_sizes['custom'] = true;3745 return $enabled_sizes;3746 },3747 true,3748 ),3749 );3750 }3751 3624 } 3752 3625
Note: See TracChangeset
for help on using the changeset viewer.