Skip to content

Commit e9c704b

Browse files
committed
MC-5233: DateTime product attributes support
1 parent f5a7ac9 commit e9c704b

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DatetimeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function setUp()
5656

5757
/**
5858
* Test to retrieve attribute value
59-
*
59+
*
6060
* @param string $frontendInput
6161
* @param int $timeType
6262
* @dataProvider getValueDataProvider

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public function getPrepareDataProvider()
239239
* @param array $filterData
240240
* @param array $expectedCondition
241241
* @param MockObject $uiComponent
242+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
242243
*/
243244
private function processFilters(
244245
string $name,
@@ -257,18 +258,22 @@ private function processFilters(
257258
$from = new \DateTime($filterData[$name]['from']);
258259
$to = new \DateTime($filterData[$name]['to']);
259260
$uiComponent->method('convertDatetime')
260-
->willReturnMap([
261-
[$filterData[$name]['from'], true, $from],
262-
[$filterData[$name]['to'], true, $to],
263-
]);
261+
->willReturnMap(
262+
[
263+
[$filterData[$name]['from'], true, $from],
264+
[$filterData[$name]['to'], true, $to],
265+
]
266+
);
264267
} else {
265268
$from = new \DateTime($filterData[$name]['from']);
266269
$to = new \DateTime($filterData[$name]['to'] . ' 23:59:59');
267270
$uiComponent->method('convertDate')
268-
->willReturnMap([
269-
[$filterData[$name]['from'], 0, 0, 0, true, $from],
270-
[$filterData[$name]['to'], 23, 59, 59, true, $to],
271-
]);
271+
->willReturnMap(
272+
[
273+
[$filterData[$name]['from'], 0, 0, 0, true, $from],
274+
[$filterData[$name]['to'], 23, 59, 59, true, $to],
275+
]
276+
);
272277
}
273278
}
274279

app/code/Magento/Ui/Test/Unit/Component/FiltersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function setUp()
5858

5959
/**
6060
* Test to Update filter component according to $component
61-
*
61+
*
6262
* @param string $filterType
6363
* @param string $filterName
6464
* @dataProvider updateDataProvider

dev/tests/integration/testsuite/Magento/Eav/Model/Entity/AttributeTest.php

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,54 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\Eav\Model\Entity;
109

11-
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\Locale\ResolverInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
1315

14-
class AttributeTest extends \PHPUnit\Framework\TestCase
16+
/**
17+
* Class to test EAV Entity attribute model
18+
*/
19+
class AttributeTest extends TestCase
1520
{
1621
/**
1722
* @var Attribute
1823
*/
1924
private $attribute;
2025

2126
/**
22-
* @var \Magento\Framework\ObjectManagerInterface
27+
* @var ObjectManagerInterface
2328
*/
2429
private $objectManager;
2530

2631
/**
2732
* @var ResolverInterface
2833
*/
29-
private $_localeResolver;
34+
private $localeResolver;
3035

3136
/**
32-
* {@inheritdoc}
37+
* @inheritdoc
3338
*/
3439
protected function setUp()
3540
{
3641
$this->objectManager = Bootstrap::getObjectManager();
3742
$this->attribute = $this->objectManager->get(Attribute::class);
38-
$this->_localeResolver = $this->objectManager->get(ResolverInterface::class);
43+
$this->localeResolver = $this->objectManager->get(ResolverInterface::class);
3944
}
4045

4146
/**
42-
* {@inheritdoc}
47+
* @inheritdoc
4348
*/
4449
protected function tearDown()
4550
{
4651
$this->attribute = null;
4752
$this->objectManager = null;
48-
$this->_localeResolver = null;
53+
$this->localeResolver = null;
4954
}
5055

5156
/**
@@ -56,11 +61,17 @@ protected function tearDown()
5661
* @dataProvider beforeSaveDataProvider
5762
* @throws
5863
*/
59-
public function testBeforeSave($defaultValue, $backendType, $locale, $expected)
60-
{
64+
public function testBeforeSave(
65+
string $defaultValue,
66+
string $backendType,
67+
string $frontendInput,
68+
string $locale,
69+
string $expected
70+
) {
6171
$this->attribute->setDefaultValue($defaultValue);
6272
$this->attribute->setBackendType($backendType);
63-
$this->_localeResolver->setLocale($locale);
73+
$this->attribute->setFrontendInput($frontendInput);
74+
$this->localeResolver->setLocale($locale);
6475
$this->attribute->beforeSave();
6576

6677
$this->assertEquals($expected, $this->attribute->getDefaultValue());
@@ -74,13 +85,15 @@ public function testBeforeSave($defaultValue, $backendType, $locale, $expected)
7485
public function beforeSaveDataProvider()
7586
{
7687
return [
77-
['21/07/18', 'datetime', 'en_AU', '2018-07-21 00:00:00'],
78-
['07/21/18', 'datetime', 'en_US', '2018-07-21 00:00:00'],
79-
['21/07/18', 'datetime', 'fr_FR', '2018-07-21 00:00:00'],
80-
['21/07/18', 'datetime', 'de_DE', '2018-07-21 00:00:00'],
81-
['21/07/18', 'datetime', 'uk_UA', '2018-07-21 00:00:00'],
82-
['100.50', 'decimal', 'en_US', '100.50'],
83-
['100,50', 'decimal', 'uk_UA', '100.5'],
88+
['21/07/18', 'datetime', 'date', 'en_AU', '2018-07-21 00:00:00'],
89+
['07/21/18', 'datetime', 'date', 'en_US', '2018-07-21 00:00:00'],
90+
['21/07/18', 'datetime', 'date', 'fr_FR', '2018-07-21 00:00:00'],
91+
['21/07/18', 'datetime', 'date', 'de_DE', '2018-07-21 00:00:00'],
92+
['21/07/18', 'datetime', 'date', 'uk_UA', '2018-07-21 00:00:00'],
93+
['100.50', 'decimal', 'decimal', 'en_US', '100.50'],
94+
['100,50', 'decimal', 'decimal', 'uk_UA', '100.5'],
95+
['07/21/2019 2:30 PM', 'datetime', 'datetime', 'en_US', '2019-07-21 21:30:00'],
96+
['21.07.2019 14:30', 'datetime', 'datetime', 'uk_UA', '2019-07-21 21:30:00'],
8497
];
8598
}
8699

@@ -90,13 +103,13 @@ public function beforeSaveDataProvider()
90103
* @param string $locale
91104
* @param string $expected
92105
* @dataProvider beforeSaveErrorDataDataProvider
93-
* @expectedException \Magento\Framework\Exception\LocalizedException
106+
* @expectedException LocalizedException
94107
*/
95108
public function testBeforeSaveErrorData($defaultValue, $backendType, $locale, $expected)
96109
{
97110
$this->attribute->setDefaultValue($defaultValue);
98111
$this->attribute->setBackendType($backendType);
99-
$this->_localeResolver->setLocale($locale);
112+
$this->localeResolver->setLocale($locale);
100113
$this->attribute->beforeSave();
101114

102115
$this->expectExceptionMessage($expected);

0 commit comments

Comments
 (0)