@@ -88,7 +88,8 @@ def patch_Img2PictureTag_picture_variants():
88
88
"sourceset" : [
89
89
{
90
90
"scale" : "preview" ,
91
- "additionalScales" : ["preview" , "large" , "larger" ],
91
+ "additionalScales" : ["large" , "larger" ],
92
+ "sizes" : "(min-width: 576px) 350px, (min-width: 768px) 600px, 98vw" ,
92
93
}
93
94
],
94
95
},
@@ -538,22 +539,55 @@ def testGetPictureTagByName(self, mock_uuid_to_object):
538
539
mock_uuid_to_object .return_value = self .item
539
540
tag = self .scaling .picture ("image" , picture_variant = "medium" )
540
541
expected = """<picture>
541
- <source srcset="http://nohost/item/@@images/image-600-....png 600w,
542
+ <source... srcset="http://nohost/item/@@images/image-600-....png 600w,
542
543
http://nohost/item/@@images/image-400-....png 400w,
543
544
http://nohost/item/@@images/image-800-....png 800w,
544
545
http://nohost/item/@@images/image-1000-....png 1000w,
545
- http://nohost/item/@@images/image-1200-....png 1200w"/>
546
+ http://nohost/item/@@images/image-1200-....png 1200w"... />
546
547
<img...src="http://nohost/item/@@images/image-600-....png".../>
547
548
</picture>"""
548
549
self .assertTrue (_ellipsis_match (expected , tag .strip ()))
550
+ # The exact placement of the img tag attributes can differ, especially
551
+ # with different beautifulsoup versions.
552
+ # So check here that all attributes are present.
553
+ self .assertIn ('height="200"' , tag )
554
+ self .assertIn ('loading="lazy"' , tag )
555
+ self .assertIn ('title="foo"' , tag )
556
+ self .assertIn ('width="200"' , tag )
557
+ self .assertIn ('sizes="(min-width: 576px) 600px, 98vw"' , tag )
549
558
559
+ @patch .object (
560
+ plone .namedfile .scaling ,
561
+ "get_picture_variants" ,
562
+ new = patch_Img2PictureTag_picture_variants ,
563
+ spec = True ,
564
+ )
565
+ @patch .object (
566
+ plone .namedfile .picture ,
567
+ "get_allowed_scales" ,
568
+ new = patch_Img2PictureTag_allowed_scales ,
569
+ spec = True ,
570
+ )
571
+ @patch .object (plone .namedfile .picture , "uuidToObject" , spec = True )
572
+ def testGetPictureTagCustomSizes (self , mock_uuid_to_object ):
573
+ ImageScaling ._sizes = patch_Img2PictureTag_allowed_scales ()
574
+ mock_uuid_to_object .return_value = self .item
575
+ tag = self .scaling .picture ("image" , picture_variant = "small" )
576
+ expected = """<picture>
577
+ <source...srcset="http://nohost/item/@@images/image-400-....png 400w,
578
+ http://nohost/item/@@images/image-800-....png 800w,
579
+ http://nohost/item/@@images/image-1000-....png 1000w".../>
580
+ <img...src="http://nohost/item/@@images/image-400-....png".../>
581
+ </picture>"""
582
+ self .assertTrue (_ellipsis_match (expected , tag .strip ()))
550
583
# The exact placement of the img tag attributes can differ, especially
551
584
# with different beautifulsoup versions.
552
585
# So check here that all attributes are present.
553
586
self .assertIn ('height="200"' , tag )
554
587
self .assertIn ('loading="lazy"' , tag )
555
588
self .assertIn ('title="foo"' , tag )
556
589
self .assertIn ('width="200"' , tag )
590
+ self .assertIn ('sizes="(min-width: 576px) 350px, (min-width: 768px) 600px, 98vw"' , tag )
557
591
558
592
@patch .object (
559
593
plone .namedfile .scaling ,
@@ -579,11 +613,11 @@ def testGetPictureTagWithAltAndTitle(self, mock_uuid_to_object):
579
613
)
580
614
base = self .item .absolute_url ()
581
615
expected = f"""<picture>
582
- <source srcset="{ base } /@@images/image-600-....png 600w,
616
+ <source... srcset="{ base } /@@images/image-600-....png 600w,
583
617
{ base } /@@images/image-400-....png 400w,
584
618
{ base } /@@images/image-800-....png 800w,
585
619
{ base } /@@images/image-1000-....png 1000w,
586
- { base } /@@images/image-1200-....png 1200w"/>
620
+ { base } /@@images/image-1200-....png 1200w"... />
587
621
<img...src="{ base } /@@images/image-600-....png".../>
588
622
</picture>"""
589
623
self .assertTrue (_ellipsis_match (expected , tag .strip ()))
0 commit comments