Skip to content

Commit feaab79

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into api_coverage
2 parents dd6edae + ab23fb9 commit feaab79

File tree

48 files changed

+1767
-99
lines changed

Some content is hidden

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

48 files changed

+1767
-99
lines changed

app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,40 @@ class NewWidget extends \Magento\Catalog\Block\Product\NewProduct implements \Ma
4444
*/
4545
protected $_pager;
4646

47+
/**
48+
* @var \Magento\Framework\Serialize\Serializer\Json
49+
*/
50+
private $serializer;
51+
52+
/**
53+
* NewWidget constructor.
54+
*
55+
* @param \Magento\Catalog\Block\Product\Context $context
56+
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
57+
* @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
58+
* @param \Magento\Framework\App\Http\Context $httpContext
59+
* @param array $data
60+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
61+
*/
62+
public function __construct(
63+
\Magento\Catalog\Block\Product\Context $context,
64+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
65+
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
66+
\Magento\Framework\App\Http\Context $httpContext,
67+
array $data = [],
68+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
69+
) {
70+
parent::__construct(
71+
$context,
72+
$productCollectionFactory,
73+
$catalogProductVisibility,
74+
$httpContext,
75+
$data
76+
);
77+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
78+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
79+
}
80+
4781
/**
4882
* Product collection initialize process
4983
*
@@ -106,7 +140,7 @@ public function getCacheKeyInfo()
106140
$this->getDisplayType(),
107141
$this->getProductsPerPage(),
108142
intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)),
109-
serialize($this->getRequest()->getParams())
143+
$this->serializer->serialize($this->getRequest()->getParams())
110144
]
111145
);
112146
}

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
140140
*/
141141
private $collectionProcessor;
142142

