@@ -19,7 +19,19 @@ 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
- $ dominant_color_metadata = $ this ->get_transparency_metadata ( $ image_path );
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
+ }
26
+
27
+ // Non existing attachment.
28
+ $ dominant_color_metadata = dominant_color_metadata ( array (), 1 );
29
+ $ this ->assertEmpty ( $ dominant_color_metadata );
30
+
31
+ // Creating attachment.
32
+ $ attachment_id = self ::factory ()->attachment ->create_upload_object ( $ image_path );
33
+ wp_maybe_generate_attachment_metadata ( get_post ( $ attachment_id ) );
34
+ $ dominant_color_metadata = dominant_color_metadata ( array (), $ attachment_id );
23
35
$ this ->assertArrayHasKey ( 'dominant_color ' , $ dominant_color_metadata );
24
36
$ this ->assertNotEmpty ( $ dominant_color_metadata ['dominant_color ' ] );
25
37
$ this ->assertContains ( $ dominant_color_metadata ['dominant_color ' ], $ expected_color );
@@ -65,7 +77,18 @@ public function test_dominant_color_get_dominant_color( string $image_path, arra
65
77
* @param bool $expected_transparency Expected transparency.
66
78
*/
67
79
public function test_has_transparency_metadata ( string $ image_path , array $ expected_color , bool $ expected_transparency ): void {
68
- $ transparency_metadata = $ this ->get_transparency_metadata ( $ image_path );
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
+ }
84
+
85
+ // Non-existing attachment.
86
+ $ transparency_metadata = dominant_color_metadata ( array (), 1 );
87
+ $ this ->assertEmpty ( $ transparency_metadata );
88
+
89
+ $ attachment_id = self ::factory ()->attachment ->create_upload_object ( $ image_path );
90
+ wp_maybe_generate_attachment_metadata ( get_post ( $ attachment_id ) );
91
+ $ transparency_metadata = dominant_color_metadata ( array (), $ attachment_id );
69
92
$ this ->assertArrayHasKey ( 'has_transparency ' , $ transparency_metadata );
70
93
$ this ->assertSame ( $ expected_transparency , $ transparency_metadata ['has_transparency ' ] );
71
94
}
@@ -504,25 +527,4 @@ public function test_dominant_color_prepare_attachment_for_js(): void {
504
527
$ this ->assertEquals ( 'ff0000 ' , $ response ['dominantColor ' ] );
505
528
$ this ->assertTrue ( $ response ['hasTransparency ' ] );
506
529
}
507
-
508
- /**
509
- * Gets transparency metadata.
510
- *
511
- * @param string $image_path Image path.
512
- * @return array{ has_transparency?: bool, dominant_color?: string } Data.
513
- */
514
- private function get_transparency_metadata ( string $ image_path ): array {
515
- $ mime_type = wp_check_filetype ( $ image_path )['type ' ];
516
- if ( ! wp_image_editor_supports ( array ( 'mime_type ' => $ mime_type ) ) ) {
517
- $ this ->markTestSkipped ( "Mime type $ mime_type is not supported. " );
518
- }
519
-
520
- // Non-existing attachment.
521
- $ transparency_metadata = dominant_color_metadata ( array (), 1 );
522
- $ this ->assertEmpty ( $ transparency_metadata );
523
-
524
- $ attachment_id = self ::factory ()->attachment ->create_upload_object ( $ image_path );
525
- wp_maybe_generate_attachment_metadata ( get_post ( $ attachment_id ) );
526
- return dominant_color_metadata ( array (), $ attachment_id );
527
- }
528
530
}
0 commit comments