Skip to content

Commit e64180c

Browse files
committed
Merge branch 'MC-39702' into 2.4-develop-sidecar-pr9
2 parents c4bf6a4 + c505601 commit e64180c

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

dev/tests/integration/testsuite/Magento/Swatches/Block/Product/Renderer/ConfigurableTest.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@ 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', ['swatch_image']);
160+
$expectedOptions = $this->getDefaultOptionsList();
161+
$expectedOptions['option 2']['value'] = $this->imageUrlBuilder->getUrl(
162+
'/m/a/magento_image.jpg',
163+
'swatch_image_base'
164+
);
165+
$expectedOptions['option 2']['thumb'] = $this->imageUrlBuilder->getUrl(
166+
'/m/a/magento_image.jpg',
167+
'swatch_thumb_base'
168+
);
169+
$this->assertOptionsData(
170+
$this->serializer->unserialize($this->block->getJsonSwatchConfig()),
171+
$expectedOptions,
172+
['swatch_input_type' => 'visual', 'use_product_image_for_swatch' => 1]
173+
);
174+
}
175+
151176
/**
152177
* @magentoDataFixture Magento/Swatches/_files/configurable_product_with_visual_swatch_attribute.php
153178
* @return void
@@ -223,15 +248,16 @@ private function updateAttributeUseProductImageFlag(): void
223248
*
224249
* @param string $sku
225250
* @param string $imageName
251+
* @param array $imageRoles
226252
* @return void
227253
*/
228-
private function updateProductImage(string $sku, string $imageName): void
229-
{
254+
private function updateProductImage(
255+
string $sku,
256+
string $imageName,
257+
array $imageRoles = ['image', 'small_image', 'thumbnail']
258+
): void {
230259
$product = $this->productRepository->get($sku);
231260
$product->setStoreId(Store::DEFAULT_STORE_ID)
232-
->setImage($imageName)
233-
->setSmallImage($imageName)
234-
->setThumbnail($imageName)
235261
->setData(
236262
'media_gallery',
237263
[
@@ -247,6 +273,10 @@ private function updateProductImage(string $sku, string $imageName): void
247273
]
248274
)
249275
->setCanSaveCustomOptions(true);
276+
foreach ($imageRoles as $role) {
277+
$product->setData($role, $imageName);
278+
}
279+
250280
$this->productResource->save($product);
251281
}
252282
}

0 commit comments

Comments
 (0)