143+
/**
144+
* @var \Magento\Framework\Serialize\Serializer\Json
145+
*/
146+
private $serializer;
147+
143148
/**
144149
* ProductRepository constructor.
145150
* @param ProductFactory $productFactory
@@ -163,6 +168,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
163168
* @param ImageProcessorInterface $imageProcessor
164169
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
165170
* @param CollectionProcessorInterface $collectionProcessor
171+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
166172
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
167173
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
168174
*/
@@ -187,7 +193,8 @@ public function __construct(
187193
MimeTypeExtensionMap $mimeTypeExtensionMap,
188194
ImageProcessorInterface $imageProcessor,
189195
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
190-
CollectionProcessorInterface $collectionProcessor = null
196+
CollectionProcessorInterface $collectionProcessor = null,
197+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
191198
) {
192199
$this->productFactory = $productFactory;
193200
$this->collectionFactory = $collectionFactory;
@@ -207,6 +214,8 @@ public function __construct(
207214
$this->imageProcessor = $imageProcessor;
208215
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
209216
$this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
217+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
218+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
210219
}
211220

212221
/**
@@ -275,8 +284,8 @@ protected function getCacheKey($data)
275284
$serializeData[$key] = $value;
276285
}
277286
}
278-
279-
return md5(serialize($serializeData));
287+
$serializeData = $this->serializer->serialize($serializeData);
288+
return md5($serializeData);
280289
}
281290

282291
/**

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Category extends AbstractResource
9292
* @param Category\TreeFactory $categoryTreeFactory
9393
* @param Category\CollectionFactory $categoryCollectionFactory
9494
* @param array $data
95+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
9596
*/
9697
public function __construct(
9798
\Magento\Eav\Model\Entity\Context $context,
@@ -100,7 +101,8 @@ public function __construct(
100101
\Magento\Framework\Event\ManagerInterface $eventManager,
101102
\Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryTreeFactory,
102103
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
103-
$data = []
104+
$data = [],
105+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
104106
) {
105107
parent::__construct(
106108
$context,
@@ -112,6 +114,8 @@ public function __construct(
112114
$this->_categoryCollectionFactory = $categoryCollectionFactory;
113115
$this->_eventManager = $eventManager;
114116
$this->connectionName = 'catalog';
117+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
118+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
115119
}
116120

117121
/**
@@ -580,7 +584,8 @@ public function getIsActiveAttributeId()
580584
*/
581585
public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
582586
{
583-
$entityIdsFilterHash = md5(serialize($entityIdsFilter));
587+
$serializeData = $this->serializer->serialize($entityIdsFilter);
588+
$entityIdsFilterHash = md5($serializeData);
584589

585590
if (!isset($this->entitiesWhereAttributesIs[$entityIdsFilterHash][$attribute->getId()][$expectedValue])) {
586591
$linkField = $this->getLinkField();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public function createBatchBaseSelect($storeId, $attributeId)
177177
[
178178
$mainTableAlias . '.value_id = value.value_id',
179179
$this->getConnection()->quoteInto('value.store_id = ?', (int)$storeId),
180+
'value.' . $linkField . ' = entity.' . $linkField,
180181
]
181182
),
182183
['label', 'position', 'disabled']
@@ -187,6 +188,7 @@ public function createBatchBaseSelect($storeId, $attributeId)
187188
[
188189
$mainTableAlias . '.value_id = default_value.value_id',
189190
$this->getConnection()->quoteInto('default_value.store_id = ?', Store::DEFAULT_STORE_ID),
191+
'default_value.' . $linkField . ' = entity.' . $linkField,
190192
]
191193
),
192194
['label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled']

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1616
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1717
use Magento\Store\Api\Data\StoreInterface;
18+
use Magento\Framework\Serialize\Serializer\Json;
1819

1920
/**
2021
* Class ProductRepositoryTest
@@ -147,6 +148,11 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase
147148
*/
148149
private $collectionProcessorMock;
149150

151+
/**
152+
* @var Json|\PHPUnit_Framework_MockObject_MockObject
153+
*/
154+
private $serializerMock;
155+
150156
/**
151157
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
152158
*/
@@ -297,6 +303,17 @@ protected function setUp()
297303
$this->collectionProcessorMock = $this->getMockBuilder(CollectionProcessorInterface::class)
298304
->getMock();
299305

306+
$this->serializerMock = $this->getMockBuilder(Json::class)->getMock();
307+
$this->serializerMock->expects($this->any())
308+
->method('unserialize')
309+
->will(
310+
$this->returnCallback(
311+
function ($value) {
312+
return json_decode($value, true);
313+
}
314+
)
315+
);
316+
300317
$this->model = $this->objectManager->getObject(
301318
\Magento\Catalog\Model\ProductRepository::class,
302319
[
@@ -317,7 +334,8 @@ protected function setUp()
317334
'imageProcessor' => $this->imageProcessorMock,
318335
'storeManager' => $this->storeManagerMock,
319336
'mediaGalleryProcessor' => $this->mediaGalleryProcessor,
320-
'collectionProcessor' => $this->collectionProcessorMock
337+
'collectionProcessor' => $this->collectionProcessorMock,
338+
'serializer' => $this->serializerMock,
321339
]
322340
);
323341
}
@@ -436,6 +454,8 @@ public function testGetByIdForcedReload()
436454
->will($this->returnValue($this->productMock));
437455
$this->productMock->expects($this->exactly(2))->method('load');
438456
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn($identifier);
457+
$this->serializerMock->expects($this->exactly(3))->method('serialize');
458+
439459
$this->assertEquals($this->productMock, $this->model->getById($identifier, $editMode, $storeId));
440460
//second invocation should just return from cache
441461
$this->assertEquals($this->productMock, $this->model->getById($identifier, $editMode, $storeId));
@@ -461,6 +481,8 @@ public function testGetForcedReload()
461481
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn($sku);
462482
$this->resourceModelMock->expects($this->exactly(2))->method('getIdBySku')
463483
->with($sku)->willReturn($id);
484+
$this->serializerMock->expects($this->exactly(3))->method('serialize');
485+
464486
$this->assertEquals($this->productMock, $this->model->get($sku, $editMode, $storeId));
465487
//second invocation should just return from cache
466488
$this->assertEquals($this->productMock, $this->model->get($sku, $editMode, $storeId));
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Model\ResourceModel;
8+
9+
use Magento\Catalog\Model\ResourceModel\Category;
10+
use Magento\Framework\DB\Select;
11+
use Magento\Framework\DB\Adapter\AdapterInterface as Adapter;
12+
use Magento\Framework\App\ResourceConnection;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend;
15+
use Magento\Eav\Model\Entity\Attribute;
16+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
17+
use Magento\Framework\Serialize\Serializer\Json;
18+
use Magento\Eav\Model\Entity\Context;
19+
use Magento\Catalog\Model\Factory;
20+
use Magento\Framework\Event\ManagerInterface;
21+
use Magento\Eav\Model\Config;
22+
use Magento\Eav\Model\Entity\Type;
23+
24+
/**
25+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+
*/
27+
class CategoryTest extends \PHPUnit_Framework_TestCase
28+
{
29+
/**
30+
* @var Category
31+
*/
32+
protected $category;
33+
34+
/**
35+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $contextMock;
38+
39+
/**
40+
* @var Select|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $selectMock;
43+
44+
/**
45+
* @var Adapter|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $connectionMock;
48+
49+
/**
50+
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $resourceMock;
53+
54+
/**
55+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
private $eavConfigMock;
58+
59+
/**
60+
* @var Type|\PHPUnit_Framework_MockObject_MockObject
61+
*/
62+
private $entityType;
63+
64+
/**
65+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
66+
*/
67+
protected $storeManagerMock;
68+
69+
/**
70+
* @var Factory|\PHPUnit_Framework_MockObject_MockObject
71+
*/
72+
protected $factoryMock;
73+
74+
/**
75+
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
76+
*/
77+
protected $managerMock;
78+
79+
/**
80+
* @var Category\TreeFactory|\PHPUnit_Framework_MockObject_MockObject
81+
*/
82+
protected $treeFactoryMock;
83+
84+
/**
85+
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
86+
*/
87+
protected $collectionFactoryMock;
88+
89+
/**
90+
* @var Json|\PHPUnit_Framework_MockObject_MockObject
91+
*/
92+
private $serializerMock;
93+
94+
/**
95+
* {@inheritDoc}
96+
*/
97+
protected function setUp()
98+
{
99+
$this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
100+
$this->selectMock->expects($this->at(2))->method('where')->willReturnSelf();
101+
$this->selectMock->expects($this->once())->method('from')->willReturnSelf();
102+
$this->selectMock->expects($this->once())->method('joinLeft')->willReturnSelf();
103+
$this->connectionMock = $this->getMockBuilder(Adapter::class)->getMockForAbstractClass();
104+
$this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock);
105+
$this->resourceMock = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock();
106+
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
107+
$this->connectionMock->expects($this->any())->method('getTableName')->willReturn('TableName');
108+
$this->resourceMock->expects($this->any())->method('getTableName')->willReturn('TableName');
109+
$this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
110+
$this->eavConfigMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
111+
$this->entityType = $this->getMockBuilder(Type::class)->disableOriginalConstructor()->getMock();
112+
$this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn($this->entityType);
113+
$this->contextMock->expects($this->any())->method('getEavConfig')->willReturn($this->eavConfigMock);
114+
$this->contextMock->expects($this->any())->method('getResource')->willReturn($this->resourceMock);
115+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMock();
116+
$this->factoryMock = $this->getMockBuilder(Factory::class)->disableOriginalConstructor()->getMock();
117+
$this->managerMock = $this->getMockBuilder(ManagerInterface::class)->getMock();
118+
$this->treeFactoryMock = $this->getMockBuilder(Category\TreeFactory::class)
119+
->disableOriginalConstructor()
120+
->getMock();
121+
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
122+
->disableOriginalConstructor()
123+
->getMock();
124+
125+
$this->serializerMock = $this->getMockBuilder(Json::class)->getMock();
126+
127+
$this->category = new Category(
128+
$this->contextMock,
129+
$this->storeManagerMock,
130+
$this->factoryMock,
131+
$this->managerMock,
132+
$this->treeFactoryMock,
133+
$this->collectionFactoryMock,
134+
[],
135+
$this->serializerMock
136+
);
137+
}
138+
139+
/**
140+
* @return void
141+
*/
142+
public function testFindWhereAttributeIs()
143+
{
144+
$entityIdsFilter = [1, 2];
145+
$expectedValue = 123;
146+
$attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->getMock();
147+
$backendModel = $this->getMockBuilder(AbstractBackend::class)->disableOriginalConstructor()->getMock();
148+
149+
$attribute->expects($this->any())->method('getBackend')->willReturn($backendModel);
150+
$this->connectionMock->expects($this->once())->method('fetchCol')->willReturn(['result']);
151+
$this->serializerMock->expects($this->once())
152+
->method('serialize')
153+
->will(
154+
$this->returnCallback(
155+
function ($value) {
156+
return json_encode($value);
157+
}
158+
)
159+
);
160+
161+
$result = $this->category->findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue);
162+
$this->assertEquals(['result'], $result);
163+
}
164+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ protected function setUp()
152152
$productLimitationMock = $this->getMock(
153153
\Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation::class
154154
);
155-
$productLimitationFactoryMock = $this->getMock(ProductLimitationFactory::class, ['create']);
155+
$productLimitationFactoryMock = $this->getMockBuilder(
156+
ProductLimitationFactory::class
157+
)->disableOriginalConstructor()->setMethods(['create'])->getMock();
158+
156159
$productLimitationFactoryMock->method('create')
157160
->willReturn($productLimitationMock);
158161
$this->collection = $this->objectManager->getObject(

0 commit comments

Comments
 (0)