3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Eav \Test \Unit \Model \Attribute \Data ;
7
8
9
+ use Magento \Framework \Locale \ResolverInterface ;
10
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
11
+
8
12
class MultilineTest extends \PHPUnit \Framework \TestCase
9
13
{
10
14
/**
@@ -13,15 +17,18 @@ class MultilineTest extends \PHPUnit\Framework\TestCase
13
17
protected $ model ;
14
18
15
19
/**
16
- * @var \PHPUnit_Framework_MockObject_MockObject
20
+ * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Stdlib\StringUtils
17
21
*/
18
22
protected $ stringMock ;
19
23
20
24
protected function setUp ()
21
25
{
22
- $ timezoneMock = $ this ->createMock (\Magento \Framework \Stdlib \DateTime \TimezoneInterface::class);
26
+ /** @var \PHPUnit_Framework_MockObject_MockObject | TimezoneInterface $timezoneMock */
27
+ $ timezoneMock = $ this ->createMock (TimezoneInterface::class);
28
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Psr\Log\LoggerInterface $loggerMock */
23
29
$ loggerMock = $ this ->createMock (\Psr \Log \LoggerInterface::class);
24
- $ localeResolverMock = $ this ->createMock (\Magento \Framework \Locale \ResolverInterface::class);
30
+ /** @var \PHPUnit_Framework_MockObject_MockObject | ResolverInterface $localeResolverMock */
31
+ $ localeResolverMock = $ this ->createMock (ResolverInterface::class);
25
32
$ this ->stringMock = $ this ->createMock (\Magento \Framework \Stdlib \StringUtils::class);
26
33
27
34
$ this ->model = new \Magento \Eav \Model \Attribute \Data \Multiline (
@@ -33,19 +40,23 @@ protected function setUp()
33
40
}
34
41
35
42
/**
36
- * @covers \Magento\Eav\Model\Attribute\Data\Multiline::extractValue
43
+ * @covers \Magento\Eav\Model\Attribute\Data\Multiline::extractValue
37
44
*
38
45
* @param mixed $param
39
46
* @param mixed $expectedResult
40
47
* @dataProvider extractValueDataProvider
41
48
*/
42
49
public function testExtractValue ($ param , $ expectedResult )
43
50
{
51
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\RequestInterface $requestMock */
44
52
$ requestMock = $ this ->createMock (\Magento \Framework \App \RequestInterface::class);
53
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Eav\Model\Attribute $attributeMock */
45
54
$ attributeMock = $ this ->createMock (\Magento \Eav \Model \Attribute::class);
46
55
47
56
$ requestMock ->expects ($ this ->once ())->method ('getParam ' )->will ($ this ->returnValue ($ param ));
48
- $ attributeMock ->expects ($ this ->once ())->method ('getAttributeCode ' )->will ($ this ->returnValue ('attributeCode ' ));
57
+ $ attributeMock ->expects ($ this ->once ())
58
+ ->method ('getAttributeCode ' )
59
+ ->will ($ this ->returnValue ('attributeCode ' ));
49
60
50
61
$ this ->model ->setAttribute ($ attributeMock );
51
62
$ this ->assertEquals ($ expectedResult , $ this ->model ->extractValue ($ requestMock ));
@@ -69,17 +80,21 @@ public function extractValueDataProvider()
69
80
}
70
81
71
82
/**
72
- * @covers \Magento\Eav\Model\Attribute\Data\Multiline::outputValue
83
+ * @covers \Magento\Eav\Model\Attribute\Data\Multiline::outputValue
73
84
*
74
85
* @param string $format
75
86
* @param mixed $expectedResult
76
87
* @dataProvider outputValueDataProvider
77
88
*/
78
89
public function testOutputValue ($ format , $ expectedResult )
79
90
{
91
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Model\AbstractModel $entityMock */
80
92
$ entityMock = $ this ->createMock (\Magento \Framework \Model \AbstractModel::class);
81
- $ entityMock ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ("value1 \nvalue2 " ));
93
+ $ entityMock ->expects ($ this ->once ())
94
+ ->method ('getData ' )
95
+ ->will ($ this ->returnValue ("value1 \nvalue2 " ));
82
96
97
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Eav\Model\Attribute $attributeMock */
83
98
$ attributeMock = $ this ->createMock (\Magento \Eav \Model \Attribute::class);
84
99
85
100
$ this ->model ->setEntity ($ entityMock );
@@ -113,8 +128,8 @@ public function outputValueDataProvider()
113
128
}
114
129
115
130
/**
116
- * @covers \Magento\Eav\Model\Attribute\Data\Multiline::validateValue
117
- * @covers \Magento\Eav\Model\Attribute\Data\Text::validateValue
131
+ * @covers \Magento\Eav\Model\Attribute\Data\Multiline::validateValue
132
+ * @covers \Magento\Eav\Model\Attribute\Data\Text::validateValue
118
133
*
119
134
* @param mixed $value
120
135
* @param bool $isAttributeRequired
@@ -124,14 +139,23 @@ public function outputValueDataProvider()
124
139
*/
125
140
public function testValidateValue ($ value , $ isAttributeRequired , $ rules , $ expectedResult )
126
141
{
142
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Model\AbstractModel $entityMock */
127
143
$ entityMock = $ this ->createMock (\Magento \Framework \Model \AbstractModel::class);
128
- $ entityMock ->expects ($ this ->any ())->method ('getDataUsingMethod ' )->will ($ this ->returnValue ("value1 \nvalue2 " ));
144
+ $ entityMock ->expects ($ this ->any ())
145
+ ->method ('getDataUsingMethod ' )
146
+ ->will ($ this ->returnValue ("value1 \nvalue2 " ));
129
147
148
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Eav\Model\Attribute $attributeMock */
130
149
$ attributeMock = $ this ->createMock (\Magento \Eav \Model \Attribute::class);
131
150
$ attributeMock ->expects ($ this ->any ())->method ('getMultilineCount ' )->will ($ this ->returnValue (2 ));
132
151
$ attributeMock ->expects ($ this ->any ())->method ('getValidateRules ' )->will ($ this ->returnValue ($ rules ));
133
- $ attributeMock ->expects ($ this ->any ())->method ('getStoreLabel ' )->will ($ this ->returnValue ('Label ' ));
134
- $ attributeMock ->expects ($ this ->any ())->method ('getIsRequired ' )->will ($ this ->returnValue ($ isAttributeRequired ));
152
+ $ attributeMock ->expects ($ this ->any ())
153
+ ->method ('getStoreLabel ' )
154
+ ->will ($ this ->returnValue ('Label ' ));
155
+
156
+ $ attributeMock ->expects ($ this ->any ())
157
+ ->method ('getIsRequired ' )
158
+ ->will ($ this ->returnValue ($ isAttributeRequired ));
135
159
136
160
$ this ->stringMock ->expects ($ this ->any ())->method ('strlen ' )->will ($ this ->returnValue (5 ));
137
161
@@ -159,21 +183,21 @@ public function validateValueDataProvider()
159
183
'expectedResult ' => true ,
160
184
],
161
185
[
162
- 'value ' => ['value1 ' , 'value2 ' ],
186
+ 'value ' => ['value1 ' , 'value2 ' ],
163
187
'isAttributeRequired ' => false ,
164
188
'rules ' => [],
165
189
'expectedResult ' => true ,
166
190
],
167
191
[
168
192
'value ' => 'value ' ,
169
193
'isAttributeRequired ' => false ,
170
- 'rules ' => ['max_text_length ' => 3 ],
194
+ 'rules ' => ['input_validation ' => ' other ' , ' max_text_length ' => 3 ],
171
195
'expectedResult ' => ['"Label" length must be equal or less than 3 characters. ' ],
172
196
],
173
197
[
174
198
'value ' => 'value ' ,
175
199
'isAttributeRequired ' => false ,
176
- 'rules ' => ['min_text_length ' => 10 ],
200
+ 'rules ' => ['input_validation ' => ' other ' , ' min_text_length ' => 10 ],
177
201
'expectedResult ' => ['"Label" length must be equal or greater than 10 characters. ' ],
178
202
],
179
203
[
0 commit comments