diff --git a/plugins/auto-sizes/auto-sizes.php b/plugins/auto-sizes/auto-sizes.php
index 7ee3c88934..74513194d3 100644
--- a/plugins/auto-sizes/auto-sizes.php
+++ b/plugins/auto-sizes/auto-sizes.php
@@ -19,7 +19,6 @@
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
-// @codeCoverageIgnoreEnd
// Define the constant.
if ( defined( 'IMAGE_AUTO_SIZES_VERSION' ) ) {
@@ -31,3 +30,4 @@
require_once __DIR__ . '/includes/auto-sizes.php';
require_once __DIR__ . '/includes/improve-calculate-sizes.php';
require_once __DIR__ . '/hooks.php';
+// @codeCoverageIgnoreEnd
diff --git a/plugins/auto-sizes/hooks.php b/plugins/auto-sizes/hooks.php
index 825f02ee4e..c6923ea6cb 100644
--- a/plugins/auto-sizes/hooks.php
+++ b/plugins/auto-sizes/hooks.php
@@ -10,7 +10,6 @@
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
-// @codeCoverageIgnoreEnd
/**
* Displays the HTML generator tag for the plugin.
@@ -43,3 +42,4 @@ function auto_sizes_render_generator(): void {
add_filter( 'render_block_core/post-featured-image', 'auto_sizes_filter_image_tag', 10, 3 );
add_filter( 'get_block_type_uses_context', 'auto_sizes_filter_uses_context', 10, 2 );
add_filter( 'render_block_context', 'auto_sizes_filter_render_block_context', 10, 3 );
+// @codeCoverageIgnoreEnd
diff --git a/plugins/auto-sizes/includes/improve-calculate-sizes.php b/plugins/auto-sizes/includes/improve-calculate-sizes.php
index eb0691bffe..3cd57a32da 100644
--- a/plugins/auto-sizes/includes/improve-calculate-sizes.php
+++ b/plugins/auto-sizes/includes/improve-calculate-sizes.php
@@ -76,7 +76,7 @@ function auto_sizes_prime_attachment_caches( $content ): string {
*/
function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $block ): string {
if ( ! is_string( $content ) ) {
- return '';
+ return ''; // @codeCoverageIgnore
}
$processor = new WP_HTML_Tag_Processor( $content );
diff --git a/plugins/auto-sizes/tests/test-auto-sizes.php b/plugins/auto-sizes/tests/test-auto-sizes.php
index 8560c33521..9173dcabef 100644
--- a/plugins/auto-sizes/tests/test-auto-sizes.php
+++ b/plugins/auto-sizes/tests/test-auto-sizes.php
@@ -266,6 +266,15 @@ public function data_provider_to_test_auto_sizes_update_content_img_tag(): array
'input' => '
',
'expected' => '
',
),
+ 'expected_when_no_img_tag' => array(
+ 'input' => '
No image here
',
+ 'expected' => 'No image here
',
+ ),
+ 'expected_when_not_responsive' => array(
+ 'input' => '
',
+ 'expected' => '
',
+ ),
+
);
}
@@ -279,4 +288,101 @@ public function test_auto_sizes_update_content_img_tag( string $input, string $e
auto_sizes_update_content_img_tag( $input )
);
}
+
+ /**
+ * @covers ::auto_sizes_attribute_includes_valid_auto
+ */
+ public function test_auto_sizes_attribute_includes_valid_auto(): void {
+ // Test when 'auto' is the first item in the list.
+ $this->assertTrue( auto_sizes_attribute_includes_valid_auto( 'auto, 100vw' ) );
+
+ // Test when 'auto' is not the first item in the list.
+ $this->assertFalse( auto_sizes_attribute_includes_valid_auto( '100vw, auto' ) );
+ }
+
+ /**
+ * Provides data for the auto_sizes_update_image_attributes test.
+ *
+ * @return array The data for the test cases.
+ */
+ public function data_provider_for_auto_sizes_update_image_attributes(): array {
+ return array(
+ array(
+ array(
+ 'loading' => 'eager',
+ 'sizes' => '100vw',
+ ),
+ array(
+ 'loading' => 'eager',
+ 'sizes' => '100vw',
+ ),
+ ),
+
+ // Test when the image is not responsive.
+ array( array( 'loading' => 'lazy' ), array( 'loading' => 'lazy' ) ),
+
+ // Test when 'auto' already exists in the sizes attribute.
+ array(
+ array(
+ 'loading' => 'lazy',
+ 'sizes' => 'auto, 100vw',
+ ),
+ array(
+ 'loading' => 'lazy',
+ 'sizes' => 'auto, 100vw',
+ ),
+ ),
+
+ // Test when 'auto' needs to be added to the sizes attribute.
+ array(
+ array(
+ 'loading' => 'lazy',
+ 'sizes' => '100vw',
+ ),
+ array(
+ 'loading' => 'lazy',
+ 'sizes' => 'auto, 100vw',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @covers ::auto_sizes_update_image_attributes
+ *
+ * @dataProvider data_provider_for_auto_sizes_update_image_attributes
+ *
+ * @param array $attr Attributes to be updated.
+ * @param array $expected Expected updated attributes.
+ */
+ public function test_auto_sizes_update_image_attributes( array $attr, array $expected ): void {
+ $this->assertSame( $expected, auto_sizes_update_image_attributes( $attr ) );
+ }
+
+ /**
+ * @covers ::auto_sizes_update_content_img_tag
+ */
+ public function test_auto_sizes_update_content_img_tag_non_string_input(): void {
+ /*
+ * These tests are separate from the data provider approach because the function
+ * auto_sizes_update_content_img_tag() expects a string as an argument. Passing a non-string
+ * value would cause a TypeError. These tests ensure that the function behaves as expected
+ * when it receives non-string inputs.
+ */
+ $this->assertSame( '', auto_sizes_update_content_img_tag( array() ) );
+ }
+
+ /**
+ * @covers ::auto_sizes_update_image_attributes
+ */
+ public function test_auto_sizes_update_image_attributes_with_null_input(): void {
+ /*
+ * This test is separate because the main test method uses a data provider
+ * that expects the $attr parameter to be an array. Passing null directly
+ * would cause a TypeError due to the type hint. By testing null separately,
+ * we ensure that the function can handle null inputs gracefully without
+ * modifying the type hint in the main test method.
+ */
+ $this->assertSame( array(), auto_sizes_update_image_attributes( null ) );
+ }
}