@@ -18,6 +18,11 @@ class DefaultValidatorTest extends \PHPUnit\Framework\TestCase
1818 */
1919 protected $ valueMock ;
2020
21+ /**
22+ * @var \PHPUnit_Framework_MockObject_MockObject
23+ */
24+ protected $ localeFormatMock ;
25+
2126 /**
2227 * @inheritdoc
2328 */
@@ -26,6 +31,8 @@ protected function setUp()
2631 $ configMock = $ this ->createMock (\Magento \Catalog \Model \ProductOptions \ConfigInterface::class);
2732 $ storeManagerMock = $ this ->createMock (\Magento \Store \Model \StoreManagerInterface::class);
2833 $ priceConfigMock = new \Magento \Catalog \Model \Config \Source \Product \Options \Price ($ storeManagerMock );
34+ $ this ->localeFormatMock = $ this ->createMock (\Magento \Framework \Locale \FormatInterface::class);
35+
2936 $ config = [
3037 [
3138 'label ' => 'group label 1 ' ,
@@ -51,7 +58,8 @@ protected function setUp()
5158 $ configMock ->expects ($ this ->once ())->method ('getAll ' )->will ($ this ->returnValue ($ config ));
5259 $ this ->validator = new \Magento \Catalog \Model \Product \Option \Validator \DefaultValidator (
5360 $ configMock ,
54- $ priceConfigMock
61+ $ priceConfigMock ,
62+ $ this ->localeFormatMock
5563 );
5664 }
5765
@@ -63,10 +71,10 @@ public function isValidTitleDataProvider()
6371 {
6472 $ mess = ['option required fields ' => 'Missed values for option required fields ' ];
6573 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 ],
7078 ];
7179 }
7280
@@ -79,15 +87,18 @@ public function isValidTitleDataProvider()
7987 * @param bool $result
8088 * @dataProvider isValidTitleDataProvider
8189 */
82- public function testIsValidTitle ($ title , $ type , $ priceType , $ product , $ messages , $ result )
90+ public function testIsValidTitle ($ title , $ type , $ priceType , $ price , $ product , $ messages , $ result )
8391 {
84- $ methods = ['getTitle ' , 'getType ' , 'getPriceType ' , '__wakeup ' , 'getProduct ' ];
92+ $ methods = ['getTitle ' , 'getType ' , 'getPriceType ' , 'getPrice ' , ' __wakeup ' , 'getProduct ' ];
8593 $ valueMock = $ this ->createPartialMock (\Magento \Catalog \Model \Product \Option::class, $ methods );
8694 $ valueMock ->expects ($ this ->once ())->method ('getTitle ' )->will ($ this ->returnValue ($ title ));
8795 $ valueMock ->expects ($ this ->any ())->method ('getType ' )->will ($ this ->returnValue ($ type ));
8896 $ 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 ));
9098 $ valueMock ->expects ($ this ->once ())->method ('getProduct ' )->will ($ this ->returnValue ($ product ));
99+
100+ $ this ->localeFormatMock ->expects ($ this ->once ())->method ('getNumber ' )->will ($ this ->returnValue ($ price ));
101+
91102 $ this ->assertEquals ($ result , $ this ->validator ->isValid ($ valueMock ));
92103 $ this ->assertEquals ($ messages , $ this ->validator ->getMessages ());
93104 }
@@ -126,4 +137,43 @@ public function testIsValidFail($product)
126137 $ this ->assertFalse ($ this ->validator ->isValid ($ valueMock ));
127138 $ this ->assertEquals ($ messages , $ this ->validator ->getMessages ());
128139 }
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+ }
129179}
0 commit comments