Make WordPress Core


Ignore:
Timestamp:
12/30/2015 01:03:11 AM (9 years ago)
Author:
azaozz
Message:

Responsive images: fix the check whether the attachment meta matches the image src to work with http/https and CDNs.

Props webaware, joemcgill, azaozz.
Fixes #35045 and #35102 for trunk.

File:
1 edited

Legend:

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

    r36120 r36121  
    12661266        $this->assertFalse( strpos( wp_calculate_image_srcset( $size_array, $large_src, $image_meta ), $full_src ) );
    12671267    }
     1268
     1269    /**
     1270     * @ticket 35045
     1271     * @ticket 33641
     1272     */
     1273    function test_wp_make_content_images_responsive_schemes() {
     1274        $image_meta = wp_get_attachment_metadata( self::$large_id );
     1275        $size_array = $this->_get_image_size_array_from_name( 'medium' );
     1276
     1277        $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) );
     1278        $sizes  = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) );
     1279
     1280        // Build HTML for the editor.
     1281        $img          = get_image_tag( self::$large_id, '', '', '', 'medium' );
     1282        $img_https    = str_replace( 'http://', 'https://', $img );
     1283        $img_relative = str_replace( 'http://', '//', $img );
     1284
     1285        // Manually add srcset and sizes to the markup from get_image_tag().
     1286        $respimg          = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img );
     1287        $respimg_https    = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_https );
     1288        $respimg_relative = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_relative );
     1289
     1290        $content = '
     1291            <p>Image, http: protocol. Should have srcset and sizes.</p>
     1292            %1$s
     1293
     1294            <p>Image, https: protocol. Should have srcset and sizes.</p>
     1295            %2$s
     1296
     1297            <p>Image, protocol-relative. Should have srcset and sizes.</p>
     1298            %3$s';
     1299
     1300        $unfiltered = sprintf( $content, $img, $img_https, $img_relative );
     1301        $expected   = sprintf( $content, $respimg, $respimg_https, $respimg_relative );
     1302        $actual     = wp_make_content_images_responsive( $unfiltered );
     1303
     1304        $this->assertSame( $expected, $actual );
     1305    }
    12681306}
Note: See TracChangeset for help on using the changeset viewer.