Skip to content

Commit b881254

Browse files
committed
Add skip_if_mime_type_unsupported helper method
1 parent cae4b7f commit b881254

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ 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-
$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 );
2623

27-
// Non existing attachment.
24+
// Non-existing attachment.
2825
$dominant_color_metadata = dominant_color_metadata( array(), 1 );
2926
$this->assertEmpty( $dominant_color_metadata );
3027

@@ -46,10 +43,7 @@ public function test_dominant_color_metadata( string $image_path, array $expecte
4643
* @param string[] $expected_color Expected color.
4744
*/
4845
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 );
5347

5448
// Test when attachment is not an image.
5549
$non_image_attachment = self::factory()->post->create(
@@ -77,10 +71,7 @@ public function test_dominant_color_get_dominant_color( string $image_path, arra
7771
* @param bool $expected_transparency Expected transparency.
7872
*/
7973
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 );
8475

8576
// Non-existing attachment.
8677
$transparency_metadata = dominant_color_metadata( array(), 1 );
@@ -103,10 +94,7 @@ public function test_has_transparency_metadata( string $image_path, array $expec
10394
* @param bool $expected_transparency Expected transparency.
10495
*/
10596
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 );
11098
// Test when metadata is not an array.
11199
$invalid_meta_attachment = self::factory()->attachment->create(
112100
array(
@@ -138,10 +126,7 @@ public function test_dominant_color_has_transparency( string $image_path, array
138126
* @param bool $expected_transparency Expected transparency.
139127
*/
140128
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 );
145130

146131
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
147132
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
@@ -527,4 +512,16 @@ public function test_dominant_color_prepare_attachment_for_js(): void {
527512
$this->assertEquals( 'ff0000', $response['dominantColor'] );
528513
$this->assertTrue( $response['hasTransparency'] );
529514
}
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+
}
530527
}

0 commit comments

Comments
 (0)