@@ -42,8 +42,6 @@ public function test_dominant_color_metadata( string $image_path, array $expecte
42
42
*
43
43
* @dataProvider provider_get_dominant_color
44
44
*
45
- * @covers helper::dominant_color_get_dominant_color
46
- *
47
45
* @param string $image_path Image path.
48
46
* @param string[] $expected_color Expected color.
49
47
*/
@@ -53,6 +51,15 @@ public function test_dominant_color_get_dominant_color( string $image_path, arra
53
51
$ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
54
52
}
55
53
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
+
56
63
// Creating attachment.
57
64
$ attachment_id = self ::factory ()->attachment ->create_upload_object ( $ image_path );
58
65
$ 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
91
98
*
92
99
* @dataProvider provider_get_dominant_color
93
100
*
94
- * @covers helper::dominant_color_get_dominant_color
95
- *
96
101
* @param string $image_path Image path.
97
102
* @param string[] $expected_color Expected color.
98
103
* @param bool $expected_transparency Expected transparency.
@@ -102,6 +107,19 @@ public function test_dominant_color_has_transparency( string $image_path, array
102
107
if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
103
108
$ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
104
109
}
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 ) );
105
123
106
124
// Creating attachment.
107
125
$ 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
113
131
*
114
132
* @dataProvider provider_get_dominant_color
115
133
*
116
- * @covers hooks ::dominant_color_img_tag_add_dominant_color
134
+ * @covers ::dominant_color_img_tag_add_dominant_color
117
135
*
118
136
* @param string $image_path Image path.
119
137
* @param string[] $expected_color Expected color.
@@ -199,7 +217,7 @@ public function data_dominant_color_img_tag_add_dominant_color_requires_proper_q
199
217
*
200
218
* @dataProvider data_provider_dominant_color_check_inline_style
201
219
*
202
- * @covers hooks ::dominant_color_img_tag_add_dominant_color
220
+ * @covers ::dominant_color_img_tag_add_dominant_color
203
221
*
204
222
* @param string $filtered_image The filtered image markup.
205
223
* Must include `src="%s" width="%d" height="%d"`.
0 commit comments