Skip to content

Commit 4a4fe88

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-73039' into 2.2-develop-pr47
2 parents 5d3c733 + 187e880 commit 4a4fe88

File tree

2 files changed

+101
-12
lines changed

2 files changed

+101
-12
lines changed

app/code/Magento/Ui/Model/Export/MetadataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(
6060
Filter $filter,
6161
TimezoneInterface $localeDate,
6262
ResolverInterface $localeResolver,
63-
$dateFormat = 'M j, Y H:i:s A',
63+
$dateFormat = 'M j, Y h:i:s A',
6464
array $data = []
6565
) {
6666
$this->filter = $filter;

app/code/Magento/Ui/Test/Unit/Model/Export/MetadataProviderTest.php

Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,74 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Ui\Test\Unit\Model\Export;
79

810
use Magento\Framework\Api\Search\DocumentInterface;
11+
use Magento\Framework\Locale\ResolverInterface;
12+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
913
use Magento\Framework\View\Element\UiComponentInterface;
1014
use Magento\Ui\Component\Listing\Columns;
1115
use Magento\Ui\Component\Listing\Columns\Column;
1216
use Magento\Ui\Component\MassAction\Filter;
1317
use Magento\Ui\Model\Export\MetadataProvider;
1418
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1519

20+
/**
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
*/
1623
class MetadataProviderTest extends \PHPUnit\Framework\TestCase
1724
{
1825
/**
1926
* @var MetadataProvider
2027
*/
21-
protected $model;
28+
private $model;
2229

2330
/**
2431
* @var Filter | \PHPUnit_Framework_MockObject_MockObject
2532
*/
26-
protected $filter;
33+
private $filter;
34+
35+
/**
36+
* @var TimezoneInterface | \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $localeDate;
2739

40+
/**
41+
* @var ResolverInterface | \PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $localeResolver;
44+
45+
/**
46+
* @inheritdoc
47+
*/
2848
protected function setUp()
2949
{
3050
$this->filter = $this->getMockBuilder(\Magento\Ui\Component\MassAction\Filter::class)
3151
->disableOriginalConstructor()
3252
->getMock();
3353

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+
3466
$objectManager = new ObjectManager($this);
3567
$this->model = $objectManager->getObject(
3668
\Magento\Ui\Model\Export\MetadataProvider::class,
3769
[
3870
'filter' => $this->filter,
71+
'localeDate' => $this->localeDate,
72+
'localeResolver' => $this->localeResolver,
73+
'data' => ['component_name' => ['field']],
3974
]
4075
);
4176
}
@@ -96,11 +131,11 @@ public function testGetFields()
96131
* @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject
97132
*/
98133
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'
104139
) {
105140
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
106141
$component = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
@@ -163,9 +198,10 @@ protected function prepareColumns(
163198
* @param array $fields
164199
* @param array $options
165200
* @param array $expected
201+
* @return void
166202
* @dataProvider getRowDataProvider
167203
*/
168-
public function testGetRowData($key, $fields, $options, $expected)
204+
public function testGetRowData(string $key, array $fields, array $options, array $expected)
169205
{
170206
/** @var DocumentInterface|\PHPUnit_Framework_MockObject_MockObject $document */
171207
$document = $this->getMockBuilder(\Magento\Framework\Api\Search\DocumentInterface::class)
@@ -192,7 +228,7 @@ public function testGetRowData($key, $fields, $options, $expected)
192228
/**
193229
* @return array
194230
*/
195-
public function getRowDataProvider()
231+
public function getRowDataProvider(): array
196232
{
197233
return [
198234
[
@@ -234,9 +270,10 @@ public function getRowDataProvider()
234270
* @param string $filter
235271
* @param array $options
236272
* @param array $expected
273+
* @return void
237274
* @dataProvider getOptionsDataProvider
238275
*/
239-
public function testGetOptions($filter, $options, $expected)
276+
public function testGetOptions(string $filter, array $options, array $expected)
240277
{
241278
$component = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
242279
->getMockForAbstractClass();
@@ -285,7 +322,7 @@ public function testGetOptions($filter, $options, $expected)
285322
/**
286323
* @return array
287324
*/
288-
public function getOptionsDataProvider()
325+
public function getOptionsDataProvider(): array
289326
{
290327
return [
291328
[
@@ -347,4 +384,56 @@ public function getOptionsDataProvider()
347384
],
348385
];
349386
}
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+
}
350439
}

0 commit comments

Comments
 (0)