Skip to content

Commit 4dd101e

Browse files
authored
Merge pull request #3914 from magento-tsg-csl3/2.2-develop-pr24
[TSG-CSL3] For 2.2 (pr24)
2 parents 71e61a7 + 3843a6c commit 4dd101e

File tree

4 files changed

+257
-5
lines changed

4 files changed

+257
-5
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Tree.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(
7373
}
7474

7575
/**
76-
* @return void
76+
* @inheritdoc
7777
*/
7878
protected function _construct()
7979
{
@@ -82,7 +82,7 @@ protected function _construct()
8282
}
8383

8484
/**
85-
* @return $this
85+
* @inheritdoc
8686
*/
8787
protected function _prepareLayout()
8888
{
@@ -182,6 +182,8 @@ public function getSuggestedCategoriesJson($namePart)
182182
}
183183

184184
/**
185+
* Get add root button html
186+
*
185187
* @return string
186188
*/
187189
public function getAddRootButtonHtml()
@@ -190,6 +192,8 @@ public function getAddRootButtonHtml()
190192
}
191193

192194
/**
195+
* Get add sub button html
196+
*
193197
* @return string
194198
*/
195199
public function getAddSubButtonHtml()
@@ -198,6 +202,8 @@ public function getAddSubButtonHtml()
198202
}
199203

200204
/**
205+
* Get expand button html
206+
*
201207
* @return string
202208
*/
203209
public function getExpandButtonHtml()
@@ -206,6 +212,8 @@ public function getExpandButtonHtml()
206212
}
207213

208214
/**
215+
* Get collapse button html
216+
*
209217
* @return string
210218
*/
211219
public function getCollapseButtonHtml()
@@ -214,6 +222,8 @@ public function getCollapseButtonHtml()
214222
}
215223

216224
/**
225+
* Get store switcher
226+
*
217227
* @return string
218228
*/
219229
public function getStoreSwitcherHtml()
@@ -222,6 +232,8 @@ public function getStoreSwitcherHtml()
222232
}
223233

224234
/**
235+
* Get loader tree url
236+
*
225237
* @param bool|null $expanded
226238
* @return string
227239
*/
@@ -235,6 +247,8 @@ public function getLoadTreeUrl($expanded = null)
235247
}
236248

237249
/**
250+
* Get nodes url
251+
*
238252
* @return string
239253
*/
240254
public function getNodesUrl()
@@ -243,6 +257,8 @@ public function getNodesUrl()
243257
}
244258

245259
/**
260+
* Get switcher tree url
261+
*
246262
* @return string
247263
*/
248264
public function getSwitchTreeUrl()
@@ -254,6 +270,8 @@ public function getSwitchTreeUrl()
254270
}
255271

256272
/**
273+
* Get is was expanded
274+
*
257275
* @return bool
258276
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
259277
*/
@@ -263,14 +281,19 @@ public function getIsWasExpanded()
263281
}
264282

265283
/**
284+
* Get move url
285+
*
266286
* @return string
287+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
267288
*/
268289
public function getMoveUrl()
269290
{
270291
return $this->getUrl('catalog/category/move', ['store' => $this->getRequest()->getParam('store')]);
271292
}
272293

273294
/**
295+
* Get tree
296+
*
274297
* @param mixed|null $parenNodeCategory
275298
* @return array
276299
*/
@@ -282,6 +305,8 @@ public function getTree($parenNodeCategory = null)
282305
}
283306

284307
/**
308+
* Get tree json
309+
*
285310
* @param mixed|null $parenNodeCategory
286311
* @return string
287312
*/
@@ -367,7 +392,7 @@ protected function _getNodeJson($node, $level = 0)
367392
}
368393
}
369394

370-
if ($isParent || $node->getLevel() < 2) {
395+
if ($isParent || $node->getLevel() < 1) {
371396
$item['expanded'] = true;
372397
}
373398

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

392417
/**
418+
* Is category movable
419+
*
393420
* @param Node|array $node
394421
* @return bool
395422
*/
@@ -403,6 +430,8 @@ protected function _isCategoryMoveable($node)
403430
}
404431

