@@ -147,6 +147,32 @@ function test_tevkori_get_srcset_array() {
147147 $ this ->assertSame ( $ expected , $ sizes );
148148 }
149149
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+
150176 function test_tevkori_get_srcset_array_thumb () {
151177 // make an image
152178 $ id = $ this ->_test_img ();
@@ -171,6 +197,28 @@ function test_tevkori_get_srcset_array_false() { // make an image
171197 $ this ->assertFalse ( $ sizes );
172198 }
173199
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+
174222 function test_tevkori_get_srcset_string () {
175223 // make an image
176224 $ id = $ this ->_test_img ();
0 commit comments