Commit 4060fe7573c for woocommerce

commit 4060fe7573cab078ca705e8e4d2d365dff435c0e
Author: Lucio Giannotta <lucio.giannotta@a8c.com>
Date:   Thu May 21 16:34:57 2026 +0800

    Fix variation gallery tests

diff --git a/plugins/woocommerce/src/Internal/VariationGallery/Migration.php b/plugins/woocommerce/src/Internal/VariationGallery/Migration.php
index 93b32c672ba..2eb71304f4b 100644
--- a/plugins/woocommerce/src/Internal/VariationGallery/Migration.php
+++ b/plugins/woocommerce/src/Internal/VariationGallery/Migration.php
@@ -67,7 +67,9 @@ class Migration {
 		$variation_ids = $select_variation_ids( self::BATCH_SIZE );

 		foreach ( $variation_ids as $variation_id ) {
-			$legacy_gallery_image_ids = wp_parse_id_list( get_post_meta( $variation_id, $legacy_meta_key, true ) );
+			$legacy_gallery_image_ids = array_values(
+				array_filter( wp_parse_id_list( get_post_meta( $variation_id, $legacy_meta_key, true ) ) )
+			);
 			$core_gallery_image_ids   = wp_parse_id_list( get_post_meta( $variation_id, $core_gallery_meta, true ) );

 			if ( empty( $core_gallery_image_ids ) && ! empty( $legacy_gallery_image_ids ) ) {
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-product-variable-test.php b/plugins/woocommerce/tests/php/includes/class-wc-product-variable-test.php
index 7e8a2716c8d..c7c446db40f 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-product-variable-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-product-variable-test.php
@@ -292,8 +292,8 @@ class WC_Product_Variable_Test extends \WC_Unit_Test_Case {
 		$available_variation = $product->get_available_variation( $variation );

 		$this->assertSame( $variation_gallery_id, $available_variation['image_id'] );
-		$this->assertStringContainsString( 'wp-image-' . $variation_gallery_id, $available_variation['gallery_images_html'] );
-		$this->assertStringNotContainsString( 'wp-image-' . $parent_featured_id, $available_variation['gallery_images_html'] );
+		$this->assertStringContainsString( 'variation-gallery.jpg', $available_variation['gallery_images_html'] );
+		$this->assertStringNotContainsString( 'parent-featured.jpg', $available_variation['gallery_images_html'] );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/VariationGallery/ClassicVariationGalleryAdminTest.php b/plugins/woocommerce/tests/php/src/Internal/VariationGallery/ClassicVariationGalleryAdminTest.php
index b9681cf1628..d13f130b9e1 100644
--- a/plugins/woocommerce/tests/php/src/Internal/VariationGallery/ClassicVariationGalleryAdminTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/VariationGallery/ClassicVariationGalleryAdminTest.php
@@ -21,17 +21,29 @@ class ClassicVariationGalleryAdminTest extends \WC_Unit_Test_Case {
 	private $sut;

 	/**
-	 * Set up test dependencies.
+	 * @var LegacyVariationGalleryCompatibility
+	 */
+	private $legacy_compat;
+
+	/**
+	 * Set up.
 	 */
 	public function setUp(): void {
 		parent::setUp();
-		$this->sut = new ClassicVariationGalleryAdmin();
+		$this->sut           = new ClassicVariationGalleryAdmin();
+		$this->legacy_compat = new LegacyVariationGalleryCompatibility();
+		$this->legacy_compat->register();
 	}

 	/**
-	 * Reset globals after each test.
+	 * Tear down.
 	 */
 	public function tearDown(): void {
+		remove_filter(
+			'woocommerce_product_variation_get_gallery_image_ids',
+			array( $this->legacy_compat, 'maybe_read_legacy_gallery_image_ids' ),
+			10
+		);
 		unset( $_POST['variable_gallery_image_ids'] );
 		parent::tearDown();
 	}
@@ -198,18 +210,20 @@ class ClassicVariationGalleryAdminTest extends \WC_Unit_Test_Case {
 	}

 	/**
-	 * Create a test attachment.
-	 *
 	 * @param string $title Attachment title.
 	 * @return int
 	 */
 	private function create_attachment( string $title ): int {
-		return wp_insert_attachment(
+		$attachment_id = wp_insert_attachment(
 			array(
 				'post_title'     => $title,
 				'post_type'      => 'attachment',
 				'post_mime_type' => 'image/jpeg',
 			)
 		);
+
+		update_post_meta( $attachment_id, '_wp_attached_file', sanitize_title( $title ) . '.jpg' );
+
+		return $attachment_id;
 	}
 }