Skip to content

Commit bfd7d2b

Browse files
committed
Add test for handling false return value from wp_get_attachment_image_src
1 parent 6a5c0df commit bfd7d2b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

plugins/webp-uploads/tests/test-picture-element.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,27 @@ public function test_picture_source_should_have_full_size_image_in_its_srcset():
373373
$this->assertStringContainsString( $image_meta['sources'][ self::$mime_type ]['file'], $picture_processor->get_attribute( 'srcset' ), 'Make sure the IMG srcset should have full size image.' );
374374
}
375375
}
376+
377+
/**
378+
* Test handling of case when wp_get_attachment_image_src returns false.
379+
*/
380+
public function test_wrap_image_in_picture_with_false_image_src(): void {
381+
$this->opt_in_to_picture_element();
382+
383+
$image = wp_get_attachment_image(
384+
self::$image_id,
385+
'large',
386+
false,
387+
array(
388+
'class' => 'wp-image-' . self::$image_id,
389+
'alt' => 'Green Leaves',
390+
)
391+
);
392+
393+
add_filter( 'wp_get_attachment_image_src', '__return_false' );
394+
$filtered_image = apply_filters( 'wp_content_img_tag', $image, 'the_content', self::$image_id );
395+
remove_filter( 'wp_get_attachment_image_src', '__return_false' );
396+
397+
$this->assertSame( $image, $filtered_image );
398+
}
376399
}

0 commit comments

Comments
 (0)