3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Ui \Test \Unit \Model \Export ;
7
9
8
10
use Magento \Framework \Api \Search \DocumentInterface ;
11
+ use Magento \Framework \Locale \ResolverInterface ;
12
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
9
13
use Magento \Framework \View \Element \UiComponentInterface ;
10
14
use Magento \Ui \Component \Listing \Columns ;
11
15
use Magento \Ui \Component \Listing \Columns \Column ;
12
16
use Magento \Ui \Component \MassAction \Filter ;
13
17
use Magento \Ui \Model \Export \MetadataProvider ;
14
18
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
15
19
20
+ /**
21
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22
+ */
16
23
class MetadataProviderTest extends \PHPUnit \Framework \TestCase
17
24
{
18
25
/**
19
26
* @var MetadataProvider
20
27
*/
21
- protected $ model ;
28
+ private $ model ;
22
29
23
30
/**
24
31
* @var Filter | \PHPUnit_Framework_MockObject_MockObject
25
32
*/
26
- protected $ filter ;
33
+ private $ filter ;
34
+
35
+ /**
36
+ * @var TimezoneInterface | \PHPUnit_Framework_MockObject_MockObject
37
+ */
38
+ private $ localeDate ;
27
39
40
+ /**
41
+ * @var ResolverInterface | \PHPUnit_Framework_MockObject_MockObject
42
+ */
43
+ private $ localeResolver ;
44
+
45
+ /**
46
+ * @inheritdoc
47
+ */
28
48
protected function setUp ()
29
49
{
30
50
$ this ->filter = $ this ->getMockBuilder (\Magento \Ui \Component \MassAction \Filter::class)
31
51
->disableOriginalConstructor ()
32
52
->getMock ();
33
53
54
+ $ this ->localeDate = $ this ->getMockBuilder (\Magento \Framework \Stdlib \DateTime \TimezoneInterface::class)
55
+ ->disableOriginalConstructor ()
56
+ ->getMock ();
57
+
58
+ $ this ->localeResolver = $ this ->getMockBuilder (\Magento \Framework \Locale \ResolverInterface::class)
59
+ ->disableOriginalConstructor ()
60
+ ->getMock ();
61
+
62
+ $ this ->localeResolver ->expects ($ this ->any ())
63
+ ->method ('getLocale ' )
64
+ ->willReturn (null );
65
+
34
66
$ objectManager = new ObjectManager ($ this );
35
67
$ this ->model = $ objectManager ->getObject (
36
68
\Magento \Ui \Model \Export \MetadataProvider::class,
37
69
[
38
70
'filter ' => $ this ->filter ,
71
+ 'localeDate ' => $ this ->localeDate ,
72
+ 'localeResolver ' => $ this ->localeResolver ,
73
+ 'data ' => ['component_name ' => ['field ' ]],
39
74
]
40
75
);
41
76
}
@@ -96,12 +131,12 @@ public function testGetFields()
96
131
* @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject
97
132
*/
98
133
protected function prepareColumns (
99
- $ componentName ,
100
- $ columnName ,
101
- $ columnLabel ,
102
- $ columnActionsName = 'actions_name ' ,
103
- $ columnActionsLabel = 'actions_label '
104
- ) {
134
+ string $ componentName ,
135
+ string $ columnName ,
136
+ string $ columnLabel ,
137
+ string $ columnActionsName = 'actions_name ' ,
138
+ string $ columnActionsLabel = 'actions_label '
139
+ ): UiComponentInterface {
105
140
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
106
141
$ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
107
142
->getMockForAbstractClass ();
@@ -165,7 +200,7 @@ protected function prepareColumns(
165
200
* @param array $expected
166
201
* @dataProvider getRowDataProvider
167
202
*/
168
- public function testGetRowData ($ key , $ fields , $ options , $ expected )
203
+ public function testGetRowData (string $ key , array $ fields , array $ options , array $ expected )
169
204
{
170
205
/** @var DocumentInterface|\PHPUnit_Framework_MockObject_MockObject $document */
171
206
$ document = $ this ->getMockBuilder (\Magento \Framework \Api \Search \DocumentInterface::class)
@@ -192,7 +227,7 @@ public function testGetRowData($key, $fields, $options, $expected)
192
227
/**
193
228
* @return array
194
229
*/
195
- public function getRowDataProvider ()
230
+ public function getRowDataProvider (): array
196
231
{
197
232
return [
198
233
[
@@ -236,7 +271,7 @@ public function getRowDataProvider()
236
271
* @param array $expected
237
272
* @dataProvider getOptionsDataProvider
238
273
*/
239
- public function testGetOptions ($ filter , $ options , $ expected )
274
+ public function testGetOptions (string $ filter , array $ options , array $ expected )
240
275
{
241
276
$ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
242
277
->getMockForAbstractClass ();
@@ -285,7 +320,7 @@ public function testGetOptions($filter, $options, $expected)
285
320
/**
286
321
* @return array
287
322
*/
288
- public function getOptionsDataProvider ()
323
+ public function getOptionsDataProvider (): array
289
324
{
290
325
return [
291
326
[
@@ -347,4 +382,55 @@ public function getOptionsDataProvider()
347
382
],
348
383
];
349
384
}
385
+
386
+ /**
387
+ * Test for convertDate function.
388
+ *
389
+ * @param string $fieldValue
390
+ * @param string $expected
391
+ * @dataProvider convertDateProvider
392
+ * @covers \Magento\Ui\Model\Export\MetadataProvider::convertDate()
393
+ */
394
+ public function testConvertDate (string $ fieldValue , string $ expected )
395
+ {
396
+ $ componentName = 'component_name ' ;
397
+ /** @var DocumentInterface|\PHPUnit_Framework_MockObject_MockObject $document */
398
+ $ document = $ this ->getMockBuilder (\Magento \Framework \DataObject::class)
399
+ ->disableOriginalConstructor ()
400
+ ->getMock ();
401
+
402
+ $ document ->expects ($ this ->once ())
403
+ ->method ('getData ' )
404
+ ->with ('field ' )
405
+ ->willReturn ($ fieldValue );
406
+
407
+ $ this ->localeDate ->expects ($ this ->once ())
408
+ ->method ('date ' )
409
+ ->willReturn (new \DateTime ($ fieldValue , new \DateTimeZone ('UTC ' )));
410
+
411
+ $ document ->expects ($ this ->once ())
412
+ ->method ('setData ' )
413
+ ->with ('field ' , $ expected );
414
+
415
+ $ this ->model ->convertDate ($ document , $ componentName );
416
+ }
417
+
418
+ /**
419
+ * Data provider for testConvertDate.
420
+ *
421
+ * @return array
422
+ */
423
+ public function convertDateProvider (): array
424
+ {
425
+ return [
426
+ [
427
+ 'fieldValue ' => '@1534505233 ' ,
428
+ 'expected ' => 'Aug 17, 2018 11:27:13 AM ' ,
429
+ ],
430
+ [
431
+ 'fieldValue ' => '@1534530000 ' ,
432
+ 'expected ' => 'Aug 17, 2018 06:20:00 PM ' ,
433
+ ],
434
+ ];
435
+ }
350
436
}
0 commit comments