@@ -147,6 +147,32 @@ function test_tevkori_get_srcset_array() {
147
147
$ this ->assertSame ( $ expected , $ sizes );
148
148
}
149
149
150
+ function test_tevkori_get_srcset_array_no_date_upoads () {
151
+ // Save the current setting for uploads folders
152
+ $ uploads_use_yearmonth_folders = get_option ( 'uploads_use_yearmonth_folders ' );
153
+
154
+ // Disable date organized uploads
155
+ update_option ( 'uploads_use_yearmonth_folders ' , 0 );
156
+
157
+ // make an image
158
+ $ id = $ this ->_test_img ();
159
+ $ sizes = tevkori_get_srcset_array ( $ id , 'medium ' );
160
+
161
+ $ image = wp_get_attachment_metadata ( $ id );
162
+ $ filename_base = substr ( $ image ['file ' ], 0 , strrpos ($ image ['file ' ], '.png ' ) );
163
+
164
+ $ expected = array (
165
+ 'http://example.org/wp-content/uploads/ ' . $ image ['sizes ' ]['medium ' ]['file ' ] . ' ' . $ image ['sizes ' ]['medium ' ]['width ' ] . 'w ' ,
166
+ 'http://example.org/wp-content/uploads/ ' . $ image ['sizes ' ]['large ' ]['file ' ] . ' ' . $ image ['sizes ' ]['large ' ]['width ' ] . 'w ' ,
167
+ 'http://example.org/wp-content/uploads/ ' . $ image ['file ' ] . ' ' . $ image ['width ' ] .'w '
168
+ );
169
+
170
+ $ this ->assertSame ( $ expected , $ sizes );
171
+
172
+ // Leave the uploads option the way you found it.
173
+ update_option ( 'uploads_use_yearmonth_folders ' , $ uploads_use_yearmonth_folders );
174
+ }
175
+
150
176
function test_tevkori_get_srcset_array_thumb () {
151
177
// make an image
152
178
$ id = $ this ->_test_img ();
@@ -171,6 +197,28 @@ function test_tevkori_get_srcset_array_false() { // make an image
171
197
$ this ->assertFalse ( $ sizes );
172
198
}
173
199
200
+ function test_tevkori_get_srcset_array_no_width () {
201
+ // Filter image_downsize() output.
202
+ add_filter ( 'image_downsize ' , array ( $ this , '_test_tevkori_get_srcset_array_no_width_filter ' ) );
203
+
204
+ // Make our attachement.
205
+ $ id = $ this ->_test_img ();
206
+ $ srcset = tevkori_get_srcset_array ( $ id , 'medium ' );
207
+
208
+ // The srcset should be false
209
+ $ this ->assertFalse ( $ srcset );
210
+
211
+ // Remove filter.
212
+ remove_filter ( 'image_downsize ' , array ( $ this , '_test_tevkori_get_srcset_array_no_width_filter ' ) );
213
+ }
214
+
215
+ /**
216
+ * Helper funtion to filter image_downsize and return zero values for width and height.
217
+ */
218
+ public function _test_tevkori_get_srcset_array_no_width_filter () {
219
+ return array ( 'http://example.org/foo.jpg ' , 0 , 0 , false );
220
+ }
221
+
174
222
function test_tevkori_get_srcset_string () {
175
223
// make an image
176
224
$ id = $ this ->_test_img ();
0 commit comments