diff --git a/app/code/Magento/Ui/Component/Filters/Type/Range.php b/app/code/Magento/Ui/Component/Filters/Type/Range.php index 3a270e3b73571..bcd7dbfe91aad 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Range.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Range.php @@ -53,7 +53,7 @@ protected function applyFilter() */ protected function applyFilterByType($type, $value) { - if (!empty($value) && $value !== '0') { + if (is_numeric($value)) { $filter = $this->filterBuilder->setConditionType($type) ->setField($this->getName()) ->setValue($value) diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php index 7b2784751ff9e..b016760c9281f 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php @@ -97,12 +97,33 @@ public function testGetComponentName() * * @param string $name * @param array $filterData - * @param array|null $expectedCondition + * @param array|null $expectedCalls * @dataProvider getPrepareDataProvider * @return void */ - public function testPrepare($name, $filterData, $expectedCondition) + public function testPrepare($name, $filterData, $expectedCalls) { + $filter = $this->getMock( + \Magento\Framework\Api\Filter::class, + [], + [], + '', + false, + false + ); + $this->filterBuilderMock->expects($this->any()) + ->method('setConditionType') + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->any()) + ->method('setField') + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->any()) + ->method('setValue') + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->any()) + ->method('create') + ->willReturn($filter); + $this->contextMock->expects($this->any()) ->method('getNamespace') ->willReturn(Range::NAME); @@ -110,9 +131,9 @@ public function testPrepare($name, $filterData, $expectedCondition) ->method('addComponentDefinition') ->with(Range::NAME, ['extends' => Range::NAME]); $this->contextMock->expects($this->any()) - ->method('getRequestParam') - ->with(UiContext::FILTER_VAR) + ->method('getFiltersParams') ->willReturn($filterData); + /** @var DataProviderInterface $dataProvider */ $dataProvider = $this->getMockForAbstractClass( \Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface::class, @@ -120,14 +141,14 @@ public function testPrepare($name, $filterData, $expectedCondition) '', false ); - $this->contextMock->expects($this->any()) + + $this->contextMock->expects($this->atLeastOnce()) ->method('getDataProvider') ->willReturn($dataProvider); - if ($expectedCondition !== null) { - $dataProvider->expects($this->any()) - ->method('addFilter') - ->with($expectedCondition, $name); - } + + $dataProvider->expects($this->exactly($expectedCalls)) + ->method('addFilter') + ->with($filter); $range = new Range( $this->contextMock, @@ -149,37 +170,67 @@ public function getPrepareDataProvider() [ 'test_date', ['test_date' => ['from' => 0, 'to' => 1]], - ['from' => null, 'orig_from' => 0, 'to' => 1], + 2 ], [ 'test_date', ['test_date' => ['from' => '', 'to' => 2]], - ['from' => null, 'orig_from' => '', 'to' => 2], + 1 ], [ 'test_date', ['test_date' => ['from' => 1, 'to' => '']], - ['from' => 1, 'orig_to' => '', 'to' => null], + 1 ], [ 'test_date', ['test_date' => ['from' => 1, 'to' => 0]], - ['from' => 1, 'orig_to' => 0, 'to' => null], + 2 ], [ 'test_date', ['test_date' => ['from' => 1, 'to' => 2]], - ['from' => 1, 'to' => 2], + 2 + ], + [ + 'test_date', + ['test_date' => ['from' => 0, 'to' => 0]], + 2 + ], + [ + 'test_date', + ['test_date' => ['from' => '0', 'to' => '0']], + 2 + ], + [ + 'test_date', + ['test_date' => ['from' => '0.0', 'to' => 1]], + 2 ], [ 'test_date', ['test_date' => ['from' => '', 'to' => '']], - null, + 0 + ], + [ + 'test_date', + ['test_date' => ['from' => 'a', 'to' => 'b']], + 0 + ], + [ + 'test_date', + ['test_date' => ['from' => '1']], + 1 + ], + [ + 'test_date', + ['test_date' => ['to' => '1']], + 1 ], [ 'test_date', ['test_date' => []], - null, + 0 ], ]; }