405432
/**
433+
* Is parent selected category
434+
*
406435
* @param Node|array $node
407436
* @return bool
408437
*/
@@ -422,6 +451,7 @@ protected function _isParentSelectedCategory($node)
422451
* Check if page loaded by outside link to category edit
423452
*
424453
* @return boolean
454+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
425455
*/
426456
public function isClearEdit()
427457
{
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Ui\Component;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Catalog\Ui\Component\ColumnFactory;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
14+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
15+
use Magento\Framework\View\Element\UiComponentFactory;
16+
use Magento\Ui\Component\Listing\Columns\ColumnInterface;
17+
use Magento\Ui\Component\Filters\FilterModifier;
18+
19+
/**
20+
* ColumnFactory test.
21+
*/
22+
class ColumnFactoryTest extends TestCase
23+
{
24+
/**
25+
* @var ColumnFactory
26+
*/
27+
private $columnFactory;
28+
29+
/**
30+
* @var ObjectManager
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var ProductAttributeInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $attribute;
38+
39+
/**
40+
* @var ContextInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $context;
43+
44+
/**
45+
* @var UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $uiComponentFactory;
48+
49+
/**
50+
* @var ColumnInterface|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $column;
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
protected function setUp()
58+
{
59+
$this->objectManager = new ObjectManager($this);
60+
61+
$this->attribute = $this->getMockBuilder(ProductAttributeInterface::class)
62+
->setMethods(['usesSource'])
63+
->getMockForAbstractClass();
64+
$this->context = $this->createMock(ContextInterface::class);
65+
$this->uiComponentFactory = $this->createMock(UiComponentFactory::class);
66+
$this->column = $this->getMockForAbstractClass(ColumnInterface::class);
67+
$this->uiComponentFactory->method('create')
68+
->willReturn($this->column);
69+
70+
$this->columnFactory = $this->objectManager->getObject(ColumnFactory::class, [
71+
'componentFactory' => $this->uiComponentFactory
72+
]);
73+
}
74+
75+
/**
76+
* Tests the create method will return correct object.
77+
*
78+
* @return void
79+
*/
80+
public function testCreatedObject()
81+
{
82+
$this->context->method('getRequestParam')
83+
->with(FilterModifier::FILTER_MODIFIER, [])
84+
->willReturn([]);
85+
86+
$object = $this->columnFactory->create($this->attribute, $this->context);
87+
$this->assertEquals(
88+
$this->column,
89+
$object,
90+
'Object must be the same which the ui component factory creates.'
91+
);
92+
}
93+
94+
/**
95+
* Tests create method with not filterable in grid attribute.
96+
*
97+
* @param array $filterModifiers
98+
* @param null|string $filter
99+
*
100+
* @return void
101+
* @dataProvider filterModifiersProvider
102+
*/
103+
public function testCreateWithNotFilterableInGridAttribute(array $filterModifiers, $filter)
104+
{
105+
$componentFactoryArgument = [
106+
'data' => [
107+
'config' => [
108+
'label' => __(null),
109+
'dataType' => 'text',
110+
'add_field' => true,
111+
'visible' => null,
112+
'filter' => $filter,
113+
'component' => 'Magento_Ui/js/grid/columns/column',
114+
],
115+
],
116+
'context' => $this->context,
117+
];
118+
119+
$this->context->method('getRequestParam')
120+
->with(FilterModifier::FILTER_MODIFIER, [])
121+
->willReturn($filterModifiers);
122+
$this->attribute->method('getIsFilterableInGrid')
123+
->willReturn(false);
124+
$this->attribute->method('getAttributeCode')
125+
->willReturn('color');
126+
127+
$this->uiComponentFactory->expects($this->once())
128+
->method('create')
129+
->with($this->anything(), $this->anything(), $componentFactoryArgument);
130+
131+
$this->columnFactory->create($this->attribute, $this->context);
132+
}
133+
134+
/**
135+
* Filter modifiers data provider.
136+
*
137+
* @return array
138+
*/
139+
public function filterModifiersProvider(): array
140+
{
141+
return [
142+
'without' => [
143+
'filter_modifiers' => [],
144+
'filter' => null,
145+
],
146+
'with' => [
147+
'filter_modifiers' => [
148+
'color' => [
149+
'condition_type' => 'notnull',
150+
],
151+
],
152+
'filter' => 'text',
153+
],
154+
];
155+
}
156+
}

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Ui\Component;
77

8+
use Magento\Ui\Component\Filters\FilterModifier;
9+
810
/**
911
* @api
1012
* @since 100.0.2
@@ -54,13 +56,15 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
5456
*/
5557
public function create($attribute, $context, array $config = [])
5658
{
59+
$filterModifiers = $context->getRequestParam(FilterModifier::FILTER_MODIFIER, []);
60+
5761
$columnName = $attribute->getAttributeCode();
5862
$config = array_merge([
5963
'label' => __($attribute->getDefaultFrontendLabel()),
6064
'dataType' => $this->getDataType($attribute),
6165
'add_field' => true,
6266
'visible' => $attribute->getIsVisibleInGrid(),
63-
'filter' => ($attribute->getIsFilterableInGrid())
67+
'filter' => ($attribute->getIsFilterableInGrid() || array_key_exists($columnName, $filterModifiers))
6468
? $this->getFilterType($attribute->getFrontendInput())
6569
: null,
6670
], $config);

0 commit comments

Comments
 (0)