Skip to content

Commit 99b2f80

Browse files
committed
Merge branch '2.1-develop' of github.com:magento/magento2ce into MAGETWO-59078
2 parents 8aaf63d + 391e33e commit 99b2f80

File tree

6 files changed

+184
-10
lines changed

6 files changed

+184
-10
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,12 +2211,17 @@ public function addMediaGalleryData()
22112211

22122212
$mediaGalleries = [];
22132213
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
2214+
$items = $this->getItems();
2215+
2216+
$select->where('entity.' . $linkField . ' IN (?)', array_map(function ($item) {
2217+
return $item->getId();
2218+
}, $items));
22142219

22152220
foreach ($this->getConnection()->fetchAll($select) as $row) {
22162221
$mediaGalleries[$row[$linkField]][] = $row;
22172222
}
22182223

2219-
foreach ($this->getItems() as $item) {
2224+
foreach ($items as $item) {
22202225
$mediaEntries = isset($mediaGalleries[$item->getId()]) ? $mediaGalleries[$item->getId()] : [];
22212226
$this->getGalleryReadHandler()->addMediaDataToProduct($item, $mediaEntries);
22222227
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
protected $collection;
3030

31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $galleryResourceMock;
35+
36+
/**
37+
* @var \PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $entityMock;
40+
41+
/**
42+
* @var \PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $metadataPoolMock;
45+
46+
/**
47+
* @var \PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $galleryReadHandlerMock;
50+
3151
/**
3252
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
3353
*/
@@ -98,25 +118,49 @@ protected function setUp()
98118
->disableOriginalConstructor()
99119
->getMock();
100120

101-
$entityMock = $this->getMockBuilder('Magento\Eav\Model\Entity\AbstractEntity')
121+
$this->entityMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AbstractEntity::class)
102122
->disableOriginalConstructor()
103123
->getMock();
104124

125+
$this->galleryResourceMock = $this->getMockBuilder(
126+
\Magento\Catalog\Model\ResourceModel\Product\Gallery::class
127+
)->disableOriginalConstructor()->getMock();
128+
129+
$this->metadataPoolMock = $this->getMockBuilder(
130+
\Magento\Framework\EntityManager\MetadataPool::class
131+
)->disableOriginalConstructor()->getMock();
132+
133+
$this->galleryReadHandlerMock = $this->getMockBuilder(
134+
\Magento\Catalog\Model\Product\Gallery\ReadHandler::class
135+
)->disableOriginalConstructor()->getMock();
136+
105137
$storeManager->expects($this->any())->method('getId')->willReturn(1);
106138
$storeManager->expects($this->any())->method('getStore')->willReturnSelf();
107139
$universalFactory->expects($this->exactly(1))->method('create')->willReturnOnConsecutiveCalls(
108-
$entityMock
140+
$this->entityMock
109141
);
110-
$entityMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
111-
$entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn([]);
112-
$entityMock->expects($this->any())->method('getTable')->willReturnArgument(0);
142+
$this->entityMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
143+
$this->entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn([]);
144+
$this->entityMock->expects($this->any())->method('getTable')->willReturnArgument(0);
113145
$this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock);
114146
$helper = new ObjectManager($this);
115147

116148
$this->prepareObjectManager([
117149
[
118150
'Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation',
119151
$this->getMock('Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation')
152+
],
153+
[
154+
\Magento\Catalog\Model\ResourceModel\Product\Gallery::class,
155+
$this->galleryResourceMock
156+
],
157+
[
158+
\Magento\Framework\EntityManager\MetadataPool::class,
159+
$this->metadataPoolMock
160+
],
161+
[
162+
\Magento\Catalog\Model\Product\Gallery\ReadHandler::class,
163+
$this->galleryReadHandlerMock
120164
]
121165
]);
122166
$this->collection = $helper->getObject(
@@ -173,6 +217,47 @@ public function testAddProductCategoriesFilter()
173217
$this->collection->addCategoriesFilter([$conditionType => $values]);
174218
}
175219

