@@ -19,6 +19,32 @@ class ValueTest extends \PHPUnit\Framework\TestCase
19
19
*/
20
20
private $ model ;
21
21
22
+ /**
23
+ * @var \Magento\Catalog\Pricing\Price\CustomOptionPriceCalculator
24
+ */
25
+ private $ customOptionPriceCalculatorMock ;
26
+
27
+ protected function setUp ()
28
+ {
29
+ $ mockedResource = $ this ->getMockedResource ();
30
+ $ mockedCollectionFactory = $ this ->getMockedValueCollectionFactory ();
31
+
32
+ $ this ->customOptionPriceCalculatorMock = $ this ->createMock (
33
+ \Magento \Catalog \Pricing \Price \CustomOptionPriceCalculator::class
34
+ );
35
+
36
+ $ helper = new ObjectManager ($ this );
37
+ $ this ->model = $ helper ->getObject (
38
+ \Magento \Catalog \Model \Product \Option \Value::class,
39
+ [
40
+ 'resource ' => $ mockedResource ,
41
+ 'valueCollectionFactory ' => $ mockedCollectionFactory ,
42
+ 'customOptionPriceCalculator ' => $ this ->customOptionPriceCalculatorMock ,
43
+ ]
44
+ );
45
+ $ this ->model ->setOption ($ this ->getMockedOption ());
46
+ }
47
+
22
48
public function testSaveProduct ()
23
49
{
24
50
$ this ->model ->setValues ([100 ])
@@ -35,11 +61,16 @@ public function testSaveProduct()
35
61
36
62
public function testGetPrice ()
37
63
{
38
- $ this ->model ->setPrice (1000 );
64
+ $ price = 1000 ;
65
+ $ this ->model ->setPrice ($ price );
39
66
$ this ->model ->setPriceType (Value::TYPE_PERCENT );
40
- $ this ->assertEquals (1000 , $ this ->model ->getPrice (false ));
67
+ $ this ->assertEquals ($ price , $ this ->model ->getPrice (false ));
41
68
42
- $ this ->assertEquals (100 , $ this ->model ->getPrice (true ));
69
+ $ percentPice = 100 ;
70
+ $ this ->customOptionPriceCalculatorMock ->expects ($ this ->atLeastOnce ())
71
+ ->method ('getOptionPriceByPriceCode ' )
72
+ ->willReturn ($ percentPice );
73
+ $ this ->assertEquals ($ percentPice , $ this ->model ->getPrice (true ));
43
74
}
44
75
45
76
public function testGetValuesCollection ()
@@ -78,23 +109,6 @@ public function testDeleteValue()
78
109
$ this ->assertInstanceOf (\Magento \Catalog \Model \Product \Option \Value::class, $ this ->model ->deleteValue (1 ));
79
110
}
80
111
81
- protected function setUp ()
82
- {
83
- $ mockedResource = $ this ->getMockedResource ();
84
- $ mockedCollectionFactory = $ this ->getMockedValueCollectionFactory ();
85
- $ mockedContext = $ this ->getMockedContext ();
86
- $ helper = new ObjectManager ($ this );
87
- $ this ->model = $ helper ->getObject (
88
- \Magento \Catalog \Model \Product \Option \Value::class,
89
- [
90
- 'resource ' => $ mockedResource ,
91
- 'valueCollectionFactory ' => $ mockedCollectionFactory ,
92
- 'context ' => $ mockedContext
93
- ]
94
- );
95
- $ this ->model ->setOption ($ this ->getMockedOption ());
96
- }
97
-
98
112
/**
99
113
* @return \Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory
100
114
*/
@@ -243,61 +257,4 @@ private function getMockedResource()
243
257
244
258
return $ mock ;
245
259
}
246
-
247
- /**
248
- * @return \Magento\Framework\Model\Context
249
- */
250
- private function getMockedContext ()
251
- {
252
- $ mockedRemoveAction = $ this ->getMockedRemoveAction ();
253
- $ mockEventManager = $ this ->getMockedEventManager ();
254
-
255
- $ mockBuilder = $ this ->getMockBuilder (\Magento \Framework \Model \Context::class)
256
- ->setMethods (['getActionValidator ' , 'getEventDispatcher ' ])
257
- ->disableOriginalConstructor ();
258
- $ mock = $ mockBuilder ->getMock ();
259
-
260
- $ mock ->expects ($ this ->any ())
261
- ->method ('getActionValidator ' )
262
- ->will ($ this ->returnValue ($ mockedRemoveAction ));
263
-
264
- $ mock ->expects ($ this ->any ())
265
- ->method ('getEventDispatcher ' )
266
- ->will ($ this ->returnValue ($ mockEventManager ));
267
-
268
- return $ mock ;
269
- }
270
-
271
- /**
272
- * @return RemoveAction
273
- */
274
- private function getMockedRemoveAction ()
275
- {
276
- $ mockBuilder = $ this ->getMockBuilder (\Magento \Framework \Model \Context::class)
277
- ->setMethods (['isAllowed ' ])
278
- ->disableOriginalConstructor ();
279
- $ mock = $ mockBuilder ->getMock ();
280
-
281
- $ mock ->expects ($ this ->any ())
282
- ->method ('isAllowed ' )
283
- ->will ($ this ->returnValue (true ));
284
-
285
- return $ mock ;
286
- }
287
-
288
- /**
289
- * @return \Magento\Framework\Event\ManagerInterface
290
- */
291
- private function getMockedEventManager ()
292
- {
293
- $ mockBuilder = $ this ->getMockBuilder (\Magento \Framework \Event \ManagerInterface::class)
294
- ->setMethods (['dispatch ' ])
295
- ->disableOriginalConstructor ();
296
- $ mock = $ mockBuilder ->getMockForAbstractClass ();
297
-
298
- $ mock ->expects ($ this ->any ())
299
- ->method ('dispatch ' );
300
-
301
- return $ mock ;
302
- }
303
260
}
0 commit comments