Skip to content

Commit 84f93ad

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-61132
2 parents ec2f926 + b241a65 commit 84f93ad

File tree

7 files changed

+86
-16
lines changed

7 files changed

+86
-16
lines changed

app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ public function update($sku, ProductAttributeMediaGalleryEntryInterface $entry)
9494
}
9595
$found = false;
9696
foreach ($existingMediaGalleryEntries as $key => $existingEntry) {
97+
$entryTypes = (array)$entry->getTypes();
98+
$existingEntryTypes = (array)$existingMediaGalleryEntries[$key]->getTypes();
99+
$existingMediaGalleryEntries[$key]->setTypes(array_diff($existingEntryTypes, $entryTypes));
100+
97101
if ($existingEntry->getId() == $entry->getId()) {
98102
$found = true;
99103
if ($entry->getFile()) {
100104
$entry->setId(null);
101105
}
102106
$existingMediaGalleryEntries[$key] = $entry;
103-
break;
104107
}
105108
}
106109
if (!$found) {

app/code/Magento/Catalog/Model/Product/Gallery/Processor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ public function clearMediaAttribute(\Magento\Catalog\Model\Product $product, $me
298298
if (is_array($mediaAttribute)) {
299299
foreach ($mediaAttribute as $attribute) {
300300
if (in_array($attribute, $mediaAttributeCodes)) {
301-
$product->setData($attribute, null);
301+
$product->setData($attribute, 'no_selection');
302302
}
303303
}
304304
} elseif (in_array($mediaAttribute, $mediaAttributeCodes)) {
305-
$product->setData($mediaAttribute, null);
305+
$product->setData($mediaAttribute, 'no_selection');
306306
}
307307

308308
return $this;

app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/GalleryManagementTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,33 @@ public function testUpdate()
191191
$productSku = 'testProduct';
192192
$entryMock = $this->getMock(\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class);
193193
$entryId = 42;
194+
$entrySecondId = 43;
194195
$this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)
195196
->willReturn($this->productMock);
196197
$existingEntryMock = $this->getMock(
197198
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class
198199
);
200+
$existingSecondEntryMock = $this->getMock(
201+
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class
202+
);
203+
199204
$existingEntryMock->expects($this->once())->method('getId')->willReturn($entryId);
205+
$existingEntryMock->expects($this->once())->method('getTypes')->willReturn(['small_image']);
206+
$existingEntryMock->expects($this->once())->method('setTypes')->with(['small_image']);
207+
$existingSecondEntryMock->expects($this->once())->method('getId')->willReturn($entrySecondId);
208+
$existingSecondEntryMock->expects($this->once())->method('getTypes')->willReturn(['image']);
209+
$existingSecondEntryMock->expects($this->once())->method('setTypes')->with([]);
200210
$this->productMock->expects($this->once())->method('getMediaGalleryEntries')
201-
->willReturn([$existingEntryMock]);
202-
$entryMock->expects($this->once())->method('getId')->willReturn($entryId);
211+
->willReturn([$existingEntryMock, $existingSecondEntryMock]);
212+
213+
$entryMock->expects($this->exactly(2))->method('getId')->willReturn($entryId);
203214
$entryMock->expects($this->once())->method('getFile')->willReturn("base64");
204215
$entryMock->expects($this->once())->method('setId')->with(null);
216+
$entryMock->expects($this->exactly(2))->method('getTypes')->willReturn(['image']);
205217

206218
$this->productMock->expects($this->once())->method('setMediaGalleryEntries')
207-
->willReturn([$entryMock]);
219+
->with([$entryMock, $existingSecondEntryMock])
220+
->willReturnSelf();
208221
$this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock);
209222
$this->assertTrue($this->model->update($productSku, $entryMock));
210223
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/ProcessorTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,56 @@ public function validateDataProvider()
197197
[false]
198198
];
199199
}
200+
201+
/**
202+
* @param int $setDataExpectsCalls
203+
* @param string|null $setDataArgument
204+
* @param array|string $mediaAttribute
205+
* @dataProvider clearMediaAttributeDataProvider
206+
*/
207+
public function testClearMediaAttribute($setDataExpectsCalls, $setDataArgument, $mediaAttribute)
208+
{
209+
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
210+
->disableOriginalConstructor()
211+
->getMock();
212+
213+
$productMock->expects($this->exactly($setDataExpectsCalls))
214+
->method('setData')
215+
->with($setDataArgument, 'no_selection');
216+
217+
$this->mediaConfig->expects($this->once())
218+
->method('getMediaAttributeCodes')
219+
->willReturn(['image', 'small_image']);
220+
221+
$this->assertSame($this->model, $this->model->clearMediaAttribute($productMock, $mediaAttribute));
222+
}
223+
224+
/**
225+
* @return array
226+
*/
227+
public function clearMediaAttributeDataProvider()
228+
{
229+
return [
230+
[
231+
'setDataExpectsCalls' => 1,
232+
'setDataArgument' => 'image',
233+
'mediaAttribute' => 'image',
234+
],
235+
[
236+
'setDataExpectsCalls' => 1,
237+
'setDataArgument' => 'image',
238+
'mediaAttribute' => ['image'],
239+
],
240+
[
241+
'setDataExpectsCalls' => 0,
242+
'setDataArgument' => null,
243+
'mediaAttribute' => 'some_image',
244+
],
245+
[
246+
'setDataExpectsCalls' => 0,
247+
'setDataArgument' => null,
248+
'mediaAttribute' => ['some_image'],
249+
],
250+
];
251+
}
200252
}

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ public function testUpdate()
237237

