Skip to content

Commit

Permalink
MAGETWO-65488: [GitHub][PR] Range filter doesn't works with 0 values …
Browse files Browse the repository at this point in the history
…in admin #7103 #8776
  • Loading branch information
magento-team authored Mar 7, 2017
2 parents 3f75fac + 9cc2700 commit 2e012ab
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Ui/Component/Filters/Type/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
85 changes: 68 additions & 17 deletions app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,37 +97,58 @@ 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);
$this->contextMock->expects($this->any())
->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,
[],
'',
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,
Expand All @@ -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
],
];
}
Expand Down

0 comments on commit 2e012ab

Please sign in to comment.