220+
public function testAddMediaGalleryData()
221+
{
222+
$attributeId = 42;
223+
$itemId = 4242;
224+
$linkField = 'entity_id';
225+
$mediaGalleriesMock = [[$linkField => $itemId]];
226+
$itemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
227+
->disableOriginalConstructor()
228+
->getMock();
229+
$attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
230+
->disableOriginalConstructor()
231+
->getMock();
232+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
233+
->disableOriginalConstructor()
234+
->getMock();
235+
$metadataMock = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadataInterface::class)
236+
->disableOriginalConstructor()
237+
->getMock();
238+
$this->collection->addItem($itemMock);
239+
$reflection = new \ReflectionClass(get_class($this->collection));
240+
$reflectionProperty = $reflection->getProperty('_isCollectionLoaded');
241+
$reflectionProperty->setAccessible(true);
242+
$reflectionProperty->setValue($this->collection, true);
243+
244+
$this->galleryResourceMock->expects($this->once())->method('createBatchBaseSelect')->willReturn($selectMock);
245+
$attributeMock->expects($this->once())->method('getAttributeId')->willReturn($attributeId);
246+
$this->entityMock->expects($this->once())->method('getAttribute')->willReturn($attributeMock);
247+
$itemMock->expects($this->atLeastOnce())->method('getId')->willReturn($itemId);
248+
$selectMock->expects($this->once())->method('where')->with('entity.' . $linkField . ' IN (?)', [$itemId]);
249+
$this->metadataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadataMock);
250+
$metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField);
251+
252+
$this->connectionMock->expects($this->once())->method('fetchAll')->with($selectMock)->willReturn(
253+
[['entity_id' => $itemId]]
254+
);
255+
$this->galleryReadHandlerMock->expects($this->once())->method('addMediaDataToProduct')
256+
->with($itemMock, $mediaGalleriesMock);
257+
258+
$this->assertSame($this->collection, $this->collection->addMediaGalleryData());
259+
}
260+
176261
/**
177262
* @param $map
178263
*/

app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Framework\Validator\Locale;
1818
use Magento\Deploy\Console\Command\DeployStaticOptionsInterface as Options;
1919
use Magento\Deploy\Model\DeployManager;
20+
use Magento\Framework\App\Cache;
21+
use Magento\Framework\App\Cache\Type\Dummy as DummyCache;
2022

2123
/**
2224
* Deploy static content command
@@ -380,6 +382,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
380382
}
381383
}
382384

385+
$this->mockCache();
383386
return $deployManager->deploy();
384387
}
385388

@@ -441,4 +444,18 @@ private function prepareDeployableEntities($filesUtil)
441444

442445
return [$deployableLanguages, $deployableAreaThemeMap, $requestedThemes];
443446
}
447+
448+
/**
449+
* Mock Cache class with dummy implementation
450+
*
451+
* @return void
452+
*/
453+
private function mockCache()
454+
{
455+
$this->objectManager->configure([
456+
'preferences' => [
457+
Cache::class => DummyCache::class
458+
]
459+
]);
460+
}
444461
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\App\Cache\Type;
7+
8+
use Magento\Framework\App\CacheInterface;
9+
10+
/**
11+
* Dummy cache adapter
12+
*
13+
* for cases when need to disable interaction with cache
14+
* but no specific cache type is used
15+
*/
16+
class Dummy implements CacheInterface
17+
{
18+
/**
19+
* Required by CacheInterface
20+
*
21+
* @return null
22+
*/
23+
public function getFrontend()
24+
{
25+
return null;
26+
}
27+
28+
/**
29+
* Pretend to load data from cache by id
30+
*
31+
* {@inheritdoc}
32+
*/
33+
public function load($identifier)
34+
{
35+
return null;
36+
}
37+
38+
/**
39+
* Pretend to save data
40+
*
41+
* {@inheritdoc}
42+
*/
43+
public function save($data, $identifier, $tags = [], $lifeTime = null)
44+
{
45+
return false;
46+
}
47+
48+
/**
49+
* Pretend to remove cached data by identifier
50+
*
51+
* {@inheritdoc}
52+
*/
53+
public function remove($identifier)
54+
{
55+
return true;
56+
}
57+
58+
/**
59+
* Pretend to clean cached data by specific tag
60+
*
61+
* {@inheritdoc}
62+
*/
63+
public function clean($tags = [])
64+
{
65+
return true;
66+
}
67+
}

lib/internal/Magento/Framework/View/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getViewConfig(array $params = [])
6262
if (isset($params['themeModel'])) {
6363
/** @var \Magento\Framework\View\Design\ThemeInterface $currentTheme */
6464
$currentTheme = $params['themeModel'];
65-
$key = $currentTheme->getCode();
65+
$key = $currentTheme->getFullPath();
6666
if (isset($this->viewConfigs[$key])) {
6767
return $this->viewConfigs[$key];
6868
}

lib/internal/Magento/Framework/View/Test/Unit/ConfigTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ protected function setUp()
4040

4141
public function testGetViewConfig()
4242
{
43-
$themeCode = 2;
43+
$themeCode = 'area/theme';
4444

4545
$themeMock = $this->getMock(
4646
'Magento\Theme\Model\Theme',
47-
['getCode'],
47+
['getFullPath'],
4848
[],
4949
'',
5050
false
5151
);
5252
$themeMock->expects($this->atLeastOnce())
53-
->method('getCode')
53+
->method('getFullPath')
5454
->will($this->returnValue($themeCode));
5555
$params = [
5656
'themeModel' => $themeMock,

0 commit comments

Comments
 (0)