238238
$targetProduct = $this->getTargetSimpleProduct();
239239
$this->assertEquals('/m/a/magento_image.jpg', $targetProduct->getData('thumbnail'));
240-
$this->assertNull($targetProduct->getData('image'));
241-
$this->assertNull($targetProduct->getData('small_image'));
240+
$this->assertEquals('no_selection', $targetProduct->getData('image'));
241+
$this->assertEquals('no_selection', $targetProduct->getData('small_image'));
242242
$mediaGallery = $targetProduct->getData('media_gallery');
243243
$this->assertCount(1, $mediaGallery['images']);
244244
$updatedImage = array_shift($mediaGallery['images']);

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,16 @@ public function waitLoader()
522522
}
523523

524524
/**
525-
* Check id media gallery is visible for the product.
525+
* Check if media gallery is visible for the product.
526526
*
527527
* @return bool
528528
*/
529529
public function isGalleryVisible()
530530
{
531531
$this->waitForElementNotVisible($this->galleryLoader);
532-
return $this->_rootElement->find($this->mediaGallery)->isVisible();
532+
$this->waitForElementVisible($this->mediaGallery);
533+
534+
return true;
533535
}
534536

535537
/**

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ public function testClearMediaAttribute()
146146
);
147147
$product->setData(['image' => 'test1', 'small_image' => 'test2', 'thumbnail' => 'test3']);
148148

149-
$this->assertNotEmpty($product->getData('image'));
149+
$this->assertNotEquals('no_selection', $product->getData('image'));
150150
$this->_model->clearMediaAttribute($product, 'image');
151-
$this->assertNull($product->getData('image'));
151+
$this->assertEquals('no_selection', $product->getData('image'));
152152

153-
$this->assertNotEmpty($product->getData('small_image'));
154-
$this->assertNotEmpty($product->getData('thumbnail'));
153+
$this->assertNotEquals('no_selection', $product->getData('small_image'));
154+
$this->assertNotEquals('no_selection', $product->getData('thumbnail'));
155155
$this->_model->clearMediaAttribute($product, ['small_image', 'thumbnail']);
156-
$this->assertNull($product->getData('small_image'));
157-
$this->assertNull($product->getData('thumbnail'));
156+
$this->assertEquals('no_selection', $product->getData('small_image'));
157+
$this->assertEquals('no_selection', $product->getData('thumbnail'));
158158
}
159159

160160
public function testSetMediaAttribute()

0 commit comments

Comments
 (0)