Skip to content

Commit 0602eb8

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-90134' into 2.3-develop-pr10-2
2 parents 99c8a2c + 3a1cf38 commit 0602eb8

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

app/code/Magento/Ui/Component/Filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function update(UiComponentInterface $component)
8282
return;
8383
}
8484

85-
if (isset($this->filterMap[$filterType])) {
85+
if (isset($this->filterMap[$filterType]) && !isset($this->columnFilters[$component->getName()])) {
8686
$filterComponent = $this->uiComponentFactory->create(
8787
$component->getName(),
8888
$this->filterMap[$filterType],
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\Ui\Test\Unit\Component;
9+
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
use \Magento\Ui\Component\Filters;
12+
13+
/**
14+
* Unit tests for \Magento\Ui\Component\Filters class
15+
*/
16+
class FiltersTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/** @var Filters|\PHPUnit_Framework_MockObject_MockObject */
19+
private $filters;
20+
21+
/** @var \Magento\Framework\View\Element\UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject */
22+
private $uiComponentInterface;
23+
24+
/** @var \Magento\Framework\View\Element\UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject */
25+
private $uiComponentFactory;
26+
27+
/** @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject */
28+
private $context;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
protected function setUp()
34+
{
35+
$objectManager = new ObjectManager($this);
36+
$this->uiComponentInterface = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
37+
->disableOriginalConstructor()
38+
->getMock();
39+
$this->uiComponentFactory = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentFactory::class)
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
43+
->disableOriginalConstructor()
44+
->getMock();
45+
$this->filters = $objectManager->getObject(
46+
Filters::class,
47+
[
48+
'columnFilters' => ['select' => $this->uiComponentInterface],
49+
'uiComponentFactory' => $this->uiComponentFactory,
50+
'context' => $this->context,
51+
]
52+
);
53+
}
54+
55+
public function testUpdate()
56+
{
57+
$componentName = 'component_name';
58+
$componentConfig = [0, 1, 2];
59+
$columnInterface = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns\ColumnInterface::class)
60+
->disableOriginalConstructor()
61+
->setMethods(['getData', 'getName', 'getConfiguration'])
62+
->getMockForAbstractClass();
63+
$columnInterface->expects($this->atLeastOnce())->method('getData')->with('config/filter')->willReturn('text');
64+
$columnInterface->expects($this->atLeastOnce())->method('getName')->willReturn($componentName);
65+
$columnInterface->expects($this->once())->method('getConfiguration')->willReturn($componentConfig);
66+
$filterComponent = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
67+
->disableOriginalConstructor()
68+
->setMethods(['setData', 'prepare'])
69+
->getMockForAbstractClass();
70+
$filterComponent->expects($this->once())->method('setData')->with('config', $componentConfig)
71+
->willReturnSelf();
72+
$filterComponent->expects($this->once())->method('prepare')->willReturnSelf();
73+
$this->uiComponentFactory->expects($this->once())->method('create')
74+
->with($componentName, 'filterInput', ['context' => $this->context])
75+
->willReturn($filterComponent);
76+
77+
$this->filters->update($columnInterface);
78+
/** Verify that filter is already set and it wouldn't be set again */
79+
$this->filters->update($columnInterface);
80+
}
81+
}

0 commit comments

Comments
 (0)