<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[37034] trunk: Responsive Images: the `src` of the image has to be first in the `srcset`, because of a bug in iOS8.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/37034">37034</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/37034","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-03-18 19:44:50 +0000 (Fri, 18 Mar 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Responsive Images: the `src` of the image has to be first in the `srcset`, because of a bug in iOS8. Update the unit tests to reflect the changes.
Props jaspermdegroot, joemcgill, azaozz.
Fixes <a href="https://core.trac.wordpress.org/ticket/35030">#35030</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
<li><a href="#trunktestsphpunittestsmediaphp">trunk/tests/phpunit/tests/media.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/media.php 2016-03-18 17:00:40 UTC (rev 37033)
+++ trunk/src/wp-includes/media.php 2016-03-18 19:44:50 UTC (rev 37034)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1067,6 +1067,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * versions of the same edit.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $image_sizes as $image ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $is_src = false;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Check if image meta isn't corrupted.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_array( $image ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1075,7 +1076,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If the file name is part of the `src`, we've confirmed a match.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $src_matched = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $src_matched = $is_src = true;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Filter out images that are from previous edits.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1087,9 +1088,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Filter out images that are wider than '$max_srcset_image_width' unless
</span><span class="cx" style="display: block; padding: 0 10px"> * that file is in the 'src' attribute.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width &&
- false === strpos( $image_src, $image['file'] ) ) {
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width && ! $is_src ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1109,11 +1108,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // If the image dimensions are within 1px of the expected size, use it.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Add the URL, descriptor, and value to the sources array to be returned.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sources[ $image['width'] ] = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $source = array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'url' => $image_baseurl . $image['file'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'descriptor' => 'w',
</span><span class="cx" style="display: block; padding: 0 10px"> 'value' => $image['width'],
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // The 'src' image has to be the first in the 'srcset', because of a bug in iOS8. See #35030.
+ if ( $is_src ) {
+ $sources = array( $image['width'] => $source ) + $sources;
+ } else {
+ $sources[ $image['width'] ] = $source;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/media.php 2016-03-18 17:00:40 UTC (rev 37033)
+++ trunk/tests/phpunit/tests/media.php 2016-03-18 19:44:50 UTC (rev 37034)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -833,24 +833,36 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Helper function to get image size array from size "name"
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function _get_image_size_array_from_name( $size_name ) {
- switch ( $size_name ) {
- case 'thumbnail':
- return array( 150, 150 );
- case 'medium':
- return array( 300, 225 );
- case 'medium_large':
- return array( 768, 576 );
- case 'large':
- return array( 1024, 768 );
- case 'full':
- return array( 1600, 1200 ); // actual size of ../data/images/test-image-large.png
- default:
- return array( 800, 600 ); // soft-resized image
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function _get_image_size_array_from_meta( $image_meta, $size_name ) {
+ $array = false;
+
+ if ( is_array( $image_meta ) ) {
+ if ( 'full' === $size_name && isset( $image_meta['width'] ) && isset( $image_meta['height'] ) ) {
+ $array = array( $image_meta['width'], $image_meta['height'] );
+ } elseif ( isset( $image_meta['sizes'][ $size_name ]['width'] ) && isset( $image_meta['sizes'][ $size_name ]['height'] ) ) {
+ $array = array( $image_meta['sizes'][ $size_name ]['width'], $image_meta['sizes'][ $size_name ]['height'] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ return $array;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Helper function to move the src image to the first position in the expected srcset string.
+ */
+ function _src_first( $srcset, $src_url, $src_width ) {
+ $src_string = $src_url . ' ' . $src_width . 'w';
+ $src_not_first = ', ' . $src_string;
+
+ if ( strpos( $srcset, $src_not_first ) ) {
+ $srcset = str_replace( $src_not_first, '', $srcset );
+ $srcset = $src_string . ', ' . $srcset;
+ }
+
+ return $srcset;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 33641
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_wp_calculate_image_srcset() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -870,9 +882,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expected = "";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected = '';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach( $image_meta['sizes'] as $name => $size ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $image_meta['sizes'] as $name => $size ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( in_array( $name, $intermediates ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $expected .= $uploads_dir_url . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -884,9 +896,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $intermediates as $int ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $image_url = wp_get_attachment_image_url( self::$large_id, $int );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $size_array = $this->_get_image_size_array_from_name( $int );
- $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int );
+ $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] );
+ $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -914,9 +927,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expected = "";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected = '';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach( $image_meta['sizes'] as $name => $size ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $image_meta['sizes'] as $name => $size ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( in_array( $name, $intermediates ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $expected .= $uploads_dir_url . $size['file'] . ' ' . $size['width'] . 'w, ';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -927,10 +940,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $intermediates as $int ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $size_array = $this->_get_image_size_array_from_name( $int );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int );
</ins><span class="cx" style="display: block; padding: 0 10px"> $image_url = wp_get_attachment_image_url( $id, $int );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] );
+ $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Remove the attachment
</span><span class="cx" style="display: block; padding: 0 10px"> wp_delete_attachment( $id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -945,7 +959,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Start by getting the attachment metadata.
</span><span class="cx" style="display: block; padding: 0 10px"> $image_meta = wp_get_attachment_metadata( self::$large_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $image_url = wp_get_attachment_image_url( self::$large_id, 'medium' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $size_array = $this->_get_image_size_array_from_name( 'medium' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Copy hash generation method used in wp_save_image().
</span><span class="cx" style="display: block; padding: 0 10px"> $hash = 'e' . time() . rand(100, 999);
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1007,9 +1021,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $intermediates as $int ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $image_url = wp_get_attachment_image_url( self::$large_id, $int );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $size_array = $this->_get_image_size_array_from_name( $int );
- $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int );
+ $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] );
+ $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1123,7 +1138,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expected_srcset = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 2000w';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected_srcset = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 2000w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1226,7 +1241,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = "";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach( $image_meta['sizes'] as $name => $size ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $image_meta['sizes'] as $name => $size ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( in_array( $name, $intermediates ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $expected .= $uploads_dir . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1235,7 +1250,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected .= $uploads_dir . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( $expected, $srcset );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected_srcset = $this->_src_first( $expected, $uploads_dir . $image_meta['file'], $size_array[0] );
+
+ $this->assertSame( $expected_srcset, $srcset );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1273,14 +1290,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 33641
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_wp_get_attachment_image_sizes() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Test sizes against the default WP sizes.
- $intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Test sizes against the default WP sizes.
+ $intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make sure themes aren't filtering the sizes array.
</span><span class="cx" style="display: block; padding: 0 10px"> remove_all_filters( 'wp_calculate_image_sizes' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach( $intermediates as $int_size ) {
- $image = wp_get_attachment_image_src( self::$large_id, $int_size );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach( $intermediates as $int_size ) {
+ $image = wp_get_attachment_image_src( self::$large_id, $int_size );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '(max-width: ' . $image[1] . 'px) 100vw, ' . $image[1] . 'px';
</span><span class="cx" style="display: block; padding: 0 10px"> $sizes = wp_get_attachment_image_sizes( self::$large_id, $int_size );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1294,15 +1311,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_wp_calculate_image_sizes() {
</span><span class="cx" style="display: block; padding: 0 10px"> // Test sizes against the default WP sizes.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
- $image_meta = wp_get_attachment_metadata( self::$large_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $intermediates = array( 'thumbnail', 'medium', 'medium_large', 'large' );
+ $image_meta = wp_get_attachment_metadata( self::$large_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make sure themes aren't filtering the sizes array.
</span><span class="cx" style="display: block; padding: 0 10px"> remove_all_filters( 'wp_calculate_image_sizes' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach( $intermediates as $int_size ) {
- $size_array = $this->_get_image_size_array_from_name( $int_size );
- $image_src = $image_meta['sizes'][$int_size]['file'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $intermediates as $int_size ) {
+ $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int_size );
+ $image_src = $image_meta['sizes'][ $int_size ]['file'];
</ins><span class="cx" style="display: block; padding: 0 10px"> list( $width, $height ) = $size_array;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '(max-width: ' . $width . 'px) 100vw, ' . $width . 'px';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1317,7 +1334,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_wp_make_content_images_responsive() {
</span><span class="cx" style="display: block; padding: 0 10px"> $image_meta = wp_get_attachment_metadata( self::$large_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $size_array = $this->_get_image_size_array_from_name( 'medium' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1450,7 +1467,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_wp_make_content_images_responsive_schemes() {
</span><span class="cx" style="display: block; padding: 0 10px"> $image_meta = wp_get_attachment_metadata( self::$large_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $size_array = $this->_get_image_size_array_from_name( 'medium' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1480,7 +1497,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $actual = wp_make_content_images_responsive( $unfiltered );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected, $actual );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 34945
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1517,7 +1534,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $_SERVER['HTTPS'] = 'on';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expected = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-300x150.jpg 300w, https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-1024x512.jpg 1024w, https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg 1200w';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-1024x512.jpg 1024w, https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-300x150.jpg 300w, https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg 1200w';
</ins><span class="cx" style="display: block; padding: 0 10px"> $actual = wp_calculate_image_srcset( $size_array, $image_url, $image_meta );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected, $actual );
</span></span></pre>
</div>
</div>
</body>
</html>