| 1132 | * @ticket 35480 |
| 1133 | */ |
| 1134 | function test_wp_calculate_image_srcset_corrupted_image_meta() { |
| 1135 | $size_array = array( 300, 150 ); |
| 1136 | $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png'; |
| 1137 | $image_meta = array( |
| 1138 | 'width' => 1600, |
| 1139 | 'height' => 800, |
| 1140 | 'file' => '2015/12/test.png', |
| 1141 | 'sizes' => array( |
| 1142 | 'thumbnail' => array( |
| 1143 | 'file' => 'test-150x150.png', |
| 1144 | 'width' => 150, |
| 1145 | 'height' => 150, |
| 1146 | 'mime-type' => 'image/png', |
| 1147 | ), |
| 1148 | 'medium' => array( |
| 1149 | 'file' => 'test-300x150.png', |
| 1150 | 'width' => 300, |
| 1151 | 'height' => 150, |
| 1152 | 'mime-type' => 'image/png', |
| 1153 | ), |
| 1154 | 'medium_large' => array( |
| 1155 | 'file' => 'test-768x384.png', |
| 1156 | 'width' => 768, |
| 1157 | 'height' => 384, |
| 1158 | 'mime-type' => 'image/png', |
| 1159 | ), |
| 1160 | 'large' => array( |
| 1161 | 'file' => 'test-1024x512.png', |
| 1162 | 'width' => 1024, |
| 1163 | 'height' => 512, |
| 1164 | 'mime-type' => 'image/png', |
| 1165 | ), |
| 1166 | ), |
| 1167 | ); |
| 1168 | |
| 1169 | $srcset = array( |
| 1170 | 300 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w', |
| 1171 | 768 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w', |
| 1172 | 1024 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w', |
| 1173 | 1600 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 1600w', |
| 1174 | ); |
| 1175 | |
| 1176 | // No sizes array |
| 1177 | $image_meta1 = $image_meta; |
| 1178 | unset( $image_meta1['sizes'] ); |
| 1179 | $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta1 ) ); |
| 1180 | |
| 1181 | // Sizes is string instead of array; only full size available means no srcset. |
| 1182 | $image_meta2 = $image_meta; |
| 1183 | $image_meta2['sizes'] = ''; |
| 1184 | $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta2 ) ); |
| 1185 | |
| 1186 | // File name is incorrect |
| 1187 | $image_meta4 = $image_meta; |
| 1188 | $image_meta4['file'] = '/'; |
| 1189 | $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta4 ) ); |
| 1190 | |
| 1191 | // Intermediate size is string instead of array. |
| 1192 | $image_meta3 = $image_meta; |
| 1193 | $image_meta3['sizes']['medium_large'] = ''; |
| 1194 | unset( $srcset[768] ); |
| 1195 | $expected_srcset = implode( ', ', $srcset ); |
| 1196 | $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) ); |
| 1197 | } |
| 1198 | |
| 1199 | /** |