mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@36121 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1265,4 +1265,42 @@ EOF;
|
||||
// Intermediate sized GIFs should not include the full size in the srcset.
|
||||
$this->assertFalse( strpos( wp_calculate_image_srcset( $size_array, $large_src, $image_meta ), $full_src ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35045
|
||||
* @ticket 33641
|
||||
*/
|
||||
function test_wp_make_content_images_responsive_schemes() {
|
||||
$image_meta = wp_get_attachment_metadata( self::$large_id );
|
||||
$size_array = $this->_get_image_size_array_from_name( 'medium' );
|
||||
|
||||
$srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) );
|
||||
$sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) );
|
||||
|
||||
// Build HTML for the editor.
|
||||
$img = get_image_tag( self::$large_id, '', '', '', 'medium' );
|
||||
$img_https = str_replace( 'http://', 'https://', $img );
|
||||
$img_relative = str_replace( 'http://', '//', $img );
|
||||
|
||||
// Manually add srcset and sizes to the markup from get_image_tag().
|
||||
$respimg = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img );
|
||||
$respimg_https = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_https );
|
||||
$respimg_relative = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_relative );
|
||||
|
||||
$content = '
|
||||
<p>Image, http: protocol. Should have srcset and sizes.</p>
|
||||
%1$s
|
||||
|
||||
<p>Image, https: protocol. Should have srcset and sizes.</p>
|
||||
%2$s
|
||||
|
||||
<p>Image, protocol-relative. Should have srcset and sizes.</p>
|
||||
%3$s';
|
||||
|
||||
$unfiltered = sprintf( $content, $img, $img_https, $img_relative );
|
||||
$expected = sprintf( $content, $respimg, $respimg_https, $respimg_relative );
|
||||
$actual = wp_make_content_images_responsive( $unfiltered );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user