Skip to content

Commit 80a7a65

Browse files
author
Mike Weis
committed
Merge branch 'develop' into FearlessKiwis-MAGETWO-55229-Problem-while-upgrading-210
2 parents 7aaa4bf + bcdd65f commit 80a7a65

File tree

14 files changed

+330
-144
lines changed

14 files changed

+330
-144
lines changed

app/code/Magento/Backend/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
<argument name="backendHelper" xsi:type="object">Magento\Backend\Helper\Data\Proxy</argument>
7272
</arguments>
7373
</type>
74-
<preference for="Magento\Framework\Authorization\RoleLocatorInterface" type="Magento\Backend\Model\Authorization\RoleLocator" />
7574
<preference for="Magento\Framework\Authorization\PolicyInterface" type="Magento\Framework\Authorization\Policy\Acl"/>
7675
<preference for="Magento\Framework\Acl\AclResource\ProviderInterface" type="Magento\Framework\Acl\AclResource\Provider"/>
7776
<type name="Magento\Framework\Acl\AclResource\Config\Reader\Filesystem">

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,18 @@ public function beforeGetHtml(
7979
$currentCategory = $this->getCurrentCategory();
8080
$mapping = [$rootId => $subject->getMenu()]; // use nodes stack to avoid recursion
8181
foreach ($collection as $category) {
82-
if (!isset($mapping[$category->getParentId()])) {
83-
continue;
82+
$categoryParentId = $category->getParentId();
83+
if (!isset($mapping[$categoryParentId])) {
84+
$parentIds = $category->getParentIds();
85+
foreach ($parentIds as $parentId) {
86+
if (isset($mapping[$parentId])) {
87+
$categoryParentId = $parentId;
88+
}
89+
}
8490
}
91+
8592
/** @var Node $parentCategoryNode */
86-
$parentCategoryNode = $mapping[$category->getParentId()];
93+
$parentCategoryNode = $mapping[$categoryParentId];
8794

8895
$categoryNode = new Node(
8996
$this->getCategoryAsArray($category, $currentCategory),

app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php

Lines changed: 93 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Catalog\Test\Unit\Plugin\Block;
108

119
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1210

11+
/**
12+
* Class TopmenuTest
13+
*
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
1316
class TopmenuTest extends \PHPUnit_Framework_TestCase
1417
{
1518
/**
@@ -18,96 +21,109 @@ class TopmenuTest extends \PHPUnit_Framework_TestCase
1821
protected $block;
1922

2023
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Helper\Category
24+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
2225
*/
23-
protected $_catalogCategory;
26+
protected $storeManagerMock;
2427

2528
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
29+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
2730
*/
28-
protected $_childrenCategory;
31+
protected $storeMock;
2932

3033
/**
31-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
34+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer\Resolver
35+
*/
36+
protected $layerResolverMock;
37+
38+
/**
39+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer
40+
*/
41+
protected $catalogLayerMock;
42+
43+
/**
44+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
3245
*/
33-
protected $_category;
46+
protected $categoryCollectionFactoryMock;
3447

3548
/**
36-
* @var \PHPUnit_Framework_MockObject_MockObject
49+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\ResourceModel\Category\Collection
3750
*/
38-
protected $menuCategoryData;
51+
protected $categoryCollectionMock;
3952

4053
/**
41-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Indexer\Category\Flat\State
54+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Helper\Category
55+
*/
56+
protected $categoryHelperMock;
57+
58+
/**
59+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
60+
*/
61+
protected $childrenCategoryMock;
62+
63+
/**
64+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
4265
*/
43-
protected $_categoryFlatState;
66+
protected $categoryMock;
4467

68+
/**
69+
* Set up
70+
*
71+
* @return void
72+
*/
4573
protected function setUp()
4674
{
47-
$this->_catalogCategory = $this->getMock(
48-
\Magento\Catalog\Helper\Category::class,
49-
['getStoreCategories', 'getCategoryUrl'],
50-
[],
51-
'',
52-
false
75+
$rootCategoryId = 2;
76+
$categoryParentId = 3;
77+
$categoryParentIds = [1, 2, 3];
78+
79+
$this->childrenCategoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class);
80+
$this->categoryHelperMock = $this->_getCleanMock(\Magento\Catalog\Helper\Category::class);
81+
$this->catalogLayerMock = $this->_getCleanMock(\Magento\Catalog\Model\Layer::class);
82+
$this->categoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class);
83+
$this->layerResolverMock = $this->_getCleanMock(\Magento\Catalog\Model\Layer\Resolver::class);
84+
$this->storeMock = $this->_getCleanMock(\Magento\Store\Model\Store::class);
85+
$this->storeManagerMock = $this->_getCleanMock(\Magento\Store\Model\StoreManagerInterface::class);
86+
$this->categoryCollectionMock = $this->_getCleanMock(
87+
\Magento\Catalog\Model\ResourceModel\Category\Collection::class
5388
);
54-
55-
$this->menuCategoryData = $this->getMock(
56-
\Magento\Catalog\Observer\MenuCategoryData::class,
57-
['getMenuCategoryData'],
89+
$this->categoryCollectionFactoryMock = $this->getMock(
90+
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class,
91+
['create'],
5892
[],
5993
'',
6094
false
6195
);
6296

63-
$this->store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
64-
->setMethods(['getRootCategoryId', 'getFilters', '__wakeup'])
65-
->disableOriginalConstructor()
66-
->getMockForAbstractClass();
67-
68-
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
69-
->setMethods(['getStore'])
70-
->disableOriginalConstructor()
71-
->getMockForAbstractClass();
72-
$this->storeManager->expects($this->any())->method('getStore')
73-
->will($this->returnValue($this->store));
74-
75-
$this->store->expects($this->any())->method('getRootCategoryId')
76-
->will($this->returnValue(1));
77-
78-
$collectionFactory = $this->getMockBuilder(
79-
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class)
80-
->setMethods(['create'])
81-
->disableOriginalConstructor()
82-
->getMock();
83-
84-
$collection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Category\Collection::class)
85-
->setMethods(
86-
[
87-
'addIsActiveFilter',
88-
'addAttributeToSelect',
89-
'addFieldToFilter',
90-
'addAttributeToFilter',
91-
'addUrlRewriteToResult',
92-
'getIterator',
93-
'setStoreId'
94-
]
95-
)->disableOriginalConstructor()
96-
->getMock();
97-
$collection->expects($this->once())->method('addIsActiveFilter');
98-
$collectionFactory->expects($this->once())->method('create')
99-
->willReturn($collection);
100-
101-
$collection->expects($this->once())->method('getIterator')
102-
->willReturn(new \ArrayIterator([]));
97+
$this->catalogLayerMock->expects($this->once())->method('getCurrentCategory')
98+
->will($this->returnValue($this->childrenCategoryMock));
99+
100+
$this->storeManagerMock->expects($this->atLeastOnce())->method('getStore')
101+
->will($this->returnValue($this->storeMock));
102+
103+
$this->categoryMock->expects($this->atLeastOnce())->method('getParentId')
104+
->will($this->returnValue($categoryParentId));
105+
$this->categoryMock->expects($this->once())->method('getParentIds')
106+
->will($this->returnValue($categoryParentIds));
107+
108+
$this->layerResolverMock->expects($this->once())->method('get')
109+
->will($this->returnValue($this->catalogLayerMock));
110+
111+
$this->storeMock->expects($this->once())->method('getRootCategoryId')
112+
->will($this->returnValue($rootCategoryId));
113+
114+
$this->categoryCollectionMock->expects($this->once())->method('getIterator')
115+
->willReturn(new \ArrayIterator([$this->categoryMock]));
116+
117+
$this->categoryCollectionFactoryMock->expects($this->once())->method('create')
118+
->willReturn($this->categoryCollectionMock);
103119

104120
$this->block = (new ObjectManager($this))->getObject(
105121
\Magento\Catalog\Plugin\Block\Topmenu::class,
106122
[
107-
'catalogCategory' => $this->_catalogCategory,
108-
'menuCategoryData' => $this->menuCategoryData,
109-
'storeManager' => $this->storeManager,
110-
'categoryCollectionFactory' => $collectionFactory,
123+
'catalogCategory' => $this->categoryHelperMock,
124+
'categoryCollectionFactory' => $this->categoryCollectionFactoryMock,
125+
'storeManager' => $this->storeManagerMock,
126+
'layerResolver' => $this->layerResolverMock,
111127
]
112128
);
113129
}
@@ -123,31 +139,21 @@ protected function _getCleanMock($className)
123139
return $this->getMock($className, [], [], '', false);
124140
}
125141

126-
protected function _preparationData()
142+
/**
143+
* Test beforeGetHtml
144+
*
145+
*/
146+
public function testBeforeGetHtml()
127147
{
128-
$this->_childrenCategory = $this->getMock(
129-
\Magento\Catalog\Model\Category::class,
130-
['getIsActive', '__wakeup'],
131-
[],
132-
'',
133-
false
134-
);
135-
148+
$treeMock = $this->getMock(\Magento\Framework\Data\Tree::class);
136149

137-
$this->_category = $this->getMock(
138-
\Magento\Catalog\Model\Category::class,
139-
['getIsActive', '__wakeup', 'getName', 'getChildren', 'getUseFlatResource', 'getChildrenNodes'],
140-
[],
141-
'',
142-
false
143-
);
150+
$parentCategoryNodeMock = $this->_getCleanMock(\Magento\Framework\Data\Tree\Node::class);
151+
$parentCategoryNodeMock->expects($this->once())->method('getTree')->will($this->returnValue($treeMock));
152+
$parentCategoryNodeMock->expects($this->once())->method('addChild');
144153

145154
$blockMock = $this->_getCleanMock(\Magento\Theme\Block\Html\Topmenu::class);
146-
return $blockMock;
147-
}
155+
$blockMock->expects($this->once())->method('getMenu')->will($this->returnValue($parentCategoryNodeMock));
148156

149-
public function testAddCatalogToTopMenuItems()
150-
{
151-
$this->block->beforeGetHtml($this->_preparationData());
157+
$this->block->beforeGetHtml($blockMock);
152158
}
153159
}

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
254254
'tax_class_id' => 'tax_class_name',
255255
];
256256

