Make WordPress Core


Ignore:
Timestamp:
09/25/2023 10:37:00 PM (3 years ago)
Author:
flixos90
Message:

Media: Rely on wp_get_loading_optimization_attributes() to add decoding="async" to images.

The wp_get_loading_optimization_attributes() function was introduced in 6.3, as a single centralized place to control loading optimization attributes for various tags, most importantly images.

This changeset consolidates the decoding="async" optimization, which was added in 6.1, to occur solely as part of wp_get_loading_optimization_attributes(), removing duplicate code and allowing centralized filtering based on [56651].

As part of the change, the wp_img_tag_add_decoding_attr() function has been deprecated. The filter of the same name continues to be maintained for backward compatibility, as before covering only images that are part of a content blob such as post content (the_content).

Props pereirinha, mukesh27, joemcgill, flixos90.
Fixes #58892.
See #53232.

File:
1 edited

Legend:

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

    r56680 r56690  
    22642264                        $respimg_html5
    22652265                );
    2266                 $content_filtered = wp_img_tag_add_decoding_attr( $content_filtered, 'the_content' );
    22672266
    22682267                // Do not add width, height, and loading.
    22692268                add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
    22702269                add_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
     2270                add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    22712271
    22722272                $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) );
     
    22742274                remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
    22752275                remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
     2276                remove_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    22762277        }
    22772278
     
    22902291                $img = get_image_tag( self::$large_id, '', '', '', 'medium' );
    22912292                $img = wp_img_tag_add_loading_optimization_attrs( $img, 'test' );
    2292                 $img = wp_img_tag_add_decoding_attr( $img, 'the_content' );
    22932293
    22942294                // Replace the src URL.
     
    23052305                $img = get_image_tag( self::$large_id, '', '', '', 'medium' );
    23062306                $img = wp_img_tag_add_loading_optimization_attrs( $img, 'test' );
    2307                 $img = wp_img_tag_add_decoding_attr( $img, 'the_content' );
    23082307                $img = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $img );
    23092308
     
    24812480                        $respimg_relative
    24822481                );
    2483                 $expected = wp_img_tag_add_decoding_attr( $expected, 'the_content' );
    24842482
    24852483                $actual = wp_filter_content_tags( $unfiltered );
     
    29742972                        $img_no_height
    29752973                );
    2976                 $content_filtered = wp_img_tag_add_decoding_attr( $content_filtered, 'the_content' );
    29772974
    29782975                // Do not add loading, srcset, and sizes.
    29792976                add_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
    29802977                add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
     2978                add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    29812979
    29822980                $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) );
     
    29842982                remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
    29852983                remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
     2984                remove_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    29862985        }
    29872986
     
    30043003                $iframe                 = '<iframe src="https://www.example.com" width="640" height="360"></iframe>';
    30053004                $iframe_no_width_height = '<iframe src="https://www.example.com"></iframe>';
     3005
     3006                add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    30063007
    30073008                $lazy_img       = wp_img_tag_add_loading_optimization_attrs( $img, 'test' );
     
    30553056                        $iframe_no_width_height
    30563057                );
    3057                 $content_filtered = wp_img_tag_add_decoding_attr( $content_filtered, 'the_content' );
    30583058
    30593059                // Do not add width, height, srcset, and sizes.
     
    30653065                remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' );
    30663066                remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
     3067                remove_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    30673068        }
    30683069
     
    30753076                $img         = get_image_tag( self::$large_id, '', '', '', 'medium' );
    30763077                $lazy_img    = wp_img_tag_add_loading_optimization_attrs( $img, 'test' );
    3077                 $lazy_img    = wp_img_tag_add_decoding_attr( $lazy_img, 'the_content' );
    30783078                $iframe      = '<iframe src="https://www.example.com" width="640" height="360"></iframe>';
    30793079                $lazy_iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' );
     
    31053105        public function test_wp_filter_content_tags_loading_lazy_opted_out() {
    31063106                $img    = get_image_tag( self::$large_id, '', '', '', 'medium' );
    3107                 $img    = wp_img_tag_add_decoding_attr( $img, 'the_content' );
    31083107                $iframe = '<iframe src="https://www.example.com" width="640" height="360"></iframe>';
    31093108
     
    31203119                // Disable globally for all tags.
    31213120                add_filter( 'wp_lazy_loading_enabled', '__return_false' );
     3121                add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    31223122
    31233123                $this->assertSame( $content, wp_filter_content_tags( $content ) );
    31243124                remove_filter( 'wp_lazy_loading_enabled', '__return_false' );
    31253125                remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
     3126                remove_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    31263127        }
    31273128
     
    31873188         *
    31883189         * @ticket 56969
     3190         *
     3191         * @expectedDeprecated wp_img_tag_add_decoding_attr
    31893192         */
    31903193        public function test_wp_img_tag_add_decoding_attr_with_single_quotes() {
     
    34363439                        'false'       => array(
    34373440                                'decoding' => false,
    3438                                 'expected' => 'no value',
    3439                         ),
    3440                         'null'        => array(
    3441                                 'decoding' => null,
    34423441                                'expected' => 'no value',
    34433442                        ),
     
    37203719         * @ticket 53675
    37213720         * @ticket 58235
     3721         * @ticket 58892
    37223722         */
    37233723        public function test_wp_omit_loading_attr_threshold_filter() {
     
    37393739                        // Due to the filter, now the first five elements should not be lazy-loaded, i.e. return `false`.
    37403740                        for ( $i = 0; $i < 5; $i++ ) {
    3741                                 $this->assertEmpty(
     3741                                $this->assertSameSetsWithIndex(
     3742                                        array(
     3743                                                'decoding' => 'async',
     3744                                        ),
    37423745                                        wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
    37433746                                        'Expected second image to not be lazy-loaded.'
     
    37463749
    37473750                        // For following elements, lazy-load them again.
    3748                         $this->assertSame(
    3749                                 array( 'loading' => 'lazy' ),
     3751                        $this->assertSameSetsWithIndex(
     3752                                array(
     3753                                        'decoding' => 'async',
     3754                                        'loading'  => 'lazy',
     3755                                ),
    37503756                                wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' )
    37513757                        );
     
    37623768         */
    37633769        public function test_wp_filter_content_tags_with_loading_optimization_attrs() {
     3770                add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    37643771                $img1         = get_image_tag( self::$large_id, '', '', '', 'large' );
    37653772                $iframe1      = '<iframe src="https://www.example.com" width="640" height="360"></iframe>';
     
    37783785                $content_unfiltered = $img1 . $iframe1 . $img2 . $img3 . $iframe2;
    37793786                $content_expected   = $prio_img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2;
    3780                 $content_expected   = wp_img_tag_add_decoding_attr( $content_expected, 'the_content' );
    37813787
    37823788                $query = $this->get_new_wp_query_for_published_post();
     
    37903796                        remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' );
    37913797                }
     3798                remove_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
    37923799
    37933800                // After filtering, the first image should not be lazy-loaded while the other ones should be.
     
    41294136         * @ticket 58089
    41304137         * @ticket 58235
     4138         * @ticket 58892
    41314139         *
    41324140         * @covers ::wp_filter_content_tags
     
    41444152                                'loading'       => false,
    41454153                                'fetchpriority' => false,
     4154                                'decoding'      => false,
    41464155                        )
    41474156                );
     
    41824191
    41834192                // Ensure that parsed content has the image with fetchpriority as it is the first large image.
    4184                 $expected_content = wpautop( str_replace( '<img ', '<img fetchpriority="high" ', $expected_image ) );
     4193                $expected_content = wpautop( str_replace( '<img ', '<img fetchpriority="high" decoding="async" ', $expected_image ) );
    41854194                $this->assertSame( $expected_content, $content, 'Post content with programmatically injected image is missing loading optimization attributes' );
    41864195        }
     
    42624271         * @ticket 56930
    42634272         * @ticket 58235
     4273         * @ticket 58892
    42644274         *
    42654275         * @covers ::wp_get_loading_optimization_attributes
     
    42734283
    42744284                // Return 'lazy' by default.
    4275                 $this->assertSame(
    4276                         array( 'loading' => 'lazy' ),
     4285                $this->assertSameSetsWithIndex(
     4286                        array(
     4287                                'decoding' => 'async',
     4288                                'loading'  => 'lazy',
     4289                        ),
    42774290                        wp_get_loading_optimization_attributes( 'img', $attr, 'test' )
    42784291                );
    4279                 $this->assertSame(
    4280                         array( 'loading' => 'lazy' ),
     4292                $this->assertSameSetsWithIndex(
     4293                        array(
     4294                                'decoding' => 'async',
     4295                                'loading'  => 'lazy',
     4296                        ),
    42814297                        wp_get_loading_optimization_attributes( 'img', $attr, 'wp_get_attachment_image' )
    42824298                );
    42834299
    42844300                // Return 'lazy' if not in the loop or the main query.
    4285                 $this->assertSame(
    4286                         array( 'loading' => 'lazy' ),
     4301                $this->assertSameSetsWithIndex(
     4302                        array(
     4303                                'decoding' => 'async',
     4304                                'loading'  => 'lazy',
     4305                        ),
    42874306                        wp_get_loading_optimization_attributes( 'img', $attr, $context )
    42884307                );
     
    42944313
    42954314                        // Return 'lazy' if in the loop but not in the main query.
    4296                         $this->assertSame(
    4297                                 array( 'loading' => 'lazy' ),
     4315                        $this->assertSameSetsWithIndex(
     4316                                array(
     4317                                        'decoding' => 'async',
     4318                                        'loading'  => 'lazy',
     4319                                ),
    42984320                                wp_get_loading_optimization_attributes( 'img', $attr, $context )
    42994321                        );
     
    43034325
    43044326                        // First three element are not lazy loaded. However, first image is loaded with fetchpriority high.
    4305                         $this->assertSame(
    4306                                 array( 'fetchpriority' => 'high' ),
     4327                        $this->assertSameSetsWithIndex(
     4328                                array(
     4329                                        'decoding'      => 'async',
     4330                                        'fetchpriority' => 'high',
     4331                                ),
    43074332                                wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    43084333                                "Expected first image to not be lazy-loaded. First large image get's high fetchpriority."
    43094334                        );
    4310                         $this->assertEmpty(
     4335                        $this->assertSameSetsWithIndex(
     4336                                array(
     4337                                        'decoding' => 'async',
     4338                                ),
    43114339                                wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    43124340                                'Expected second image to not be lazy-loaded.'
    43134341                        );
    4314                         $this->assertEmpty(
     4342                        $this->assertSameSetsWithIndex(
     4343                                array(
     4344                                        'decoding' => 'async',
     4345                                ),
    43154346                                wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    43164347                                'Expected third image to not be lazy-loaded.'
     
    43184349
    43194350                        // Return 'lazy' if in the loop and in the main query for any subsequent elements.
    4320                         $this->assertSame(
    4321                                 array( 'loading' => 'lazy' ),
     4351                        $this->assertSameSetsWithIndex(
     4352                                array(
     4353                                        'decoding' => 'async',
     4354                                        'loading'  => 'lazy',
     4355                                ),
    43224356                                wp_get_loading_optimization_attributes( 'img', $attr, $context )
    43234357                        );
    43244358
    43254359                        // Yes, for all subsequent elements.
    4326                         $this->assertSame(
    4327                                 array( 'loading' => 'lazy' ),
     4360                        $this->assertSameSetsWithIndex(
     4361                                array(
     4362                                        'decoding' => 'async',
     4363                                        'loading'  => 'lazy',
     4364                                ),
    43284365                                wp_get_loading_optimization_attributes( 'img', $attr, $context )
    43294366                        );
     
    43454382                $attr = $this->get_width_height_for_high_priority();
    43464383
    4347                 $this->assertSame(
    4348                         array( 'loading' => 'lazy' ),
     4384                $this->assertSameSetsWithIndex(
     4385                        array(
     4386                                'decoding' => 'async',
     4387                                'loading'  => 'lazy',
     4388                        ),
    43494389                        wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    43504390                        'The "loading" attribute should be "lazy" when not in the loop or the main query.'
     
    43594399                        the_post();
    43604400
    4361                         $this->assertSame(
    4362                                 array( 'fetchpriority' => 'high' ),
     4401                        $this->assertSameSetsWithIndex(
     4402                                array(
     4403                                        'decoding'      => 'async',
     4404                                        'fetchpriority' => 'high',
     4405                                ),
    43634406                                wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    43644407                                'The "fetchpriority" attribute should be "high" while in the loop and the main query.'
     
    43894432                $this->set_main_query( $query );
    43904433
    4391                 $this->assertSame(
    4392                         array( 'loading' => 'lazy' ),
     4434                $this->assertSameSetsWithIndex(
     4435                        array(
     4436                                'decoding' => 'async',
     4437                                'loading'  => 'lazy',
     4438                        ),
    43934439                        wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    43944440                        'The "loading" attribute should be "lazy" before the main query loop.'
     
    43984444                        the_post();
    43994445
    4400                         $this->assertSame(
    4401                                 array( 'fetchpriority' => 'high' ),
     4446                        $this->assertSameSetsWithIndex(
     4447                                array(
     4448                                        'decoding'      => 'async',
     4449                                        'fetchpriority' => 'high',
     4450                                ),
    44024451                                wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    44034452                                'The "fetchpriority" attribute should be "high" while in the loop and the main query.'
     
    44684517                add_filter( 'wp_loading_optimization_force_header_contexts', '__return_empty_array' );
    44694518
    4470                 $this->assertSame(
    4471                         array( 'loading' => 'lazy' ),
     4519                $this->assertSameSetsWithIndex(
     4520                        array(
     4521                                'decoding' => 'async',
     4522                                'loading'  => 'lazy',
     4523                        ),
    44724524                        wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    44734525                        'Images in the header context should get lazy-loaded after the wp_loading_optimization_force_header_contexts filter.'
     
    45034555                );
    45044556
    4505                 $this->assertSame(
    4506                         array( 'fetchpriority' => 'high' ),
     4557                $this->assertSameSetsWithIndex(
     4558                        array(
     4559                                'decoding'      => 'async',
     4560                                'fetchpriority' => 'high',
     4561                        ),
    45074562                        wp_get_loading_optimization_attributes( 'img', $attr, 'something_completely_arbitrary' )
    45084563                );
     
    45144569         * @ticket 58211
    45154570         * @ticket 58235
     4571         * @ticket 58892
    45164572         *
    45174573         * @covers ::wp_get_loading_optimization_attributes
     
    45314587
    45324588                // Lazy if not main query.
    4533                 $this->assertSame(
    4534                         array( 'loading' => 'lazy' ),
     4589                $this->assertSameSetsWithIndex(
     4590                        array(
     4591                                'decoding' => 'async',
     4592                                'loading'  => 'lazy',
     4593                        ),
    45354594                        wp_get_loading_optimization_attributes( 'img', $attr, $context )
    45364595                );
     
    45424601         * @ticket 58211
    45434602         * @ticket 58235
     4603         * @ticket 58892
    45444604         *
    45454605         * @covers ::wp_get_loading_optimization_attributes
     
    45584618
    45594619                // Lazy if header not called.
    4560                 $this->assertSame(
    4561                         array( 'loading' => 'lazy' ),
     4620                $this->assertSameSetsWithIndex(
     4621                        array(
     4622                                'decoding' => 'async',
     4623                                'loading'  => 'lazy',
     4624                        ),
    45624625                        wp_get_loading_optimization_attributes( 'img', $attr, $context )
    45634626                );
     
    45864649
    45874650                // First image is loaded with high fetchpriority.
    4588                 $this->assertSame(
    4589                         array( 'fetchpriority' => 'high' ),
     4651                $this->assertSameSetsWithIndex(
     4652                        array(
     4653                                'decoding'      => 'async',
     4654                                'fetchpriority' => 'high',
     4655                        ),
    45904656                        wp_get_loading_optimization_attributes( 'img', $attr, $context ),
    45914657                        'Expected first image to not be lazy-loaded. First large image is loaded with high fetchpriority.'
     
    45984664         * @ticket 58211
    45994665         * @ticket 58235
     4666         * @ticket 58892
    46004667         *
    46014668         * @covers ::wp_get_loading_optimization_attributes
     
    46184685
    46194686                $attr = $this->get_width_height_for_high_priority();
    4620                 $this->assertSame(
    4621                         array( 'loading' => 'lazy' ),
     4687                $this->assertSameSetsWithIndex(
     4688                        array(
     4689                                'decoding' => 'async',
     4690                                'loading'  => 'lazy',
     4691                        ),
    46224692                        wp_get_loading_optimization_attributes( 'img', $attr, $context )
    46234693                );
     
    46294699         * @ticket 58211
    46304700         * @ticket 58235
     4701         * @ticket 58892
    46314702         *
    46324703         * @covers ::wp_get_loading_optimization_attributes
     
    46494720
    46504721                // Load lazy if the there is no loop and footer was called.
    4651                 $this->assertSame(
    4652                         array( 'loading' => 'lazy' ),
     4722                $this->assertSameSetsWithIndex(
     4723                        array(
     4724                                'decoding' => 'async',
     4725                                'loading'  => 'lazy',
     4726                        ),
    46534727                        wp_get_loading_optimization_attributes( 'img', $attr, $context )
    46544728                );
     
    46604734         * @ticket 58089
    46614735         * @ticket 58235
     4736         * @ticket 58892
    46624737         *
    46634738         * @covers ::wp_get_loading_optimization_attributes
     
    46694744        public function test_wp_get_loading_optimization_attributes_should_return_lazy_for_special_contexts_outside_of_the_content( $context ) {
    46704745                $attr = $this->get_width_height_for_high_priority();
    4671                 $this->assertSame(
    4672                         array( 'loading' => 'lazy' ),
     4746                $this->assertSameSetsWithIndex(
     4747                        array(
     4748                                'decoding' => 'async',
     4749                                'loading'  => 'lazy',
     4750                        ),
    46734751                        wp_get_loading_optimization_attributes( 'img', $attr, $context )
    46744752                );
     
    47054783
    47064784        /**
     4785         * Tests to cover the decoding attribute within wp_get_loading_optimization_attributes().
     4786         *
     4787         * @ticket 58892
     4788         *
     4789         * @covers ::wp_get_loading_optimization_attributes
     4790         */
     4791        public function test_wp_get_loading_optimization_attributes_decoding_attribute() {
     4792
     4793                $this->assertSameSetsWithIndex(
     4794                        array(
     4795                                'decoding' => 'async',
     4796                        ),
     4797                        wp_get_loading_optimization_attributes( 'img', array(), 'the_content' ),
     4798                        'Expected decoding attribute to be async.'
     4799                );
     4800
     4801                $this->assertSameSetsWithIndex(
     4802                        array(
     4803                                'decoding' => 'auto',
     4804                        ),
     4805                        wp_get_loading_optimization_attributes( 'img', array( 'decoding' => 'auto' ), 'the_content' ),
     4806                        'Expected decoding attribute to be auto.'
     4807                );
     4808
     4809                $result = null;
     4810                add_filter(
     4811                        'the_content',
     4812                        static function ( $content ) use ( &$result ) {
     4813                                $result = wp_get_loading_optimization_attributes( 'img', array(), 'something_completely_arbitrary' );
     4814                                return $content;
     4815                        }
     4816                );
     4817                apply_filters( 'the_content', '' );
     4818
     4819                $this->assertSameSetsWithIndex(
     4820                        array(),
     4821                        $result,
     4822                        'Expected decoding attribute to be empty for img on arbitrary context, while running the_content.'
     4823                );
     4824
     4825                $this->assertSameSetsWithIndex(
     4826                        array(),
     4827                        wp_get_loading_optimization_attributes( 'iframe', array(), 'the_content' ),
     4828                        'Expected decoding attribute to be empty for iframe.'
     4829                );
     4830        }
     4831
     4832        /**
    47074833         * @ticket 44427
    47084834         * @ticket 50367
     
    48104936                        array(
    48114937                                'loading'       => false,
     4938                                'decoding'      => 'async',
    48124939                                'fetchpriority' => 'high',
    48134940                        )
     
    50165143                                        'height' => 100,
    50175144                                ),
    5018                                 array( 'loading' => 'lazy' ),
    5019                                 'Expected default `loading="lazy"`.',
     5145                                array(
     5146                                        'decoding' => 'async',
     5147                                        'loading'  => 'lazy',
     5148                                ),
     5149                                'Expected default `decoding="async"` and `loading="lazy"`.',
    50205150                        ),
    50215151                        'img_without_height' => array(
    50225152                                'img',
    50235153                                array( 'width' => 100 ),
    5024                                 array(),
    5025                                 'Expected blank array as height is required.',
     5154                                array(
     5155                                        'decoding' => 'async',
     5156                                ),
     5157                                'Only `decoding` is set as height is required for `loading` attribute.',
    50265158                        ),
    50275159                        'img_without_width'  => array(
    50285160                                'img',
    50295161                                array( 'height' => 100 ),
    5030                                 array(),
    5031                                 'Expected blank array as width is required.',
     5162                                array(
     5163                                        'decoding' => 'async',
     5164                                ),
     5165                                'Only `decoding` is set as width is required for `loading` attribute.',
    50325166                        ),
    50335167                );
     
    50625196                        'img'    => array(
    50635197                                'img',
    5064                                 array( 'loading' => 'lazy' ),
    5065                                 'Expected `loading="lazy"` for the img.',
     5198                                array(
     5199                                        'decoding' => 'async',
     5200                                        'loading'  => 'lazy',
     5201                                ),
     5202                                'Expected `decoding="async"` and `loading="lazy"` and `decoding="async"` for the img.',
    50665203                        ),
    50675204                        'iframe' => array(
     
    51065243
    51075244                // Skip logic if context is `template`.
    5108                 $this->assertSame(
    5109                         array( 'fetchpriority' => 'high' ),
     5245                $this->assertSameSetsWithIndex(
     5246                        array(
     5247                                'decoding'      => 'async',
     5248                                'fetchpriority' => 'high',
     5249                        ),
    51105250                        wp_get_loading_optimization_attributes( 'img', $attr, 'template_part_' . WP_TEMPLATE_PART_AREA_HEADER ),
    51115251                        'Images in the header block template part should not be lazy-loaded and first large image is set high fetchpriority.'
     
    51155255        /**
    51165256         * @ticket 58235
     5257         * @ticket 58892
    51175258         *
    51185259         * @covers ::wp_get_loading_optimization_attributes
     
    51265267                $this->assertEqualSetsWithIndex(
    51275268                        array(
     5269                                'decoding'      => 'async',
    51285270                                'loading'       => 'lazy',
    51295271                                'fetchpriority' => 'high',
     
    51445286
    51455287                // Check fetchpriority high logic if loading attribute is present.
    5146                 $this->assertSame(
    5147                         array(
     5288                $this->assertSameSetsWithIndex(
     5289                        array(
     5290                                'decoding'      => 'async',
    51485291                                'fetchpriority' => 'high',
    51495292                        ),
     
    51675310                // fetchpriority not set as image is of lower resolution.
    51685311                $this->assertSame(
    5169                         array(),
     5312                        array(
     5313                                'decoding' => 'async',
     5314                        ),
    51705315                        wp_get_loading_optimization_attributes( 'img', $attr, 'test' ),
    51715316                        'loading optimization attr array should be empty.'
     
    51835328
    51845329                // The first image processed in a shortcode should have fetchpriority set to high.
    5185                 $this->assertSame(
     5330                $this->assertSameSetsWithIndex(
    51865331                        $expected,
    51875332                        wp_get_loading_optimization_attributes( 'img', $attr, 'do_shortcode' ),
     
    52015346                                },
    52025347                                'expected' => array(
     5348                                        'decoding'      => 'async',
    52035349                                        'fetchpriority' => 'high',
    52045350                                ),
     
    52185364                                },
    52195365                                'expected' => array(
    5220                                         'loading' => 'lazy',
     5366                                        'decoding' => 'async',
     5367                                        'loading'  => 'lazy',
    52215368                                ),
    5222                                 'message'  => 'Lazy-loading not applied to during shortcode rendering.',
     5369                                'message'  => 'Lazy-loading or decoding not applied to during shortcode rendering.',
    52235370                        ),
    52245371                        'shortcode_image_outside_of_the_loop_are_loaded_lazy'  => array(
     
    52285375                                },
    52295376                                'expected' => array(
    5230                                         'loading' => 'lazy',
     5377                                        'decoding' => 'async',
     5378                                        'loading'  => 'lazy',
    52315379                                ),
    5232                                 'message'  => 'Lazy-loading not applied to shortcodes outside the loop.',
     5380                                'message'  => 'Lazy-loading or decoding not applied to shortcodes outside the loop.',
    52335381                        ),
    52345382                );
     
    53275475                        ),
    53285476                        'image with loading=lazy'       => array(
    5329                                 array( 'loading' => 'lazy' ),
     5477                                array(
     5478                                        'loading'  => 'lazy',
     5479                                        'decoding' => 'async',
     5480                                ),
    53305481                                'img',
    53315482                                $this->get_width_height_for_high_priority(),
     
    54645615                $attr = $this->get_width_height_for_high_priority();
    54655616
    5466                 $this->assertSame(
     5617                $this->assertSameSetsWithIndex(
    54675618                        array( 'fetchpriority' => 'high' ),
    54685619                        wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
     
    54735624                add_filter( 'pre_wp_get_loading_optimization_attributes', '__return_false' );
    54745625
    5475                 $this->assertSameSets(
    5476                         array( 'loading' => 'lazy' ),
     5626                $this->assertSameSetsWithIndex(
     5627                        array(
     5628                                'decoding' => 'async',
     5629                                'loading'  => 'lazy',
     5630                        ),
    54775631                        wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
    54785632                        'The filter did not return the default attributes.'
     
    54825636                add_filter( 'pre_wp_get_loading_optimization_attributes', '__return_empty_array' );
    54835637
    5484                 $this->assertSameSets(
     5638                $this->assertSameSetsWithIndex(
    54855639                        array(),
    54865640                        wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
     
    55045658                );
    55055659
    5506                 $this->assertSameSets(
     5660                $this->assertSameSetsWithIndex(
    55075661                        array( 'custom_attr' => 'custom_value' ),
    55085662                        wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
     
    55195673                $attr = $this->get_width_height_for_high_priority();
    55205674
    5521                 $this->assertSameSets(
    5522                         array( 'loading' => 'lazy' ),
     5675                $this->assertSameSetsWithIndex(
     5676                        array(
     5677                                'decoding' => 'async',
     5678                                'loading'  => 'lazy',
     5679                        ),
    55235680                        wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
    55245681                        'Before the filter it will not return the loading attribute.'
     
    55375694                );
    55385695
    5539                 $this->assertSameSets(
    5540                         array( 'fetchpriority' => 'high' ),
     5696                $this->assertSameSetsWithIndex(
     5697                        array(
     5698                                'decoding'      => 'async',
     5699                                'fetchpriority' => 'high',
     5700                        ),
    55415701                        wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
    55425702                        'After the filter it will not return the fetchpriority attribute.'
Note: See TracChangeset for help on using the changeset viewer.