From bdf9f4205c9b11f35b6389829358a6a8c2509d77 Mon Sep 17 00:00:00 2001 From: Rashed Hossain Date: Thu, 27 Aug 2026 15:40:23 +0600 Subject: [PATCH 1/2] Dominant Color Images: Clean up redundant metadata generation in tests. Removes unnecessary calls to wp_maybe_generate_attachment_metadata() following create_upload_object() and asserts directly against generated attachment metadata in test_get_dominant_color_valid(). Fixes #2524. --- .../tests/data/class-testcase.php | 14 +++++--------- .../tests/test-dominant-color.php | 5 ----- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/plugins/dominant-color-images/tests/data/class-testcase.php b/plugins/dominant-color-images/tests/data/class-testcase.php index 2925664276..81b39f84ba 100644 --- a/plugins/dominant-color-images/tests/data/class-testcase.php +++ b/plugins/dominant-color-images/tests/data/class-testcase.php @@ -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 ); } /** @@ -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 ); @@ -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 ); @@ -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 ); diff --git a/plugins/dominant-color-images/tests/test-dominant-color.php b/plugins/dominant-color-images/tests/test-dominant-color.php index 2603e9f356..c4ad65afa1 100644 --- a/plugins/dominant-color-images/tests/test-dominant-color.php +++ b/plugins/dominant-color-images/tests/test-dominant-color.php @@ -27,7 +27,6 @@ public function test_dominant_color_metadata( string $image_path, array $expecte // Creating attachment. $attachment_id = self::factory()->attachment->create_upload_object( $image_path ); - wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) ); $dominant_color_metadata = dominant_color_metadata( array(), $attachment_id ); $this->assertArrayHasKey( 'dominant_color', $dominant_color_metadata ); $this->assertNotEmpty( $dominant_color_metadata['dominant_color'] ); @@ -78,7 +77,6 @@ public function test_has_transparency_metadata( string $image_path, array $expec $this->assertEmpty( $transparency_metadata ); $attachment_id = self::factory()->attachment->create_upload_object( $image_path ); - wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) ); $transparency_metadata = dominant_color_metadata( array(), $attachment_id ); $this->assertArrayHasKey( 'has_transparency', $transparency_metadata ); $this->assertSame( $expected_transparency, $transparency_metadata['has_transparency'] ); @@ -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. @@ -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 ); @@ -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 ); From 144813297c51e28cbb8cc795d09ab54c23d57997 Mon Sep 17 00:00:00 2001 From: Rashed Hossain Date: Thu, 27 Aug 2026 15:49:09 +0600 Subject: [PATCH 2/2] Dominant Color Images: Fix coding standards alignment in tests. --- plugins/dominant-color-images/tests/test-dominant-color.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/dominant-color-images/tests/test-dominant-color.php b/plugins/dominant-color-images/tests/test-dominant-color.php index c4ad65afa1..1307130d4d 100644 --- a/plugins/dominant-color-images/tests/test-dominant-color.php +++ b/plugins/dominant-color-images/tests/test-dominant-color.php @@ -26,7 +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 ); + $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'] ); @@ -76,7 +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 ); + $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'] );