Skip to content

Commit

Permalink
Merge pull request magento#3914 from magento-tsg-csl3/2.2-develop-pr24
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.2 (pr24)
  • Loading branch information
viktym authored Mar 18, 2019
2 parents 71e61a7 + 3843a6c commit 4dd101e
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 5 deletions.
36 changes: 33 additions & 3 deletions app/code/Magento/Catalog/Block/Adminhtml/Category/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(
}

/**
* @return void
* @inheritdoc
*/
protected function _construct()
{
Expand All @@ -82,7 +82,7 @@ protected function _construct()
}

/**
* @return $this
* @inheritdoc
*/
protected function _prepareLayout()
{
Expand Down Expand Up @@ -182,6 +182,8 @@ public function getSuggestedCategoriesJson($namePart)
}

/**
* Get add root button html
*
* @return string
*/
public function getAddRootButtonHtml()
Expand All @@ -190,6 +192,8 @@ public function getAddRootButtonHtml()
}

/**
* Get add sub button html
*
* @return string
*/
public function getAddSubButtonHtml()
Expand All @@ -198,6 +202,8 @@ public function getAddSubButtonHtml()
}

/**
* Get expand button html
*
* @return string
*/
public function getExpandButtonHtml()
Expand All @@ -206,6 +212,8 @@ public function getExpandButtonHtml()
}

/**
* Get collapse button html
*
* @return string
*/
public function getCollapseButtonHtml()
Expand All @@ -214,6 +222,8 @@ public function getCollapseButtonHtml()
}

/**
* Get store switcher
*
* @return string
*/
public function getStoreSwitcherHtml()
Expand All @@ -222,6 +232,8 @@ public function getStoreSwitcherHtml()
}

/**
* Get loader tree url
*
* @param bool|null $expanded
* @return string
*/
Expand All @@ -235,6 +247,8 @@ public function getLoadTreeUrl($expanded = null)
}

/**
* Get nodes url
*
* @return string
*/
public function getNodesUrl()
Expand All @@ -243,6 +257,8 @@ public function getNodesUrl()
}

/**
* Get switcher tree url
*
* @return string
*/
public function getSwitchTreeUrl()
Expand All @@ -254,6 +270,8 @@ public function getSwitchTreeUrl()
}

/**
* Get is was expanded
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
Expand All @@ -263,14 +281,19 @@ public function getIsWasExpanded()
}

/**
* Get move url
*
* @return string
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function getMoveUrl()
{
return $this->getUrl('catalog/category/move', ['store' => $this->getRequest()->getParam('store')]);
}

/**
* Get tree
*
* @param mixed|null $parenNodeCategory
* @return array
*/
Expand All @@ -282,6 +305,8 @@ public function getTree($parenNodeCategory = null)
}

/**
* Get tree json
*
* @param mixed|null $parenNodeCategory
* @return string
*/
Expand Down Expand Up @@ -367,7 +392,7 @@ protected function _getNodeJson($node, $level = 0)
}
}

if ($isParent || $node->getLevel() < 2) {
if ($isParent || $node->getLevel() < 1) {
$item['expanded'] = true;
}

Expand All @@ -390,6 +415,8 @@ public function buildNodeName($node)
}

/**
* Is category movable
*
* @param Node|array $node
* @return bool
*/
Expand All @@ -403,6 +430,8 @@ protected function _isCategoryMoveable($node)
}

/**
* Is parent selected category
*
* @param Node|array $node
* @return bool
*/
Expand All @@ -422,6 +451,7 @@ protected function _isParentSelectedCategory($node)
* Check if page loaded by outside link to category edit
*
* @return boolean
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function isClearEdit()
{
Expand Down
156 changes: 156 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Ui/Component/ColumnFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Ui\Component;

use PHPUnit\Framework\TestCase;
use Magento\Catalog\Ui\Component\ColumnFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\ColumnInterface;
use Magento\Ui\Component\Filters\FilterModifier;

/**
* ColumnFactory test.
*/
class ColumnFactoryTest extends TestCase
{
/**
* @var ColumnFactory
*/
private $columnFactory;

/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var ProductAttributeInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $attribute;

/**
* @var ContextInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $context;

/**
* @var UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $uiComponentFactory;

/**
* @var ColumnInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $column;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->objectManager = new ObjectManager($this);

$this->attribute = $this->getMockBuilder(ProductAttributeInterface::class)
->setMethods(['usesSource'])
->getMockForAbstractClass();
$this->context = $this->createMock(ContextInterface::class);
$this->uiComponentFactory = $this->createMock(UiComponentFactory::class);
$this->column = $this->getMockForAbstractClass(ColumnInterface::class);
$this->uiComponentFactory->method('create')
->willReturn($this->column);

$this->columnFactory = $this->objectManager->getObject(ColumnFactory::class, [
'componentFactory' => $this->uiComponentFactory
]);
}

/**
* Tests the create method will return correct object.
*
* @return void
*/
public function testCreatedObject()
{
$this->context->method('getRequestParam')
->with(FilterModifier::FILTER_MODIFIER, [])
->willReturn([]);

$object = $this->columnFactory->create($this->attribute, $this->context);
$this->assertEquals(
$this->column,
$object,
'Object must be the same which the ui component factory creates.'
);
}

/**
* Tests create method with not filterable in grid attribute.
*
* @param array $filterModifiers
* @param null|string $filter
*
* @return void
* @dataProvider filterModifiersProvider
*/
public function testCreateWithNotFilterableInGridAttribute(array $filterModifiers, $filter)
{
$componentFactoryArgument = [
'data' => [
'config' => [
'label' => __(null),
'dataType' => 'text',
'add_field' => true,
'visible' => null,
'filter' => $filter,
'component' => 'Magento_Ui/js/grid/columns/column',
],
],
'context' => $this->context,
];

$this->context->method('getRequestParam')
->with(FilterModifier::FILTER_MODIFIER, [])
->willReturn($filterModifiers);
$this->attribute->method('getIsFilterableInGrid')
->willReturn(false);
$this->attribute->method('getAttributeCode')
->willReturn('color');

$this->uiComponentFactory->expects($this->once())
->method('create')
->with($this->anything(), $this->anything(), $componentFactoryArgument);

$this->columnFactory->create($this->attribute, $this->context);
}

/**
* Filter modifiers data provider.
*
* @return array
*/
public function filterModifiersProvider(): array
{
return [
'without' => [
'filter_modifiers' => [],
'filter' => null,
],
'with' => [
'filter_modifiers' => [
'color' => [
'condition_type' => 'notnull',
],
],
'filter' => 'text',
],
];
}
}
6 changes: 5 additions & 1 deletion app/code/Magento/Catalog/Ui/Component/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Ui\Component;

use Magento\Ui\Component\Filters\FilterModifier;

/**
* @api
* @since 100.0.2
Expand Down Expand Up @@ -54,13 +56,15 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
*/
public function create($attribute, $context, array $config = [])
{
$filterModifiers = $context->getRequestParam(FilterModifier::FILTER_MODIFIER, []);

$columnName = $attribute->getAttributeCode();
$config = array_merge([
'label' => __($attribute->getDefaultFrontendLabel()),
'dataType' => $this->getDataType($attribute),
'add_field' => true,
'visible' => $attribute->getIsVisibleInGrid(),
'filter' => ($attribute->getIsFilterableInGrid())
'filter' => ($attribute->getIsFilterableInGrid() || array_key_exists($columnName, $filterModifiers))
? $this->getFilterType($attribute->getFrontendInput())
: null,
], $config);
Expand Down
Loading

0 comments on commit 4dd101e

Please sign in to comment.