@@ -19,12 +19,9 @@ class Test_Dominant_Color extends TestCase {
19
19
* @param string[] $expected_color Expected color.
20
20
*/
21
21
public function test_dominant_color_metadata ( string $ image_path , array $ expected_color ): void {
22
- $ mime_type = wp_check_filetype ( $ image_path )['type ' ];
23
- if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
24
- $ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
25
- }
22
+ $ this ->skip_if_mime_type_unsupported ( $ image_path );
26
23
27
- // Non existing attachment.
24
+ // Non- existing attachment.
28
25
$ dominant_color_metadata = dominant_color_metadata ( array (), 1 );
29
26
$ this ->assertEmpty ( $ dominant_color_metadata );
30
27
@@ -46,10 +43,7 @@ public function test_dominant_color_metadata( string $image_path, array $expecte
46
43
* @param string[] $expected_color Expected color.
47
44
*/
48
45
public function test_dominant_color_get_dominant_color ( string $ image_path , array $ expected_color ): void {
49
- $ mime_type = wp_check_filetype ( $ image_path )['type ' ];
50
- if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
51
- $ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
52
- }
46
+ $ this ->skip_if_mime_type_unsupported ( $ image_path );
53
47
54
48
// Test when attachment is not an image.
55
49
$ non_image_attachment = self ::factory ()->post ->create (
@@ -77,10 +71,7 @@ public function test_dominant_color_get_dominant_color( string $image_path, arra
77
71
* @param bool $expected_transparency Expected transparency.
78
72
*/
79
73
public function test_has_transparency_metadata ( string $ image_path , array $ expected_color , bool $ expected_transparency ): void {
80
- $ mime_type = wp_check_filetype ( $ image_path )['type ' ];
81
- if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
82
- $ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
83
- }
74
+ $ this ->skip_if_mime_type_unsupported ( $ image_path );
84
75
85
76
// Non-existing attachment.
86
77
$ transparency_metadata = dominant_color_metadata ( array (), 1 );
@@ -103,10 +94,7 @@ public function test_has_transparency_metadata( string $image_path, array $expec
103
94
* @param bool $expected_transparency Expected transparency.
104
95
*/
105
96
public function test_dominant_color_has_transparency ( string $ image_path , array $ expected_color , bool $ expected_transparency ): void {
106
- $ mime_type = wp_check_filetype ( $ image_path )['type ' ];
107
- if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
108
- $ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
109
- }
97
+ $ this ->skip_if_mime_type_unsupported ( $ image_path );
110
98
// Test when metadata is not an array.
111
99
$ invalid_meta_attachment = self ::factory ()->attachment ->create (
112
100
array (
@@ -138,10 +126,7 @@ public function test_dominant_color_has_transparency( string $image_path, array
138
126
* @param bool $expected_transparency Expected transparency.
139
127
*/
140
128
public function test_tag_add_adjust_to_image_attributes ( string $ image_path , array $ expected_color , bool $ expected_transparency ): void {
141
- $ mime_type = wp_check_filetype ( $ image_path )['type ' ];
142
- if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
143
- $ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
144
- }
129
+ $ this ->skip_if_mime_type_unsupported ( $ image_path );
145
130
146
131
$ attachment_id = self ::factory ()->attachment ->create_upload_object ( $ image_path );
147
132
wp_maybe_generate_attachment_metadata ( get_post ( $ attachment_id ) );
@@ -527,4 +512,16 @@ public function test_dominant_color_prepare_attachment_for_js(): void {
527
512
$ this ->assertEquals ( 'ff0000 ' , $ response ['dominantColor ' ] );
528
513
$ this ->assertTrue ( $ response ['hasTransparency ' ] );
529
514
}
515
+
516
+ /**
517
+ * Skips if MIME type is not supported.
518
+ *
519
+ * @param string $image_path Image path.
520
+ */
521
+ private function skip_if_mime_type_unsupported ( string $ image_path ): void {
522
+ $ mime_type = wp_check_filetype ( $ image_path )['type ' ];
523
+ if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
524
+ $ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
525
+ }
526
+ }
530
527
}
0 commit comments