Skip to content

Commit 9bc3fd4

Browse files
MAGETWO-93764: [2.3] Zero value in the email filter field returns all email address
1 parent 8c1bd4c commit 9bc3fd4

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Input extends AbstractFilter
2929
*
3030
* @return void
3131
*/
32-
public function prepare()
32+
public function prepare(): void
3333
{
3434
$this->wrappedComponent = $this->uiComponentFactory->create(
3535
$this->getName(),
@@ -62,12 +62,12 @@ public function prepare()
6262
*
6363
* @return void
6464
*/
65-
protected function applyFilter()
65+
protected function applyFilter(): void
6666
{
6767
if (isset($this->filterData[$this->getName()])) {
6868
$value = str_replace(['%', '_'], ['\%', '\_'], $this->filterData[$this->getName()]);
6969

70-
if (!empty($value)) {
70+
if ($value || $value === '0') {
7171
$filter = $this->filterBuilder->setConditionType('like')
7272
->setField($this->getName())
7373
->setValue(sprintf('%%%s%%', $value))

app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Ui\Test\Unit\Component\Filters\Type;
77

88
use Magento\Framework\View\Element\UiComponent\ContextInterface;
9-
use Magento\Framework\View\Element\UiComponent\ContextInterface as UiContext;
109
use Magento\Framework\View\Element\UiComponentFactory;
1110
use Magento\Framework\View\Element\UiComponentInterface;
1211
use Magento\Ui\Component\Filters\Type\Input;
@@ -37,18 +36,18 @@ class InputTest extends \PHPUnit\Framework\TestCase
3736
protected $filterModifierMock;
3837

3938
/**
40-
* Set up
39+
* @inheritdoc
4140
*/
4241
protected function setUp()
4342
{
4443
$this->contextMock = $this->getMockForAbstractClass(
45-
\Magento\Framework\View\Element\UiComponent\ContextInterface::class,
44+
ContextInterface::class,
4645
[],
4746
'',
4847
false
4948
);
5049
$this->uiComponentFactory = $this->createPartialMock(
51-
\Magento\Framework\View\Element\UiComponentFactory::class,
50+
UiComponentFactory::class,
5251
['create']
5352
);
5453
$this->filterBuilderMock = $this->createMock(\Magento\Framework\Api\FilterBuilder::class);
@@ -63,7 +62,7 @@ protected function setUp()
6362
*
6463
* @return void
6564
*/
66-
public function testGetComponentName()
65+
public function testGetComponentName(): void
6766
{
6867
$this->contextMock->expects($this->never())->method('getProcessor');
6968
$date = new Input(
@@ -86,15 +85,15 @@ public function testGetComponentName()
8685
* @dataProvider getPrepareDataProvider
8786
* @return void
8887
*/
89-
public function testPrepare($name, $filterData, $expectedCondition)
88+
public function testPrepare(string $name, array $filterData, ?array $expectedCondition): void
9089
{
9190
$processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
9291
->disableOriginalConstructor()
9392
->getMock();
9493
$this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($processor);
9594
/** @var UiComponentInterface $uiComponent */
9695
$uiComponent = $this->getMockForAbstractClass(
97-
\Magento\Framework\View\Element\UiComponentInterface::class,
96+
UiComponentInterface::class,
9897
[],
9998
'',
10099
false
@@ -169,14 +168,24 @@ public function testPrepare($name, $filterData, $expectedCondition)
169168
/**
170169
* @return array
171170
*/
172-
public function getPrepareDataProvider()
171+
public function getPrepareDataProvider(): array
173172
{
174173
return [
175174
[
176175
'test_date',
177176
['test_date' => ''],
178177
null,
179178
],
179+
[
180+
'test_date',
181+
['test_date' => null],
182+
null,
183+
],
184+
[
185+
'test_date',
186+
['test_date' => '0'],
187+
['like' => '%0%'],
188+
],
180189
[
181190
'test_date',
182191
['test_date' => 'some_value'],

0 commit comments

Comments
 (0)