Skip to content

Commit

Permalink
Merge pull request #226 from magento-troll/troll_bugfix
Browse files Browse the repository at this point in the history
[Troll] Bugfixes P0 - P3
  • Loading branch information
kandy authored Aug 8, 2016
2 parents 10407d3 + debb977 commit bcdd65f
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 95 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<th scope="col" class="col shipping"><?php /* @escapeNotVerified */ echo __('Ship To') ?></th>
<th scope="col" class="col total"><?php /* @escapeNotVerified */ echo __('Order Total') ?></th>
<th scope="col" class="col status"><?php /* @escapeNotVerified */ echo __('Status') ?></th>
<th scope="col" class="col actions">&nbsp;</th>
<th scope="col" class="col actions"><?php /* @escapeNotVerified */ echo __('Action') ?></th>
</tr>
</thead>
<tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Ui/view/base/web/js/lib/step-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ define([
modal.closeModal();
}
},
showSpecificStep: function () {
showSpecificStep: function (data, event) {
var index = _.indexOf(this.stepsNames, event.target.hash.substr(1)),
stepName = this.wizard.move(index);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
disable="isDisabled($col())"
ko-checked="$col().visible"
attr="id: ++ko.uid"/>
<label class="admin__field-label" text="$col().label" attr="for: ko.uid"/>
<label class="admin__field-label"
text="$col().label"
attr="for: ko.uid, title: $col().label"/>
</div>
</div>
<div class="admin__action-dropdown-menu-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/**
* Test class for \Magento\Backend\Block\Menu
*
* @magentoAppArea adminhtml
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class MenuTest extends \PHPUnit_Framework_TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class ProductsViewedTest extends \Magento\TestFramework\TestCase\AbstractBackendController
{
/**
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Reports/_files/viewed_products.php
*/
public function testExecute()
Expand Down

0 comments on commit bcdd65f

Please sign in to comment.