Skip to content

Commit cae4b7f

Browse files
committed
Revert "Extract common PHP into helper method"
This reverts commit e6c54b0.
1 parent e04692d commit cae4b7f

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ class Test_Dominant_Color extends TestCase {
1919
* @param string[] $expected_color Expected color.
2020
*/
2121
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 );
2335
$this->assertArrayHasKey( 'dominant_color', $dominant_color_metadata );
2436
$this->assertNotEmpty( $dominant_color_metadata['dominant_color'] );
2537
$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
6577
* @param bool $expected_transparency Expected transparency.
6678
*/
6779
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 );
6992
$this->assertArrayHasKey( 'has_transparency', $transparency_metadata );
7093
$this->assertSame( $expected_transparency, $transparency_metadata['has_transparency'] );
7194
}
@@ -504,25 +527,4 @@ public function test_dominant_color_prepare_attachment_for_js(): void {
504527
$this->assertEquals( 'ff0000', $response['dominantColor'] );
505528
$this->assertTrue( $response['hasTransparency'] );
506529
}
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-
}
528530
}

0 commit comments

Comments
 (0)