Skip to content

Commit cf65c01

Browse files
Sarthak JaiswalSarthak Jaiswal
authored andcommitted
Fixed incorrect annotation helper & hooks in covers
1 parent b65df2d commit cf65c01

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

plugins/dominant-color-images/tests/test-dominant-color.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public function test_dominant_color_metadata( string $image_path, array $expecte
4242
*
4343
* @dataProvider provider_get_dominant_color
4444
*
45-
* @covers helper::dominant_color_get_dominant_color
46-
*
4745
* @param string $image_path Image path.
4846
* @param string[] $expected_color Expected color.
4947
*/
@@ -53,6 +51,15 @@ public function test_dominant_color_get_dominant_color( string $image_path, arra
5351
$this->markTestSkipped( "Mime type $mime_type is not supported." );
5452
}
5553

54+
// Test when attachment is not an image.
55+
$non_image_attachment = self::factory()->post->create(
56+
array(
57+
'post_type' => 'attachment',
58+
'post_mime_type' => 'application/pdf',
59+
)
60+
);
61+
$this->assertNull( dominant_color_get_dominant_color( $non_image_attachment ) );
62+
5663
// Creating attachment.
5764
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
5865
$this->assertContains( dominant_color_get_dominant_color( $attachment_id ), $expected_color );
@@ -91,8 +98,6 @@ public function test_has_transparency_metadata( string $image_path, array $expec
9198
*
9299
* @dataProvider provider_get_dominant_color
93100
*
94-
* @covers helper::dominant_color_get_dominant_color
95-
*
96101
* @param string $image_path Image path.
97102
* @param string[] $expected_color Expected color.
98103
* @param bool $expected_transparency Expected transparency.
@@ -102,6 +107,19 @@ public function test_dominant_color_has_transparency( string $image_path, array
102107
if ( ! wp_image_editor_supports( array( 'mime_type' => $mime_type ) ) ) {
103108
$this->markTestSkipped( "Mime type $mime_type is not supported." );
104109
}
110+
// Test when metadata is not an array.
111+
$invalid_meta_attachment = self::factory()->attachment->create(
112+
array(
113+
'post_mime_type' => 'image/jpeg',
114+
)
115+
);
116+
update_post_meta( $invalid_meta_attachment, '_wp_attachment_metadata', 'not_an_array' );
117+
$this->assertNull( dominant_color_has_transparency( $invalid_meta_attachment ) );
118+
119+
// Test when has_transparency is not set in metadata.
120+
delete_post_meta( $invalid_meta_attachment, '_wp_attachment_metadata' );
121+
update_post_meta( $invalid_meta_attachment, '_wp_attachment_metadata', array( 'other_key' => 'value' ) );
122+
$this->assertNull( dominant_color_has_transparency( $invalid_meta_attachment ) );
105123

106124
// Creating attachment.
107125
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
@@ -113,7 +131,7 @@ public function test_dominant_color_has_transparency( string $image_path, array
113131
*
114132
* @dataProvider provider_get_dominant_color
115133
*
116-
* @covers hooks::dominant_color_img_tag_add_dominant_color
134+
* @covers ::dominant_color_img_tag_add_dominant_color
117135
*
118136
* @param string $image_path Image path.
119137
* @param string[] $expected_color Expected color.
@@ -199,7 +217,7 @@ public function data_dominant_color_img_tag_add_dominant_color_requires_proper_q
199217
*
200218
* @dataProvider data_provider_dominant_color_check_inline_style
201219
*
202-
* @covers hooks::dominant_color_img_tag_add_dominant_color
220+
* @covers ::dominant_color_img_tag_add_dominant_color
203221
*
204222
* @param string $filtered_image The filtered image markup.
205223
* Must include `src="%s" width="%d" height="%d"`.

0 commit comments

Comments
 (0)