257+
/**
258+
* Attributes codes which shows as date
259+
*
260+
* @var array
261+
*/
262+
protected $dateAttrCodes = [
263+
'special_from_date',
264+
'special_to_date'
265+
];
266+
257267
/**
258268
* Attributes codes which are appropriate for export and not the part of additional_attributes.
259269
*
@@ -338,6 +348,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
338348
* @param Product\Type\Factory $_typeFactory
339349
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
340350
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
351+
* @param array $dateAttrCodes
341352
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
342353
*/
343354
public function __construct(
@@ -356,7 +367,8 @@ public function __construct(
356367
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory,
357368
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
358369
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
359-
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
370+
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
371+
array $dateAttrCodes = []
360372
) {
361373
$this->_entityCollectionFactory = $collectionFactory;
362374
$this->_exportConfig = $exportConfig;
@@ -371,6 +383,7 @@ public function __construct(
371383
$this->_typeFactory = $_typeFactory;
372384
$this->_linkTypeProvider = $linkTypeProvider;
373385
$this->rowCustomizer = $rowCustomizer;
386+
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
374387

375388
parent::__construct($localeDate, $config, $resource, $storeManager);
376389

@@ -897,7 +910,15 @@ protected function collectRawData()
897910
}
898911
$fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code;
899912

900-
if ($this->_attributeTypes[$code] === 'datetime') {
913+
if (in_array($code, $this->dateAttrCodes)) {
914+
$attrValue = $this->_localeDate->formatDateTime(
915+
new \DateTime($attrValue),
916+
\IntlDateFormatter::SHORT,
917+
\IntlDateFormatter::NONE,
918+
null,
919+
date_default_timezone_get()
920+
);
921+
} else if ($this->_attributeTypes[$code] === 'datetime') {
901922
$attrValue = $this->_localeDate->formatDateTime(
902923
new \DateTime($attrValue),
903924
\IntlDateFormatter::SHORT,

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
210210
'_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
211211
];
212212

213+
/**
214+
* Attributes codes which shows as date
215+
*
216+
* @var array
217+
*/
218+
protected $dateAttrCodes = [
219+
'special_from_date',
220+
'special_to_date'
221+
];
222+
213223
/**
214224
* Need to log in import history
215225
*
@@ -664,6 +674,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
664674
* @param Product\TaxClassProcessor $taxClassProcessor
665675
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
666676
* @param array $data
677+
* @param array $dateAttrCodes
667678
* @throws \Magento\Framework\Exception\LocalizedException
668679
*
669680
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -705,7 +716,8 @@ public function __construct(
705716
Product\TaxClassProcessor $taxClassProcessor,
706717
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
707718
\Magento\Catalog\Model\Product\Url $productUrl,
708-
array $data = []
719+
array $data = [],
720+
array $dateAttrCodes = []
709721
) {
710722
$this->_eventManager = $eventManager;
711723
$this->stockRegistry = $stockRegistry;
@@ -734,6 +746,7 @@ public function __construct(
734746
$this->taxClassProcessor = $taxClassProcessor;
735747
$this->scopeConfig = $scopeConfig;
736748
$this->productUrl = $productUrl;
749+
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
737750
parent::__construct(
738751
$jsonHelper,
739752
$importExportData,
@@ -1642,7 +1655,12 @@ protected function _saveProducts()
16421655
$attrTable = $attribute->getBackend()->getTable();
16431656
$storeIds = [0];
16441657

1645-
if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
1658+
if (
1659+
'datetime' == $attribute->getBackendType()
1660+
&& in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
1661+
) {
1662+
$attrValue = $this->dateTime->formatDate($attrValue, false);
1663+
} else if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
16461664
$attrValue = $this->dateTime->gmDate(
16471665
'Y-m-d H:i:s',
16481666
$this->_localeDate->date($attrValue)->getTimestamp()

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ protected function setUp()
343343
$this->attributeColFactory,
344344
$this->typeFactory,
345345
$this->linkTypeProvider,
346-
$this->rowCustomizer,
347-
$this->metadataPool
346+
$this->rowCustomizer
348347
);
348+
$this->setPropertyValue($this->product, 'metadataPool', $this->metadataPool);
349349

350350
$this->object = new StubProduct();
351351
}

0 commit comments

Comments
 (0)