@@ -526,4 +526,62 @@ public function test_wrap_image_in_picture_with_false_image_src(): void {
526
526
527
527
$ this ->assertSame ( $ image , $ filtered_image );
528
528
}
529
+
530
+ /**
531
+ * Test that images are not wrapped in picture element for unsupported contexts.
532
+ *
533
+ * @dataProvider data_provider_webp_uploads_wrap_image_in_picture_with_different_context
534
+ *
535
+ * @param string $context The context to test.
536
+ * @param bool $expected Whether the image should be wrapped in a picture element.
537
+ */
538
+ public function test_webp_uploads_wrap_image_in_picture_with_different_context ( string $ context , bool $ expected ): void {
539
+ $ image = wp_get_attachment_image (
540
+ self ::$ image_id ,
541
+ 'large ' ,
542
+ false ,
543
+ array (
544
+ 'class ' => 'wp-image- ' . self ::$ image_id ,
545
+ 'alt ' => 'Green Leaves ' ,
546
+ )
547
+ );
548
+
549
+ $ this ->opt_in_to_picture_element ();
550
+ $ filtered_image = apply_filters ( 'wp_content_img_tag ' , $ image , $ context , self ::$ image_id );
551
+ if ( $ expected ) {
552
+ $ this ->assertStringStartsWith ( '<picture ' , $ filtered_image );
553
+ } else {
554
+ $ this ->assertSame ( $ image , $ filtered_image );
555
+ }
556
+ }
557
+
558
+ /**
559
+ * Data provider for test_webp_uploads_wrap_image_in_picture_with_different_context.
560
+ *
561
+ * @return array<string, array{ context: string, expected: bool }>
562
+ */
563
+ public function data_provider_webp_uploads_wrap_image_in_picture_with_different_context (): array {
564
+ return array (
565
+ 'the_content ' =>
566
+ array (
567
+ 'context ' => 'the_content ' ,
568
+ 'expected ' => true ,
569
+ ),
570
+ 'post_thumbnail_html ' =>
571
+ array (
572
+ 'context ' => 'post_thumbnail_html ' ,
573
+ 'expected ' => true ,
574
+ ),
575
+ 'widget_block_content ' =>
576
+ array (
577
+ 'context ' => 'widget_block_content ' ,
578
+ 'expected ' => true ,
579
+ ),
580
+ 'invalid_context ' =>
581
+ array (
582
+ 'context ' => 'invalid_context ' ,
583
+ 'expected ' => false ,
584
+ ),
585
+ );
586
+ }
529
587
}
0 commit comments