@@ -18,6 +18,11 @@ class DefaultValidatorTest extends \PHPUnit\Framework\TestCase
18
18
*/
19
19
protected $ valueMock ;
20
20
21
+ /**
22
+ * @var \PHPUnit_Framework_MockObject_MockObject
23
+ */
24
+ protected $ localeFormatMock ;
25
+
21
26
/**
22
27
* @inheritdoc
23
28
*/
@@ -26,6 +31,8 @@ protected function setUp()
26
31
$ configMock = $ this ->createMock (\Magento \Catalog \Model \ProductOptions \ConfigInterface::class);
27
32
$ storeManagerMock = $ this ->createMock (\Magento \Store \Model \StoreManagerInterface::class);
28
33
$ priceConfigMock = new \Magento \Catalog \Model \Config \Source \Product \Options \Price ($ storeManagerMock );
34
+ $ this ->localeFormatMock = $ this ->createMock (\Magento \Framework \Locale \FormatInterface::class);
35
+
29
36
$ config = [
30
37
[
31
38
'label ' => 'group label 1 ' ,
@@ -51,7 +58,8 @@ protected function setUp()
51
58
$ configMock ->expects ($ this ->once ())->method ('getAll ' )->will ($ this ->returnValue ($ config ));
52
59
$ this ->validator = new \Magento \Catalog \Model \Product \Option \Validator \DefaultValidator (
53
60
$ configMock ,
54
- $ priceConfigMock
61
+ $ priceConfigMock ,
62
+ $ this ->localeFormatMock
55
63
);
56
64
}
57
65
@@ -63,10 +71,10 @@ public function isValidTitleDataProvider()
63
71
{
64
72
$ mess = ['option required fields ' => 'Missed values for option required fields ' ];
65
73
return [
66
- ['option_title ' , 'name 1.1 ' , 'fixed ' , new \Magento \Framework \DataObject (['store_id ' => 1 ]), [], true ],
67
- ['option_title ' , 'name 1.1 ' , 'fixed ' , new \Magento \Framework \DataObject (['store_id ' => 0 ]), [], true ],
68
- [null , 'name 1.1 ' , 'fixed ' , new \Magento \Framework \DataObject (['store_id ' => 1 ]), [], true ],
69
- [null , 'name 1.1 ' , 'fixed ' , new \Magento \Framework \DataObject (['store_id ' => 0 ]), $ mess , false ],
74
+ ['option_title ' , 'name 1.1 ' , 'fixed ' , 10 , new \Magento \Framework \DataObject (['store_id ' => 1 ]), [], true ],
75
+ ['option_title ' , 'name 1.1 ' , 'fixed ' , 10 , new \Magento \Framework \DataObject (['store_id ' => 0 ]), [], true ],
76
+ [null , 'name 1.1 ' , 'fixed ' , 10 , new \Magento \Framework \DataObject (['store_id ' => 1 ]), [], true ],
77
+ [null , 'name 1.1 ' , 'fixed ' , 10 , new \Magento \Framework \DataObject (['store_id ' => 0 ]), $ mess , false ],
70
78
];
71
79
}
72
80
@@ -79,15 +87,18 @@ public function isValidTitleDataProvider()
79
87
* @param bool $result
80
88
* @dataProvider isValidTitleDataProvider
81
89
*/
82
- public function testIsValidTitle ($ title , $ type , $ priceType , $ product , $ messages , $ result )
90
+ public function testIsValidTitle ($ title , $ type , $ priceType , $ price , $ product , $ messages , $ result )
83
91
{
84
- $ methods = ['getTitle ' , 'getType ' , 'getPriceType ' , '__wakeup ' , 'getProduct ' ];
92
+ $ methods = ['getTitle ' , 'getType ' , 'getPriceType ' , 'getPrice ' , ' __wakeup ' , 'getProduct ' ];
85
93
$ valueMock = $ this ->createPartialMock (\Magento \Catalog \Model \Product \Option::class, $ methods );
86
94
$ valueMock ->expects ($ this ->once ())->method ('getTitle ' )->will ($ this ->returnValue ($ title ));
87
95
$ valueMock ->expects ($ this ->any ())->method ('getType ' )->will ($ this ->returnValue ($ type ));
88
96
$ valueMock ->expects ($ this ->once ())->method ('getPriceType ' )->will ($ this ->returnValue ($ priceType ));
89
- // $valueMock->expects($this->once())->method('getPrice')->will($this->returnValue($price));
97
+ $ valueMock ->expects ($ this ->once ())->method ('getPrice ' )->will ($ this ->returnValue ($ price ));
90
98
$ valueMock ->expects ($ this ->once ())->method ('getProduct ' )->will ($ this ->returnValue ($ product ));
99
+
100
+ $ this ->localeFormatMock ->expects ($ this ->once ())->method ('getNumber ' )->will ($ this ->returnValue ($ price ));
101
+
91
102
$ this ->assertEquals ($ result , $ this ->validator ->isValid ($ valueMock ));
92
103
$ this ->assertEquals ($ messages , $ this ->validator ->getMessages ());
93
104
}
@@ -126,4 +137,43 @@ public function testIsValidFail($product)
126
137
$ this ->assertFalse ($ this ->validator ->isValid ($ valueMock ));
127
138
$ this ->assertEquals ($ messages , $ this ->validator ->getMessages ());
128
139
}
140
+
141
+ /**
142
+ * Data provider for testValidationNegativePrice
143
+ * @return array
144
+ */
145
+ public function validationPriceDataProvider ()
146
+ {
147
+ return [
148
+ ['option_title ' , 'name 1.1 ' , 'fixed ' , -12 , new \Magento \Framework \DataObject (['store_id ' => 1 ])],
149
+ ['option_title ' , 'name 1.1 ' , 'fixed ' , -12 , new \Magento \Framework \DataObject (['store_id ' => 0 ])],
150
+ ['option_title ' , 'name 1.1 ' , 'fixed ' , 12 , new \Magento \Framework \DataObject (['store_id ' => 1 ])],
151
+ ['option_title ' , 'name 1.1 ' , 'fixed ' , 12 , new \Magento \Framework \DataObject (['store_id ' => 0 ])]
152
+ ];
153
+ }
154
+
155
+ /**
156
+ * @param $title
157
+ * @param $type
158
+ * @param $priceType
159
+ * @param $price
160
+ * @param $product
161
+ * @dataProvider validationPriceDataProvider
162
+ */
163
+ public function testValidationPrice ($ title , $ type , $ priceType , $ price , $ product )
164
+ {
165
+ $ methods = ['getTitle ' , 'getType ' , 'getPriceType ' , 'getPrice ' , '__wakeup ' , 'getProduct ' ];
166
+ $ valueMock = $ this ->createPartialMock (\Magento \Catalog \Model \Product \Option::class, $ methods );
167
+ $ valueMock ->expects ($ this ->once ())->method ('getTitle ' )->will ($ this ->returnValue ($ title ));
168
+ $ valueMock ->expects ($ this ->exactly (2 ))->method ('getType ' )->will ($ this ->returnValue ($ type ));
169
+ $ valueMock ->expects ($ this ->once ())->method ('getPriceType ' )->will ($ this ->returnValue ($ priceType ));
170
+ $ valueMock ->expects ($ this ->once ())->method ('getPrice ' )->will ($ this ->returnValue ($ price ));
171
+ $ valueMock ->expects ($ this ->once ())->method ('getProduct ' )->will ($ this ->returnValue ($ product ));
172
+
173
+ $ this ->localeFormatMock ->expects ($ this ->once ())->method ('getNumber ' )->will ($ this ->returnValue ($ price ));
174
+
175
+ $ messages = [];
176
+ $ this ->assertTrue ($ this ->validator ->isValid ($ valueMock ));
177
+ $ this ->assertEquals ($ messages , $ this ->validator ->getMessages ());
178
+ }
129
179
}
0 commit comments