Make WordPress Core


Ignore:
Timestamp:
09/06/2022 09:11:41 PM (4 years ago)
Author:
adamsilverstein
Message:

Media: revert the multi-mime feature.

This feature isn't quite ready to land.

Reverts r53786, r53848, r53847, r53845, r53751.

Props flixos90, azaozz, dd32.
See #55443.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r53920 r54085  
    22562256                add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
    22572257                add_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
    2258                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    22592258
    22602259                $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) );
    … …  
    22622261                remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
    22632262                remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
    2264                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    2265 
    22662263        }
    22672264
    … …  
    22972294                $img = wp_img_tag_add_decoding_attr( $img, 'the_content' );
    22982295                $img = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $img );
    2299                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    23002296
    23012297                // The content filter should return the image unchanged.
    23022298                $this->assertSame( $img, wp_filter_content_tags( $img ) );
    2303 
    2304                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    23052299        }
    23062300
    … …  
    23722366                add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    23732367                add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    2374                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    23752368
    23762369                add_filter(
    … …  
    24352428         */
    24362429        public function test_wp_filter_content_tags_schemes() {
    2437                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    24382430                $image_meta = wp_get_attachment_metadata( self::$large_id );
    24392431                $size_array = $this->get_image_size_array_from_meta( $image_meta, 'medium' );
    … …  
    24812473
    24822474                $this->assertSame( $expected, $actual );
    2483                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    24842475        }
    24852476
    … …  
    29752966                add_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
    29762967                add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    2977                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    29782968
    29792969                $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) );
    … …  
    29812971                remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
    29822972                remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    2983                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    29842973        }
    29852974
    … …  
    30573046                add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
    30583047                add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    3059                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    30603048
    30613049                $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) );
    … …  
    30633051                remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
    30643052                remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    3065                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    30663053        }
    30673054
    … …  
    30923079                add_filter( 'wp_lazy_loading_enabled', '__return_true' );
    30933080
    3094                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    3095 
    30963081                $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) );
    30973082                remove_filter( 'wp_lazy_loading_enabled', '__return_true' );
    30983083                remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    3099                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    3100 
    31013084        }
    31023085
    … …  
    31233106                add_filter( 'wp_lazy_loading_enabled', '__return_false' );
    31243107
    3125                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    3126 
    31273108                $this->assertSame( $content, wp_filter_content_tags( $content ) );
    31283109                remove_filter( 'wp_lazy_loading_enabled', '__return_false' );
    31293110                remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    3130                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    31313111        }
    31323112
    … …  
    35543534        function test_wp_filter_content_tags_with_wp_get_loading_attr_default() {
    35553535                global $wp_query, $wp_the_query;
    3556                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    35573536
    35583537                $img1         = get_image_tag( self::$large_id, '', '', '', 'large' );
    … …  
    35903569                        remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    35913570                }
    3592                 remove_filter( 'wp_content_image_mimes', '__return_empty_array' );
    35933571
    35943572                // After filtering, the first image should not be lazy-loaded while the other ones should be.
    … …  
    36403618                remove_filter( 'wp_omit_loading_attr_threshold', '__return_null', 100 );
    36413619        }
    3642 
    3643         /**
    3644          * @ticket 55443
    3645          */
    3646         public function test_wp_image_use_alternate_mime_types_replaces_jpg_with_webp_where_available() {
    3647                 if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
    3648                         $this->markTestSkipped( 'This test requires WebP support.' );
    3649                 }
    3650 
    3651                 // The attachment $large_id is a JPEG image, so it gets WebP files generated by default.
    3652                 $tag          = wp_get_attachment_image( self::$large_id, 'full' );
    3653                 $expected_tag = $tag;
    3654 
    3655                 $metadata = wp_get_attachment_metadata( self::$large_id );
    3656                 foreach ( $metadata['sizes'] as $size => $properties ) {
    3657                         // Some sizes may not have WebP if the WebP file is larger than the JPEG for the size.
    3658                         if ( ! isset( $properties['sources']['image/webp'] ) ) {
    3659                                 continue;
    3660                         }
    3661                         $expected_tag = str_replace( $properties['sources']['image/jpeg']['file'], $properties['sources']['image/webp']['file'], $expected_tag );
    3662                 }
    3663                 // Same applies to the full size.
    3664                 if ( isset( $metadata['sources']['image/webp'] ) ) {
    3665                         $expected_tag = str_replace( $metadata['sources']['image/jpeg']['file'], $metadata['sources']['image/webp']['file'], $expected_tag );
    3666                 }
    3667 
    3668                 $this->assertNotSame( $tag, $expected_tag );
    3669                 $this->assertSame( $expected_tag, wp_image_use_alternate_mime_types( $tag, 'the_content', self::$large_id ) );
    3670         }
    3671 
    3672         /**
    3673          * @ticket 55443
    3674          */
    3675         public function test_wp_image_use_alternate_mime_types_does_not_replace_jpg_when_webp_is_not_available() {
    3676                 if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
    3677                         $this->markTestSkipped( 'This test requires WebP support.' );
    3678                 }
    3679 
    3680                 // The attachment $large_id is a JPEG image, so it gets WebP files generated by default.
    3681                 $tag = wp_get_attachment_image( self::$large_id, 'full' );
    3682 
    3683                 // Update attachment metadata as if the image had no WebP available for any sub-sizes and the full size.
    3684                 $metadata = wp_get_attachment_metadata( self::$large_id );
    3685                 foreach ( $metadata['sizes'] as $size => $properties ) {
    3686                         unset( $metadata['sizes'][ $size ]['sources']['image/webp'] );
    3687                 }
    3688                 unset( $metadata['sources']['image/webp'] );
    3689                 wp_update_attachment_metadata( self::$large_id, $metadata );
    3690 
    3691                 $this->assertSame( $tag, wp_image_use_alternate_mime_types( $tag, 'the_content', self::$large_id ) );
    3692         }
    3693 
    3694         /**
    3695          * @ticket 55443
    3696          */
    3697         public function test_wp_image_use_alternate_mime_types_still_replaces_jpg_subsizes_when_webp_is_not_available_for_full_size() {
    3698                 if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
    3699                         $this->markTestSkipped( 'This test requires WebP support.' );
    3700                 }
    3701 
    3702                 // The attachment $large_id is a JPEG image, so it gets WebP files generated by default.
    3703                 $tag          = wp_get_attachment_image( self::$large_id, 'full' );
    3704                 $expected_tag = $tag;
    3705 
    3706                 // Update attachment metadata as if the image had no WebP available for the full size.
    3707                 $metadata = wp_get_attachment_metadata( self::$large_id );
    3708                 unset( $metadata['sources']['image/webp'] );
    3709                 wp_update_attachment_metadata( self::$large_id, $metadata );
    3710 
    3711                 foreach ( $metadata['sizes'] as $size => $properties ) {
    3712                         // Some sizes may not have WebP if the WebP file is larger than the JPEG for the size.
    3713                         if ( ! isset( $properties['sources']['image/webp'] ) ) {
    3714                                 continue;
    3715                         }
    3716                         $expected_tag = str_replace( $properties['sources']['image/jpeg']['file'], $properties['sources']['image/webp']['file'], $expected_tag );
    3717                 }
    3718 
    3719                 $this->assertNotSame( $tag, $expected_tag );
    3720                 $this->assertSame( $expected_tag, wp_image_use_alternate_mime_types( $tag, 'the_content', self::$large_id ) );
    3721         }
    3722 
    3723         /**
    3724          * @ticket 55443
    3725          */
    3726         public function test_wp_image_use_alternate_mime_types_respects_wp_content_image_mimes_filter() {
    3727                 if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
    3728                         $this->markTestSkipped( 'This test requires WebP support.' );
    3729                 }
    3730 
    3731                 // The attachment $large_id is a JPEG image, so it gets WebP files generated by default.
    3732                 $tag = wp_get_attachment_image( self::$large_id, 'full' );
    3733 
    3734                 // Invalid filter value results in no changes to content.
    3735                 add_filter( 'wp_content_image_mimes', '__return_false' );
    3736                 $this->assertSame( $tag, wp_image_use_alternate_mime_types( $tag, 'the_content', self::$large_id ) );
    3737 
    3738                 // Empty array results in no changes to content.
    3739                 add_filter( 'wp_content_image_mimes', '__return_empty_array' );
    3740                 $this->assertSame( $tag, wp_image_use_alternate_mime_types( $tag, 'the_content', self::$large_id ) );
    3741 
    3742                 // Preferring JPEG over WebP results in no changes to content.
    3743                 add_filter(
    3744                         'wp_content_image_mimes',
    3745                         function() {
    3746                                 return array( 'image/jpeg', 'image/webp' );
    3747                         }
    3748                 );
    3749                 $this->assertSame( $tag, wp_image_use_alternate_mime_types( $tag, 'the_content', self::$large_id ) );
    3750         }
    3751 
    3752         /**
    3753          * @ticket 55443
    3754          */
    3755         public function test__wp_in_front_end_context_without_wp_query() {
    3756                 unset( $GLOBALS['wp_query'] );
    3757 
    3758                 $this->assertFalse( _wp_in_front_end_context() );
    3759         }
    3760 
    3761         /**
    3762          * @ticket 55443
    3763          */
    3764         public function test__wp_in_front_end_context_with_feed() {
    3765                 remove_all_actions( 'template_redirect' );
    3766                 do_action( 'template_redirect' );
    3767                 $GLOBALS['wp_query']->is_feed = true;
    3768 
    3769                 $this->assertFalse( _wp_in_front_end_context() );
    3770         }
    3771 
    3772         /**
    3773          * @ticket 55443
    3774          */
    3775         public function test__wp_in_front_end_context_before_and_after_template_redirect() {
    3776                 $result = _wp_in_front_end_context();
    3777 
    3778                 remove_all_actions( 'template_redirect' );
    3779                 do_action( 'template_redirect' );
    3780 
    3781                 $this->assertFalse( $result );
    3782                 $this->assertTrue( _wp_in_front_end_context() );
    3783         }
    3784 
    3785         /**
    3786          * @ticket 55443
    3787          */
    3788         public function test__wp_in_front_end_context_within_wp_head() {
    3789                 remove_all_actions( 'template_redirect' );
    3790                 do_action( 'template_redirect' );
    3791 
    3792                 // Call function within a 'wp_head' callback.
    3793                 remove_all_actions( 'wp_head' );
    3794                 $result = null;
    3795                 add_action(
    3796                         'wp_head',
    3797                         function() use ( &$result ) {
    3798                                 $result = _wp_in_front_end_context();
    3799                         }
    3800                 );
    3801                 do_action( 'wp_head' );
    3802 
    3803                 $this->assertFalse( $result );
    3804         }
    38053620}
    38063621
Note: See TracChangeset for help on using the changeset viewer.