Skip to content

Commit 3ae8cf4

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into bugfix
2 parents 6d87d7c + 4bc9fcc commit 3ae8cf4

File tree

42 files changed

+1039
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1039
-67
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/credentials.xml.dist

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232
<field path="payment/authorizenet_directpost/trans_key" value="" />
3333
<field path="payment/authorizenet_directpost/trans_md5" value="" />
3434

35-
<field path="payment/braintree_section/braintree/braintree_advanced/merchant_account_id" value="" />
36-
<field path="payment/braintree_section/braintree/braintree_required/merchant_id" value="" />
37-
<field path="payment/braintree_section/braintree/braintree_required/public_key" value="" />
38-
<field path="payment/braintree_section/braintree/braintree_required/private_key" value="" />
35+
<field replace="braintree_enabled_fraud_merchant_account_id" value="" />
36+
<field replace="braintree_enabled_fraud_merchant_id" value="" />
37+
<field replace="braintree_enabled_fraud_public_key" value="" />
38+
<field replace="braintree_enabled_fraud_private_key" value="" />
39+
40+
<field replace="braintree_disabled_fraud_merchant_account_id" value="" />
41+
<field replace="braintree_disabled_fraud_merchant_id" value="" />
42+
<field replace="braintree_disabled_fraud_public_key" value="" />
43+
<field replace="braintree_disabled_fraud_private_key" value="" />
3944

4045
<field path="payment/paypal_group_all_in_one/wpp_usuk/wpp_required_settings/wpp_and_express_checkout/business_account" value="" />
4146
<field path="payment/paypal_group_all_in_one/wpp_usuk/wpp_required_settings/wpp_and_express_checkout/api_username" value="" />

0 commit comments

Comments
 (0)