Skip to content

Commit bb49726

Browse files
author
Oleksii Korshenko
authored
Merge pull request #229 from magento-performance/MAGETWO-56582
[Performance] P0 bug
2 parents aaff5c0 + 9767984 commit bb49726

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function addMediaDataToProduct(Product $product, array $mediaEntries)
7878

7979
foreach ($mediaEntries as $mediaEntry) {
8080
$mediaEntry = $this->substituteNullsWithDefaultValues($mediaEntry);
81-
$value['images'][] = $mediaEntry;
81+
$value['images'][$mediaEntry['value_id']] = $mediaEntry;
8282
}
8383
$product->setData($attrCode, $value);
8484
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model\Product\Gallery;
7+
8+
/**
9+
* Unit test for catalog product Media Gallery ReadHandler
10+
*/
11+
class ReadHandlerTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/** @var \Magento\Catalog\Model\Product\Gallery\ReadHandler */
14+
protected $model;
15+
16+
/**
17+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
18+
*/
19+
protected $objectHelper;
20+
21+
/**
22+
* @var \Magento\Catalog\Model\Product\Attribute\Repository|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $attributeRepository;
25+
26+
protected function setUp()
27+
{
28+
$this->objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
29+
30+
$this->attributeRepository = $this->getMock(
31+
'Magento\Catalog\Model\Product\Attribute\Repository',
32+
['get'],
33+
[],
34+
'',
35+
false
36+
);
37+
$this->model = $this->objectHelper->getObject(
38+
\Magento\Catalog\Model\Product\Gallery\ReadHandler::class,
39+
[
40+
'attributeRepository' => $this->attributeRepository,
41+
]
42+
);
43+
}
44+
45+
public function testAddMediaDataToProduct()
46+
{
47+
$attribute = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute::class)
48+
->disableOriginalConstructor()
49+
->getMock();
50+
51+
$attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue('image'));
52+
53+
$this->attributeRepository->expects($this->once())
54+
->method('get')
55+
->with('media_gallery')
56+
->willReturn($attribute);
57+
58+
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$product->expects($this->once())->method('setData')->with(
62+
'image',
63+
[
64+
'images' =>[
65+
10 => ['value_id' => 10,]
66+
],
67+
'values' => []
68+
]
69+
);
70+
$this->model->addMediaDataToProduct($product, [['value_id' => 10]]);
71+
}
72+
}

0 commit comments

Comments
 (0)