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,11 +131,11 @@ 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 '
134
+ string $ componentName ,
135
+ string $ columnName ,
136
+ string $ columnLabel ,
137
+ string $ columnActionsName = 'actions_name ' ,
138
+ string $ columnActionsLabel = 'actions_label '
104
139
) {
105
140
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
106
141
$ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
@@ -163,9 +198,10 @@ protected function prepareColumns(
163
198
* @param array $fields
164
199
* @param array $options
165
200
* @param array $expected
201
+ * @return void
166
202
* @dataProvider getRowDataProvider
167
203
*/
168
- public function testGetRowData ($ key , $ fields , $ options , $ expected )
204
+ public function testGetRowData (string $ key , array $ fields , array $ options , array $ expected )
169
205
{
170
206
/** @var DocumentInterface|\PHPUnit_Framework_MockObject_MockObject $document */
171
207
$ document = $ this ->getMockBuilder (\Magento \Framework \Api \Search \DocumentInterface::class)
@@ -192,7 +228,7 @@ public function testGetRowData($key, $fields, $options, $expected)
192
228
/**
193
229
* @return array
194
230
*/
195
- public function getRowDataProvider ()
231
+ public function getRowDataProvider (): array
196
232
{
197
233
return [
198
234
[
@@ -234,9 +270,10 @@ public function getRowDataProvider()
234
270
* @param string $filter
235
271
* @param array $options
236
272
* @param array $expected
273
+ * @return void
237
274
* @dataProvider getOptionsDataProvider
238
275
*/
239
- public function testGetOptions ($ filter , $ options , $ expected )
276
+ public function testGetOptions (string $ filter , array $ options , array $ expected )
240
277
{
241
278
$ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
242
279
->getMockForAbstractClass ();
@@ -285,7 +322,7 @@ public function testGetOptions($filter, $options, $expected)
285
322
/**
286
323
* @return array
287
324
*/
288
- public function getOptionsDataProvider ()
325
+ public function getOptionsDataProvider (): array
289
326
{
290
327
return [
291
328
[
@@ -347,4 +384,56 @@ public function getOptionsDataProvider()
347
384
],
348
385
];
349
386
}
387
+
388
+ /**
389
+ * Test for convertDate function.
390
+ *
391
+ * @param string $fieldValue
392
+ * @param string $expected
393
+ * @return void
394
+ * @dataProvider convertDateProvider
395
+ * @covers \Magento\Ui\Model\Export\MetadataProvider::convertDate()
396
+ */
397
+ public function testConvertDate (string $ fieldValue , string $ expected )
398
+ {
399
+ $ componentName = 'component_name ' ;
400
+ /** @var DocumentInterface|\PHPUnit_Framework_MockObject_MockObject $document */
401
+ $ document = $ this ->getMockBuilder (\Magento \Framework \DataObject::class)
402
+ ->disableOriginalConstructor ()
403
+ ->getMock ();
404
+
405
+ $ document ->expects ($ this ->once ())
406
+ ->method ('getData ' )
407
+ ->with ('field ' )
408
+ ->willReturn ($ fieldValue );
409
+
410
+ $ this ->localeDate ->expects ($ this ->once ())
411
+ ->method ('date ' )
412
+ ->willReturn (new \DateTime ($ fieldValue , new \DateTimeZone ('UTC ' )));
413
+
414
+ $ document ->expects ($ this ->once ())
415
+ ->method ('setData ' )
416
+ ->with ('field ' , $ expected );
417
+
418
+ $ this ->model ->convertDate ($ document , $ componentName );
419
+ }
420
+
421
+ /**
422
+ * Data provider for testConvertDate.
423
+ *
424
+ * @return array
425
+ */
426
+ public function convertDateProvider (): array
427
+ {
428
+ return [
429
+ [
430
+ 'fieldValue ' => '@1534505233 ' ,
431
+ 'expected ' => 'Aug 17, 2018 11:27:13 AM ' ,
432
+ ],
433
+ [
434
+ 'fieldValue ' => '@1534530000 ' ,
435
+ 'expected ' => 'Aug 17, 2018 06:20:00 PM ' ,
436
+ ],
437
+ ];
438
+ }
350
439
}
0 commit comments