Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into CICD-2390
Browse files Browse the repository at this point in the history
  • Loading branch information
kandy committed Aug 9, 2016
2 parents d2b5faa + c107794 commit 1c691b7
Show file tree
Hide file tree
Showing 15 changed files with 335 additions and 146 deletions.
1 change: 0 additions & 1 deletion app/code/Magento/Backend/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<argument name="backendHelper" xsi:type="object">Magento\Backend\Helper\Data\Proxy</argument>
</arguments>
</type>
<preference for="Magento\Framework\Authorization\RoleLocatorInterface" type="Magento\Backend\Model\Authorization\RoleLocator" />
<preference for="Magento\Framework\Authorization\PolicyInterface" type="Magento\Framework\Authorization\Policy\Acl"/>
<preference for="Magento\Framework\Acl\AclResource\ProviderInterface" type="Magento\Framework\Acl\AclResource\Provider"/>
<type name="Magento\Framework\Acl\AclResource\Config\Reader\Filesystem">
Expand Down
13 changes: 10 additions & 3 deletions app/code/Magento/Catalog/Plugin/Block/Topmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ public function beforeGetHtml(
$currentCategory = $this->getCurrentCategory();
$mapping = [$rootId => $subject->getMenu()]; // use nodes stack to avoid recursion
foreach ($collection as $category) {
if (!isset($mapping[$category->getParentId()])) {
continue;
$categoryParentId = $category->getParentId();
if (!isset($mapping[$categoryParentId])) {
$parentIds = $category->getParentIds();
foreach ($parentIds as $parentId) {
if (isset($mapping[$parentId])) {
$categoryParentId = $parentId;
}
}
}

/** @var Node $parentCategoryNode */
$parentCategoryNode = $mapping[$category->getParentId()];
$parentCategoryNode = $mapping[$categoryParentId];

$categoryNode = new Node(
$this->getCategoryAsArray($category, $currentCategory),
Expand Down
180 changes: 93 additions & 87 deletions app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Catalog\Test\Unit\Plugin\Block;

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

/**
* Class TopmenuTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TopmenuTest extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -18,96 +21,109 @@ class TopmenuTest extends \PHPUnit_Framework_TestCase
protected $block;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Helper\Category
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
*/
protected $_catalogCategory;
protected $storeManagerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
*/
protected $_childrenCategory;
protected $storeMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer\Resolver
*/
protected $layerResolverMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer
*/
protected $catalogLayerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
*/
protected $_category;
protected $categoryCollectionFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\ResourceModel\Category\Collection
*/
protected $menuCategoryData;
protected $categoryCollectionMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Indexer\Category\Flat\State
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Helper\Category
*/
protected $categoryHelperMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
*/
protected $childrenCategoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Category
*/
protected $_categoryFlatState;
protected $categoryMock;

/**
* Set up
*
* @return void
*/
protected function setUp()
{
$this->_catalogCategory = $this->getMock(
\Magento\Catalog\Helper\Category::class,
['getStoreCategories', 'getCategoryUrl'],
[],
'',
false
$rootCategoryId = 2;
$categoryParentId = 3;
$categoryParentIds = [1, 2, 3];

$this->childrenCategoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class);
$this->categoryHelperMock = $this->_getCleanMock(\Magento\Catalog\Helper\Category::class);
$this->catalogLayerMock = $this->_getCleanMock(\Magento\Catalog\Model\Layer::class);
$this->categoryMock = $this->_getCleanMock(\Magento\Catalog\Model\Category::class);
$this->layerResolverMock = $this->_getCleanMock(\Magento\Catalog\Model\Layer\Resolver::class);
$this->storeMock = $this->_getCleanMock(\Magento\Store\Model\Store::class);
$this->storeManagerMock = $this->_getCleanMock(\Magento\Store\Model\StoreManagerInterface::class);
$this->categoryCollectionMock = $this->_getCleanMock(
\Magento\Catalog\Model\ResourceModel\Category\Collection::class
);

$this->menuCategoryData = $this->getMock(
\Magento\Catalog\Observer\MenuCategoryData::class,
['getMenuCategoryData'],
$this->categoryCollectionFactoryMock = $this->getMock(
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class,
['create'],
[],
'',
false
);

$this->store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
->setMethods(['getRootCategoryId', 'getFilters', '__wakeup'])
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
->setMethods(['getStore'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->storeManager->expects($this->any())->method('getStore')
->will($this->returnValue($this->store));

$this->store->expects($this->any())->method('getRootCategoryId')
->will($this->returnValue(1));

$collectionFactory = $this->getMockBuilder(
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();

$collection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Category\Collection::class)
->setMethods(
[
'addIsActiveFilter',
'addAttributeToSelect',
'addFieldToFilter',
'addAttributeToFilter',
'addUrlRewriteToResult',
'getIterator',
'setStoreId'
]
)->disableOriginalConstructor()
->getMock();
$collection->expects($this->once())->method('addIsActiveFilter');
$collectionFactory->expects($this->once())->method('create')
->willReturn($collection);

$collection->expects($this->once())->method('getIterator')
->willReturn(new \ArrayIterator([]));
$this->catalogLayerMock->expects($this->once())->method('getCurrentCategory')
->will($this->returnValue($this->childrenCategoryMock));

$this->storeManagerMock->expects($this->atLeastOnce())->method('getStore')
->will($this->returnValue($this->storeMock));

$this->categoryMock->expects($this->atLeastOnce())->method('getParentId')
->will($this->returnValue($categoryParentId));
$this->categoryMock->expects($this->once())->method('getParentIds')
->will($this->returnValue($categoryParentIds));

$this->layerResolverMock->expects($this->once())->method('get')
->will($this->returnValue($this->catalogLayerMock));

$this->storeMock->expects($this->once())->method('getRootCategoryId')
->will($this->returnValue($rootCategoryId));

$this->categoryCollectionMock->expects($this->once())->method('getIterator')
->willReturn(new \ArrayIterator([$this->categoryMock]));

$this->categoryCollectionFactoryMock->expects($this->once())->method('create')
->willReturn($this->categoryCollectionMock);

$this->block = (new ObjectManager($this))->getObject(
\Magento\Catalog\Plugin\Block\Topmenu::class,
[
'catalogCategory' => $this->_catalogCategory,
'menuCategoryData' => $this->menuCategoryData,
'storeManager' => $this->storeManager,
'categoryCollectionFactory' => $collectionFactory,
'catalogCategory' => $this->categoryHelperMock,
'categoryCollectionFactory' => $this->categoryCollectionFactoryMock,
'storeManager' => $this->storeManagerMock,
'layerResolver' => $this->layerResolverMock,
]
);
}
Expand All @@ -123,31 +139,21 @@ protected function _getCleanMock($className)
return $this->getMock($className, [], [], '', false);
}

protected function _preparationData()
/**
* Test beforeGetHtml
*
*/
public function testBeforeGetHtml()
{
$this->_childrenCategory = $this->getMock(
\Magento\Catalog\Model\Category::class,
['getIsActive', '__wakeup'],
[],
'',
false
);

$treeMock = $this->getMock(\Magento\Framework\Data\Tree::class);

$this->_category = $this->getMock(
\Magento\Catalog\Model\Category::class,
['getIsActive', '__wakeup', 'getName', 'getChildren', 'getUseFlatResource', 'getChildrenNodes'],
[],
'',
false
);
$parentCategoryNodeMock = $this->_getCleanMock(\Magento\Framework\Data\Tree\Node::class);
$parentCategoryNodeMock->expects($this->once())->method('getTree')->will($this->returnValue($treeMock));
$parentCategoryNodeMock->expects($this->once())->method('addChild');

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

public function testAddCatalogToTopMenuItems()
{
$this->block->beforeGetHtml($this->_preparationData());
$this->block->beforeGetHtml($blockMock);
}
}
25 changes: 23 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
'tax_class_id' => 'tax_class_name',
];

/**
* Attributes codes which shows as date
*
* @var array
*/
protected $dateAttrCodes = [
'special_from_date',
'special_to_date'
];

/**
* Attributes codes which are appropriate for export and not the part of additional_attributes.
*
Expand Down Expand Up @@ -338,6 +348,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @param Product\Type\Factory $_typeFactory
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
* @param array $dateAttrCodes
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -356,7 +367,8 @@ public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory,
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
array $dateAttrCodes = []
) {
$this->_entityCollectionFactory = $collectionFactory;
$this->_exportConfig = $exportConfig;
Expand All @@ -371,6 +383,7 @@ public function __construct(
$this->_typeFactory = $_typeFactory;
$this->_linkTypeProvider = $linkTypeProvider;
$this->rowCustomizer = $rowCustomizer;
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);

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

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

if ($this->_attributeTypes[$code] === 'datetime') {
if (in_array($code, $this->dateAttrCodes)) {
$attrValue = $this->_localeDate->formatDateTime(
new \DateTime($attrValue),
\IntlDateFormatter::SHORT,
\IntlDateFormatter::NONE,
null,
date_default_timezone_get()
);
} else if ($this->_attributeTypes[$code] === 'datetime') {
$attrValue = $this->_localeDate->formatDateTime(
new \DateTime($attrValue),
\IntlDateFormatter::SHORT,
Expand Down
22 changes: 20 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
'_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
];

/**
* Attributes codes which shows as date
*
* @var array
*/
protected $dateAttrCodes = [
'special_from_date',
'special_to_date'
];

/**
* Need to log in import history
*
Expand Down Expand Up @@ -664,6 +674,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
* @param Product\TaxClassProcessor $taxClassProcessor
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param array $data
* @param array $dateAttrCodes
* @throws \Magento\Framework\Exception\LocalizedException
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand Down Expand Up @@ -705,7 +716,8 @@ public function __construct(
Product\TaxClassProcessor $taxClassProcessor,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Catalog\Model\Product\Url $productUrl,
array $data = []
array $data = [],
array $dateAttrCodes = []
) {
$this->_eventManager = $eventManager;
$this->stockRegistry = $stockRegistry;
Expand Down Expand Up @@ -734,6 +746,7 @@ public function __construct(
$this->taxClassProcessor = $taxClassProcessor;
$this->scopeConfig = $scopeConfig;
$this->productUrl = $productUrl;
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
parent::__construct(
$jsonHelper,
$importExportData,
Expand Down Expand Up @@ -1642,7 +1655,12 @@ protected function _saveProducts()
$attrTable = $attribute->getBackend()->getTable();
$storeIds = [0];

if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
if (
'datetime' == $attribute->getBackendType()
&& in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
) {
$attrValue = $this->dateTime->formatDate($attrValue, false);
} else if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
$attrValue = $this->dateTime->gmDate(
'Y-m-d H:i:s',
$this->_localeDate->date($attrValue)->getTimestamp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ protected function setUp()
$this->attributeColFactory,
$this->typeFactory,
$this->linkTypeProvider,
$this->rowCustomizer,
$this->metadataPool
$this->rowCustomizer
);
$this->setPropertyValue($this->product, 'metadataPool', $this->metadataPool);

$this->object = new StubProduct();
}
Expand Down
Loading

0 comments on commit 1c691b7

Please sign in to comment.