Skip to content

Commit c4dc7c3

Browse files
committed
MAGETWO-58053: [GITHUB] Product image issue with multiple store views Magento 2.1.0 #6259
1 parent c4d4654 commit c4dc7c3

File tree

1 file changed

+90
-37
lines changed

1 file changed

+90
-37
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Gallery/CreateHandlerTest.php

Lines changed: 90 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ public function testExecuteWithImageDuplicate()
5959
}
6060

6161
/**
62-
* @covers \Magento\Catalog\Model\Product\Gallery\CreateHandler::execute
6362
* @dataProvider executeDataProvider
64-
* @param array $expectedValues
63+
* @param $image
64+
* @param $smallImage
65+
* @param $swatchImage
66+
* @param $thumbnail
6567
*/
66-
public function testExecuteWithImageRoles($expectedValues)
68+
public function testExecuteWithImageRoles($image, $smallImage, $swatchImage, $thumbnail)
6769
{
6870
/** @var $product \Magento\Catalog\Model\Product */
6971
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
@@ -74,55 +76,106 @@ public function testExecuteWithImageRoles($expectedValues)
7476
'media_gallery',
7577
['images' => ['image' => ['file' => $this->fileName, 'label' => '']]]
7678
);
77-
foreach ($expectedValues as $mediaAttribute => $value) {
78-
if ($value) {
79-
$product->setData($mediaAttribute, $value);
80-
}
81-
}
79+
$product->setData('image', $image);
80+
$product->setData('small_image', $smallImage);
81+
$product->setData('swatch_image', $swatchImage);
82+
$product->setData('thumbnail', $thumbnail);
8283
$this->createHandler->execute($product);
84+
85+
$resource = $product->getResource();
86+
$id = $product->getId();
87+
$storeId = $product->getStoreId();
88+
8389
$this->assertStringStartsWith('/m/a/magento_image', $product->getData('media_gallery/images/image/new_file'));
90+
$this->assertEquals(
91+
$image,
92+
$resource->getAttributeRawValue($id, $resource->getAttribute('image'), $storeId)
93+
);
94+
$this->assertEquals(
95+
$smallImage,
96+
$resource->getAttributeRawValue($id, $resource->getAttribute('small_image'), $storeId)
97+
);
98+
$this->assertEquals(
99+
$swatchImage,
100+
$resource->getAttributeRawValue($id, $resource->getAttribute('swatch_image'), $storeId)
101+
);
102+
$this->assertEquals(
103+
$thumbnail,
104+
$resource->getAttributeRawValue($id, $resource->getAttribute('thumbnail'),$storeId)
105+
);
106+
}
107+
108+
/**
109+
* @dataProvider executeDataProvider
110+
* @param $image
111+
* @param $smallImage
112+
* @param $swatchImage
113+
* @param $thumbnail
114+
*/
115+
public function testExecuteWithoutImages($image, $smallImage, $swatchImage, $thumbnail)
116+
{
117+
/** @var $product \Magento\Catalog\Model\Product */
118+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
119+
\Magento\Catalog\Model\Product::class
120+
);
121+
$product->load(1);
122+
$product->setData(
123+
'media_gallery',
124+
['images' => ['image' => ['file' => $this->fileName, 'label' => '']]]
125+
);
126+
$product->setData('image', $image);
127+
$product->setData('small_image', $smallImage);
128+
$product->setData('swatch_image', $swatchImage);
129+
$product->setData('thumbnail', $thumbnail);
130+
$this->createHandler->execute($product);
131+
132+
$product->unsetData('image');
133+
$product->unsetData('small_image');
134+
$product->unsetData('swatch_image');
135+
$product->unsetData('thumbnail');
136+
$this->createHandler->execute($product);
137+
84138
$resource = $product->getResource();
85-
$attributeValues = [];
86-
foreach (array_keys($expectedValues) as $mediaAttribute) {
87-
$attributeValues[$mediaAttribute] = $resource->getAttributeRawValue(
88-
$product->getId(),
89-
$resource->getAttribute($mediaAttribute),
90-
$product->getStoreId()
91-
);
92-
}
139+
$id = $product->getId();
140+
$storeId = $product->getStoreId();
141+
93142
$this->assertStringStartsWith('/m/a/magento_image', $product->getData('media_gallery/images/image/new_file'));
94-
$this->assertEquals($expectedValues, $attributeValues);
143+
$this->assertEquals(
144+
$image,
145+
$resource->getAttributeRawValue($id, $resource->getAttribute('image'), $storeId)
146+
);
147+
$this->assertEquals(
148+
$smallImage,
149+
$resource->getAttributeRawValue($id, $resource->getAttribute('small_image'), $storeId)
150+
);
151+
$this->assertEquals(
152+
$swatchImage,
153+
$resource->getAttributeRawValue($id, $resource->getAttribute('swatch_image'), $storeId)
154+
);
155+
$this->assertEquals(
156+
$thumbnail,
157+
$resource->getAttributeRawValue($id, $resource->getAttribute('thumbnail'),$storeId)
158+
);
95159
}
96160

161+
97162
/**
98163
* @return array
99164
*/
100165
public function executeDataProvider()
101166
{
102167
return [
103168
[
104-
[
105-
'image' => $this->fileName,
106-
'small_image' => $this->fileName,
107-
'swatch_image' => $this->fileName,
108-
'thumbnail' => $this->fileName
109-
]
110-
],
111-
[
112-
[
113-
'image' => 'no_selection',
114-
'small_image' => 'no_selection',
115-
'swatch_image' => 'no_selection',
116-
'thumbnail' => 'no_selection'
117-
]
169+
'image' => $this->fileName,
170+
'small_image' => $this->fileName,
171+
'swatch_image' => $this->fileName,
172+
'thumbnail' => $this->fileName
118173
],
119174
[
120-
[
121-
'image' => null,
122-
'small_image' => null,
123-
'swatch_image' => null,
124-
'thumbnail' => null
125-
]
175+
'image' => 'no_selection',
176+
'small_image' => 'no_selection',
177+
'swatch_image' => 'no_selection',
178+
'thumbnail' => 'no_selection'
126179
]
127180
];
128181
}

0 commit comments

Comments
 (0)