@@ -148,6 +148,32 @@ public function testGetJsonSwatchConfigUsedProductImage(): void
148
148
);
149
149
}
150
150
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
+
151
177
/**
152
178
* @magentoDataFixture Magento/Swatches/_files/configurable_product_with_visual_swatch_attribute.php
153
179
* @return void
@@ -249,4 +275,18 @@ private function updateProductImage(string $sku, string $imageName): void
249
275
->setCanSaveCustomOptions (true );
250
276
$ this ->productResource ->save ($ product );
251
277
}
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
+ }
252
291
}
292
+
0 commit comments