@@ -148,6 +148,32 @@ public function testGetJsonSwatchConfigUsedProductImage(): void
148148 );
149149 }
150150
151+ /**
152+ * @magentoDataFixture Magento/Swatches/_files/configurable_product_with_visual_swatch_attribute.php
153+ * @magentoDataFixture Magento/Catalog/_files/product_image.php
154+ * @return void
155+ */
156+ public function testGetJsonSwatchConfigUsedWithSwatchImageType (): void
157+ {
158+ $ this ->updateAttributeUseProductImageFlag ();
159+ $ this ->updateProductImage ('simple_option_2 ' , '/m/a/magento_image.jpg ' );
160+ $ this ->setSwatchImage ('simple_option_2 ' , '/m/a/magento_image.jpg ' );
161+ $ expectedOptions = $ this ->getDefaultOptionsList ();
162+ $ expectedOptions ['option 2 ' ]['value ' ] = $ this ->imageUrlBuilder ->getUrl (
163+ '/m/a/magento_image.jpg ' ,
164+ 'swatch_image_base '
165+ );
166+ $ expectedOptions ['option 2 ' ]['thumb ' ] = $ this ->imageUrlBuilder ->getUrl (
167+ '/m/a/magento_image.jpg ' ,
168+ 'swatch_thumb_base '
169+ );
170+ $ this ->assertOptionsData (
171+ $ this ->serializer ->unserialize ($ this ->block ->getJsonSwatchConfig ()),
172+ $ expectedOptions ,
173+ ['swatch_input_type ' => 'visual ' , 'use_product_image_for_swatch ' => 1 ]
174+ );
175+ }
176+
151177 /**
152178 * @magentoDataFixture Magento/Swatches/_files/configurable_product_with_visual_swatch_attribute.php
153179 * @return void
@@ -249,4 +275,18 @@ private function updateProductImage(string $sku, string $imageName): void
249275 ->setCanSaveCustomOptions (true );
250276 $ this ->productResource ->save ($ product );
251277 }
278+
279+ /**
280+ * Set swatch image for a Product.
281+ *
282+ * @param string $sku
283+ * @param string $imageName
284+ * @return void
285+ */
286+ private function setSwatchImage (string $ sku , string $ imageName ): void
287+ {
288+ $ product = $ this ->productRepository ->get ($ sku );
289+ $ product ->setSwatchImage ($ imageName )->save ($ product );
290+ }
252291}
292+
0 commit comments