Skip to content

Commit b09861d

Browse files
additional tests
1 parent 39ab835 commit b09861d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/class-tiny-picture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ protected function create_alternative_sources( $original_source_html ) {
379379
}
380380

381381
$source_attr_parts['type'] = $mimetype;
382-
$source_parts[] = '<source';
382+
$source_parts = array( '<source' );
383383
foreach ( $source_attr_parts as $source_attr_name => $source_attr_val ) {
384384
$source_parts[] = $source_attr_name . '="' . $source_attr_val . '"';
385385
}

test/unit/TinyPictureTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,28 @@ public function test_picture_with_attributes() {
191191
$output = $this->tiny_picture->replace_sources($input);
192192

193193
$this->assertEquals($expected, $output);
194+
}
195+
196+
public function test_adds_both_avif_and_webp()
197+
{
198+
$this->wp->createImage(1000, '2025/01', 'test.webp');
199+
$this->wp->createImage(1000, '2025/01', 'test.avif');
200+
201+
$input = '<img src="/wp-content/uploads/2025/01/test.png">';
202+
$expected = '<picture><source srcset="/wp-content/uploads/2025/01/test.webp" type="image/webp" /><source srcset="/wp-content/uploads/2025/01/test.avif" type="image/avif" /><img src="/wp-content/uploads/2025/01/test.png"></picture>';
203+
$output = $this->tiny_picture->replace_sources($input);
204+
205+
$this->assertEquals($expected, $output);
206+
}
207+
208+
public function test_img_with_query_and_fragment_keeps_both()
209+
{
210+
$this->wp->createImage(37857, '2025/09', 'test.avif');
194211

212+
$input = '<img src="/wp-content/uploads/2025/09/test.png?v=123#top">';
213+
$expected = '<picture><source srcset="/wp-content/uploads/2025/09/test.avif" type="image/avif" /><img src="/wp-content/uploads/2025/09/test.png?v=123#top"></picture>';
214+
$output = $this->tiny_picture->replace_sources($input);
215+
216+
$this->assertEquals($expected, $output);
195217
}
196218
}

0 commit comments

Comments
 (0)