Skip to content

Commit 7cb20bb

Browse files
committed
MAGETWO-70327: Customer admin grid incorrectly filters by Date of Birth field
1 parent d43d6f8 commit 7cb20bb

File tree

2 files changed

+16
-79
lines changed

2 files changed

+16
-79
lines changed

app/code/Magento/Braintree/Test/Unit/Ui/Component/Report/Filters/Type/DateRangeTest.php

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,14 @@ protected function setUp()
6969
->disableOriginalConstructor()
7070
->getMock();
7171

72-
$this->dataProviderMock = $this->getMockForAbstractClass(DataProviderInterface::class);
73-
7472
$this->contextMock->expects($this->any())
7573
->method('getNamespace')
7674
->willReturn(DateRange::NAME);
7775
$this->contextMock->expects($this->any())
7876
->method('addComponentDefinition')
7977
->with(DateRange::NAME, ['extends' => DateRange::NAME]);
8078

81-
$this->contextMock->expects($this->any())
82-
->method('getDataProvider')
83-
->willReturn($this->dataProviderMock);
79+
$this->dataProviderMock = $this->getMockForAbstractClass(DataProviderInterface::class);
8480
}
8581

8682
/**
@@ -95,16 +91,21 @@ protected function setUp()
9591
*/
9692
public function testPrepare($name, $filterData, $expectedCondition)
9793
{
98-
$this->contextMock->expects($this->any())
99-
->method('getFiltersParams')
100-
->willReturn($filterData);
101-
94+
/** @var FormDate PHPUnit_Framework_MockObject_MockObject|$uiComponent */
10295
$uiComponent = $this->getMockBuilder(FormDate::class)->disableOriginalConstructor()->getMock();
10396

10497
$uiComponent->expects($this->any())
10598
->method('getContext')
10699
->willReturn($this->contextMock);
107100

101+
$this->contextMock->expects($this->any())
102+
->method('getFiltersParams')
103+
->willReturn($filterData);
104+
105+
$this->contextMock->expects($this->any())
106+
->method('getDataProvider')
107+
->willReturn($this->dataProviderMock);
108+
108109
if ($expectedCondition !== null) {
109110
if (is_string($filterData[$name])) {
110111
$uiComponent->expects(static::once())
@@ -115,11 +116,11 @@ public function testPrepare($name, $filterData, $expectedCondition)
115116
$uiComponent->method('convertDate')
116117
->willReturnMap([
117118
[
118-
$filterData[$name]['from'],
119+
$filterData[$name]['from'], 0, 0, 0, true,
119120
new \DateTime($filterData[$name]['from'], new \DateTimeZone('UTC'))
120121
],
121122
[
122-
$filterData[$name]['to'],
123+
$filterData[$name]['to'], 23, 59, 59, true,
123124
new \DateTime($filterData[$name]['to'] . ' 23:59:00', new \DateTimeZone('UTC'))
124125
],
125126
]);
@@ -158,23 +159,6 @@ public function testPrepare($name, $filterData, $expectedCondition)
158159
->with($filterMock);
159160
break;
160161
}
161-
} else {
162-
$uiComponent->method('convertDate')
163-
->willReturnMap([
164-
[
165-
$filterData[$name]['from'],
166-
new \DateTime($filterData[$name]['from'], new \DateTimeZone('UTC'))
167-
],
168-
[
169-
$filterData[$name]['to'],
170-
new \DateTime($filterData[$name]['to'] . ' 23:59:00', new \DateTimeZone('UTC'))
171-
],
172-
]);
173-
174-
$filterMock = $this->getFilterMockWithoutExpectedCondition();
175-
$this->dataProviderMock->expects(static::exactly(2))
176-
->method('addFilter')
177-
->with($filterMock);
178162
}
179163

180164
$this->uiComponentFactory->expects($this->any())
@@ -226,31 +210,6 @@ private function getFilterMock($name, $expectedType, $expectedDate, &$i)
226210
return $filterMock;
227211
}
228212

229-
/**
230-
* Gets Filter mock without expected condition
231-
*
232-
* @return Filter|\PHPUnit_Framework_MockObject_MockObject
233-
*/
234-
private function getFilterMockWithoutExpectedCondition()
235-
{
236-
$this->filterBuilderMock->expects(static::exactly(2))
237-
->method('setConditionType')
238-
->willReturnSelf();
239-
$this->filterBuilderMock->expects(static::exactly(2))
240-
->method('setField')
241-
->willReturnSelf();
242-
$this->filterBuilderMock->expects(static::exactly(2))
243-
->method('setValue')
244-
->willReturnSelf();
245-
246-
$filterMock = $this->getMock(Filter::class);
247-
$this->filterBuilderMock->expects(static::exactly(2))
248-
->method('create')
249-
->willReturn($filterMock);
250-
251-
return $filterMock;
252-
}
253-
254213
/**
255214
* @return array
256215
*/

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,6 @@ public function testPrepare($name, $filterData, $expectedCondition)
126126

127127
if ($expectedCondition !== null) {
128128
$this->processFilters($name, $filterData, $expectedCondition, $uiComponent);
129-
} else {
130-
$uiComponent->method('convertDate')
131-
->willReturnMap([
132-
[$filterData[$name]['from'], new \DateTime($filterData[$name]['from'])],
133-
[$filterData[$name]['to'], new \DateTime($filterData[$name]['to'] . ' 23:59:59')],
134-
]);
135-
136-
$this->filterBuilderMock->expects(static::exactly(2))
137-
->method('setConditionType')
138-
->willReturnSelf();
139-
$this->filterBuilderMock->expects(static::exactly(2))
140-
->method('setField')
141-
->willReturnSelf();
142-
$this->filterBuilderMock->expects(static::exactly(2))
143-
->method('setValue')
144-
->willReturnSelf();
145-
146-
$filterMock = $this->getMock(Filter::class);
147-
$this->filterBuilderMock->expects(static::exactly(2))
148-
->method('create')
149-
->willReturn($filterMock);
150-
$this->dataProviderMock->expects(static::exactly(2))
151-
->method('addFilter')
152-
->with($filterMock);
153129
}
154130

155131
$this->uiComponentFactory->expects($this->any())
@@ -252,10 +228,12 @@ private function processFilters($name, $filterData, $expectedCondition, $uiCompo
252228
->with($filterData[$name])
253229
->willReturn(new \DateTime($filterData[$name]));
254230
} else {
231+
$from = new \DateTime($filterData[$name]['from']);
232+
$to = new \DateTime($filterData[$name]['to'] . ' 23:59:59');
255233
$uiComponent->method('convertDate')
256234
->willReturnMap([
257-
[$filterData[$name]['from'], new \DateTime($filterData[$name]['from'])],
258-
[$filterData[$name]['to'], new \DateTime($filterData[$name]['to'] . ' 23:59:59')],
235+
[$filterData[$name]['from'], 0, 0, 0, true, $from],
236+
[$filterData[$name]['to'], 23, 59, 59, true, $to],
259237
]);
260238
}
261239

0 commit comments

Comments
 (0)