Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions plugins/dominant-color-images/tests/data/class-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,12 @@ public function test_get_dominant_color_valid( string $image_path, array $expect
}

$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
$metadata = wp_get_attachment_metadata( $attachment_id );

$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertNotWPError( $dominant_color_data );
$this->assertContains( $dominant_color_data['dominant_color'], $expected_color );
$this->assertSame( $dominant_color_data['has_transparency'], $expected_transparency );
$this->assertIsArray( $metadata );
$this->assertArrayHasKey( 'dominant_color', $metadata );
$this->assertContains( $metadata['dominant_color'], $expected_color );
$this->assertSame( $metadata['has_transparency'], $expected_transparency );
}

/**
Expand All @@ -209,7 +208,6 @@ public function test_get_dominant_color_invalid( string $image_path ): void {
$this->markTestSkipped( "Mime type $mime_type is not supported." );
}
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

Expand All @@ -227,7 +225,6 @@ public function test_get_dominant_color_data_unsupported_mime_type(): void {
$image_path = TESTS_PLUGIN_DIR . '/tests/data/images/red.jpg';

$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

Expand All @@ -245,7 +242,6 @@ public function test_get_dominant_color_data_unsupported_mime_type(): void {
*/
public function test_get_dominant_color_none_images( string $image_path ): void {
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

Expand Down
9 changes: 2 additions & 7 deletions plugins/dominant-color-images/tests/test-dominant-color.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public function test_dominant_color_metadata( string $image_path, array $expecte
$this->assertEmpty( $dominant_color_metadata );

// Creating attachment.
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
$dominant_color_metadata = dominant_color_metadata( array(), $attachment_id );
$this->assertArrayHasKey( 'dominant_color', $dominant_color_metadata );
$this->assertNotEmpty( $dominant_color_metadata['dominant_color'] );
Expand Down Expand Up @@ -77,8 +76,7 @@ public function test_has_transparency_metadata( string $image_path, array $expec
$transparency_metadata = dominant_color_metadata( array(), 1 );
$this->assertEmpty( $transparency_metadata );

$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
$transparency_metadata = dominant_color_metadata( array(), $attachment_id );
$this->assertArrayHasKey( 'has_transparency', $transparency_metadata );
$this->assertSame( $expected_transparency, $transparency_metadata['has_transparency'] );
Expand Down Expand Up @@ -130,7 +128,6 @@ public function test_tag_add_adjust_to_image_attributes( string $image_path, arr
$this->skip_if_mime_type_unsupported( $image_path );

$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

list( $src, $width, $height ) = wp_get_attachment_image_src( $attachment_id );
// Testing tag_add_adjust() with image being lazy load.
Expand Down Expand Up @@ -167,7 +164,6 @@ public function test_tag_add_adjust_to_image_attributes( string $image_path, arr
*/
public function test_dominant_color_img_tag_add_dominant_color_requires_proper_quotes( string $image, bool $expected ): void {
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/red.jpg' );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$image_url = wp_get_attachment_image_url( $attachment_id );
$image = sprintf( $image, $image_url );
Expand Down Expand Up @@ -211,7 +207,6 @@ public function data_dominant_color_img_tag_add_dominant_color_requires_proper_q
*/
public function test_dominant_color_img_tag_add_dominant_color_should_add_dominant_color_inline_style( string $filtered_image, string $expected ): void {
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/red.jpg' );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

list( $src, $width, $height ) = wp_get_attachment_image_src( $attachment_id );

Expand Down
Loading