Skip to content

Commit 894dccf

Browse files
committed
ACP2E-2127: Date filter is not working in admin grid.
- Added the test coverage.
1 parent 0264d9e commit 894dccf

File tree

1 file changed

+157
-0
lines changed
  • app/code/Magento/Customer/Test/Unit/Ui/Component/Form/Element/DataType

1 file changed

+157
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Test\Unit\Ui\Component\Form\Element\DataType;
10+
11+
use Exception;
12+
use Magento\Customer\Ui\Component\Form\Element\DataType\Date;
13+
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
14+
use Magento\Ui\Component\Form\Element\DataType\Date as UiComponentDate;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Test for class \Magento\Customer\Ui\Component\Form\Element\DataType\Date
20+
*/
21+
class DateTest extends TestCase
22+
{
23+
/**
24+
* @var Date
25+
*/
26+
protected Date $model;
27+
28+
/**
29+
* @var DateFormatterFactory|MockObject
30+
*/
31+
private $dateFormatterFactoryMock;
32+
33+
/**
34+
* @var UiComponentDate|MockObject
35+
*/
36+
private $subjectMock;
37+
38+
/**
39+
* Set up
40+
*
41+
* @return void
42+
*/
43+
protected function setUp(): void
44+
{
45+
$this->dateFormatterFactoryMock = $this->getMockForAbstractClass(DateFormatterFactory::class);
46+
$this->subjectMock = $this->getMockBuilder(UiComponentDate::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
$this->model = new Date(
50+
$this->dateFormatterFactoryMock
51+
);
52+
}
53+
54+
/**
55+
* Run test for beforeConvertDate() method
56+
*
57+
* @param string $date
58+
* @param string $locale
59+
* @param int $hour
60+
* @param int $minute
61+
* @param int $second
62+
* @param bool $setUtcTimeZone
63+
* @param array $expected
64+
* @return void
65+
* @dataProvider beforeConvertDateDataProvider
66+
* @throws Exception
67+
*/
68+
public function testBeforeConvertDate(
69+
string $date,
70+
string $locale,
71+
int $hour,
72+
int $minute,
73+
int $second,
74+
bool $setUtcTimeZone,
75+
array $expected
76+
): void {
77+
$this->subjectMock->expects($this->once())
78+
->method('getLocale')
79+
->willReturn($locale);
80+
$this->assertEquals(
81+
$expected,
82+
$this->model->beforeConvertDate(
83+
$this->subjectMock,
84+
$date,
85+
$hour,
86+
$minute,
87+
$second,
88+
$setUtcTimeZone
89+
)
90+
);
91+
}
92+
93+
/**
94+
* DataProvider for testBeforeConvertDate()
95+
*
96+
* @return array
97+
*/
98+
public function beforeConvertDateDataProvider(): array
99+
{
100+
return [
101+
[
102+
'2023-10-15',
103+
'en_US',
104+
0,
105+
0,
106+
0,
107+
true,
108+
['10/15/2023', 0, 0, 0, true]
109+
],
110+
[
111+
'10/15/2023',
112+
'en_US',
113+
0,
114+
0,
115+
0,
116+
true,
117+
['10/15/2023', 0, 0, 0, true]
118+
],
119+
[
120+
'2023-10-15',
121+
'en_GB',
122+
0,
123+
0,
124+
0,
125+
true,
126+
['15/10/2023', 0, 0, 0, true]
127+
],
128+
[
129+
'15/10/2023',
130+
'en_GB',
131+
0,
132+
0,
133+
0,
134+
true,
135+
['15/10/2023', 0, 0, 0, true]
136+
],
137+
[
138+
'2023-10-15',
139+
'ja_JP',
140+
0,
141+
0,
142+
0,
143+
true,
144+
['2023/10/15', 0, 0, 0, true]
145+
],
146+
[
147+
'2023/10/15',
148+
'ja_JP',
149+
0,
150+
0,
151+
0,
152+
true,
153+
['2023/10/15', 0, 0, 0, true]
154+
]
155+
];
156+
}
157+
}

0 commit comments

Comments
 (0)