3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
declare (strict_types=1 );
8
7
9
8
namespace Magento \Eav \Model \Entity ;
10
9
11
- use Magento \TestFramework \ Helper \ Bootstrap ;
10
+ use Magento \Framework \ Exception \ LocalizedException ;
12
11
use Magento \Framework \Locale \ResolverInterface ;
12
+ use Magento \Framework \ObjectManagerInterface ;
13
+ use Magento \TestFramework \Helper \Bootstrap ;
14
+ use PHPUnit \Framework \TestCase ;
13
15
14
- class AttributeTest extends \PHPUnit \Framework \TestCase
16
+ /**
17
+ * Class to test EAV Entity attribute model
18
+ */
19
+ class AttributeTest extends TestCase
15
20
{
16
21
/**
17
22
* @var Attribute
18
23
*/
19
24
private $ attribute ;
20
25
21
26
/**
22
- * @var \Magento\Framework\ ObjectManagerInterface
27
+ * @var ObjectManagerInterface
23
28
*/
24
29
private $ objectManager ;
25
30
26
31
/**
27
32
* @var ResolverInterface
28
33
*/
29
- private $ _localeResolver ;
34
+ private $ localeResolver ;
30
35
31
36
/**
32
- * { @inheritdoc}
37
+ * @inheritdoc
33
38
*/
34
39
protected function setUp ()
35
40
{
36
41
$ this ->objectManager = Bootstrap::getObjectManager ();
37
42
$ this ->attribute = $ this ->objectManager ->get (Attribute::class);
38
- $ this ->_localeResolver = $ this ->objectManager ->get (ResolverInterface::class);
43
+ $ this ->localeResolver = $ this ->objectManager ->get (ResolverInterface::class);
39
44
}
40
45
41
46
/**
42
- * { @inheritdoc}
47
+ * @inheritdoc
43
48
*/
44
49
protected function tearDown ()
45
50
{
46
51
$ this ->attribute = null ;
47
52
$ this ->objectManager = null ;
48
- $ this ->_localeResolver = null ;
53
+ $ this ->localeResolver = null ;
49
54
}
50
55
51
56
/**
@@ -56,11 +61,17 @@ protected function tearDown()
56
61
* @dataProvider beforeSaveDataProvider
57
62
* @throws
58
63
*/
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
+ ) {
61
71
$ this ->attribute ->setDefaultValue ($ defaultValue );
62
72
$ this ->attribute ->setBackendType ($ backendType );
63
- $ this ->_localeResolver ->setLocale ($ locale );
73
+ $ this ->attribute ->setFrontendInput ($ frontendInput );
74
+ $ this ->localeResolver ->setLocale ($ locale );
64
75
$ this ->attribute ->beforeSave ();
65
76
66
77
$ this ->assertEquals ($ expected , $ this ->attribute ->getDefaultValue ());
@@ -74,13 +85,15 @@ public function testBeforeSave($defaultValue, $backendType, $locale, $expected)
74
85
public function beforeSaveDataProvider ()
75
86
{
76
87
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 ' ],
84
97
];
85
98
}
86
99
@@ -90,13 +103,13 @@ public function beforeSaveDataProvider()
90
103
* @param string $locale
91
104
* @param string $expected
92
105
* @dataProvider beforeSaveErrorDataDataProvider
93
- * @expectedException \Magento\Framework\Exception\ LocalizedException
106
+ * @expectedException LocalizedException
94
107
*/
95
108
public function testBeforeSaveErrorData ($ defaultValue , $ backendType , $ locale , $ expected )
96
109
{
97
110
$ this ->attribute ->setDefaultValue ($ defaultValue );
98
111
$ this ->attribute ->setBackendType ($ backendType );
99
- $ this ->_localeResolver ->setLocale ($ locale );
112
+ $ this ->localeResolver ->setLocale ($ locale );
100
113
$ this ->attribute ->beforeSave ();
101
114
102
115
$ this ->expectExceptionMessage ($ expected );
0 commit comments