@@ -317,6 +317,64 @@ public function test_can_override_noscript_attributes()
317317 );
318318 }
319319
320+ public function test_can_initialize_from_array ()
321+ {
322+ $ imageSetArray = array (
323+ 'sources ' => array (
324+ 0 => array (
325+ 'image ' => '01.jpg ' ,
326+ 'widths ' => array (0 => 500 , 1 => 900 , 2 => 1300 , 3 => 1700 ),
327+ 'srcset ' => array (
328+ 0 => array (
329+ 'image ' => array (
330+ 'source ' => array ('fileName ' => '01.jpg ' , 'path ' => '/path/to/images/source/01.jpg ' , 'url ' => '/images/source/01.jpg ' , 'width ' => 2932 , 'height ' => 2000 , 'ratio ' => 1.466 ,),
331+ 'cached ' => array ('fileName ' => '01.jpg/one.jpg ' , 'path ' => '/path/to/images/cache/01.jpg/one.jpg ' , 'url ' => '/images/cache/01.jpg/one.jpg ' , 'width ' => 500 , 'height ' => 341 , 'ratio ' => 1.466275659824047 ,),
332+ ),
333+ 'width ' => 500 ,
334+ ),
335+ 1 => array (
336+ 'image ' => array (
337+ 'source ' => array ('fileName ' => '01.jpg ' , 'path ' => '/path/to/images/source/01.jpg ' , 'url ' => '/images/source/01.jpg ' , 'width ' => 2932 , 'height ' => 2000 , 'ratio ' => 1.466 ,),
338+ 'cached ' => array ('fileName ' => '01.jpg/two.jpg ' , 'path ' => '/path/to/images/cache/01.jpg/two.jpg ' , 'url ' => '/images/cache/01.jpg/two.jpg ' , 'width ' => 900 , 'height ' => 614 , 'ratio ' => 1.4657980456026058 ,),
339+ ),
340+ 'width ' => 900 ,
341+ ),
342+ 2 => array (
343+ 'image ' => array (
344+ 'source ' => array ('fileName ' => '01.jpg ' , 'path ' => '/path/to/images/source/01.jpg ' , 'url ' => '/images/source/01.jpg ' , 'width ' => 2932 , 'height ' => 2000 , 'ratio ' => 1.466 ,),
345+ 'cached ' => array ('fileName ' => '01.jpg/three.jpg ' , 'path ' => '/path/to/images/cache/01.jpg/three.jpg ' , 'url ' => '/images/cache/01.jpg/three.jpg ' , 'width ' => 1300 , 'height ' => 887 , 'ratio ' => 1.4656144306651635 ,),
346+ ),
347+ 'width ' => 1300 ,
348+ ),
349+ 3 => array (
350+ 'image ' => array (
351+ 'source ' => array ('fileName ' => '01.jpg ' , 'path ' => '/path/to/images/source/01.jpg ' , 'url ' => '/images/source/01.jpg ' , 'width ' => 2932 , 'height ' => 2000 , 'ratio ' => 1.466 ,),
352+ 'cached ' => array ('fileName ' => '01.jpg/four.jpg ' , 'path ' => '/path/to/images/cache/01.jpg/four.jpg ' , 'url ' => '/images/cache/01.jpg/four.jpg ' , 'width ' => 1700 , 'height ' => 1160 , 'ratio ' => 1.4655172413793103 ,),
353+ ),
354+ 'width ' => 1700 ,
355+ ),
356+ ),
357+ ),
358+ ),
359+ 'lqip ' => array (
360+ 'source ' => array ('fileName ' => '01.jpg ' , 'path ' => '/path/to/images/source/01.jpg ' , 'url ' => '/images/source/01.jpg ' , 'width ' => 2932 , 'height ' => 2000 , 'ratio ' => 1.466 ,),
361+ 'cached ' => array ('fileName ' => '01.jpg/lqip.gif ' , 'path ' => '/path/to/images/cache/01.jpg/lqip.gif ' , 'url ' => '/images/cache/01.jpg/lqip.gif ' , 'width ' => 15 , 'height ' => 10 , 'ratio ' => 1.5 ,),
362+ ),
363+ );
364+
365+ $ imageRender = ImageSetRender::fromArray ($ imageSetArray );
366+
367+ $ output = $ imageRender ->img ([
368+ 'class ' => 'test ' ,
369+ 'alt ' => 'This is a test ' ,
370+ ]);
371+
372+ $ this ->assertEquals (
373+ '<img class="lazyload test" alt="This is a test" src="/images/cache/01.jpg/lqip.gif" width="1700" height="1160" data-src="/images/cache/01.jpg/four.jpg" data-srcset="/images/cache/01.jpg/one.jpg 500w, /images/cache/01.jpg/two.jpg 900w, /images/cache/01.jpg/three.jpg 1300w, /images/cache/01.jpg/four.jpg 1700w" data-sizes="100vw"> ' ,
374+ $ output
375+ );
376+ }
377+
320378 protected function prepareAllImages (): array
321379 {
322380 $ image1 = $ this ->prepareImage ();
@@ -500,3 +558,11 @@ protected function prepareForPictureFormats($options = []): object
500558 ];
501559 }
502560}
561+
562+
563+
564+ /*
565+
566+
567+
568+ */
0 commit comments