@@ -66,63 +66,58 @@ class BundleSelectionPriceTest extends \PHPUnit_Framework_TestCase
66
66
*/
67
67
protected $ priceCurrencyMock ;
68
68
69
- /**
70
- * @var float
71
- */
72
- protected $ quantity ;
73
-
74
69
/**
75
70
* Test setUp
76
71
*/
77
72
protected function setUp ()
78
73
{
79
74
$ this ->productMock = $ this ->getMock (
80
- ' Magento\Catalog\Model\Product ' ,
75
+ \ Magento \Catalog \Model \Product::class ,
81
76
['__wakeup ' , 'getPriceInfo ' , 'getSelectionPriceType ' , 'getSelectionPriceValue ' ],
82
77
[],
83
78
'' ,
84
79
false
85
80
);
86
81
87
82
$ this ->bundleMock = $ this ->getMock (
88
- ' Magento\Catalog\Model\Product ' ,
83
+ \ Magento \Catalog \Model \Product::class ,
89
84
['__wakeup ' , 'getPriceType ' , 'getPriceInfo ' , 'setFinalPrice ' , 'getData ' ],
90
85
[],
91
86
'' ,
92
87
false
93
88
);
94
- $ this ->calculatorMock = $ this ->getMockBuilder (' Magento\Framework\Pricing\Adjustment\CalculatorInterface ' )
89
+ $ this ->calculatorMock = $ this ->getMockBuilder (\ Magento \Framework \Pricing \Adjustment \CalculatorInterface::class )
95
90
->getMockForAbstractClass ();
96
91
$ this ->eventManagerMock = $ this ->getMock (
97
- ' Magento\Framework\Event\Manager ' ,
92
+ \ Magento \Framework \Event \Manager::class ,
98
93
['dispatch ' ],
99
94
[],
100
95
'' ,
101
96
false
102
97
);
103
98
$ this ->priceInfoMock = $ this ->getMock (
104
- ' Magento\Framework\Pricing\PriceInfo\Base ' ,
99
+ \ Magento \Framework \Pricing \PriceInfo \Base::class ,
105
100
['getPrice ' ],
106
101
[],
107
102
'' ,
108
103
false
109
104
);
110
105
$ this ->discountCalculatorMock = $ this ->getMock (
111
- ' Magento\Bundle\Pricing\Price\DiscountCalculator ' ,
106
+ \ Magento \Bundle \Pricing \Price \DiscountCalculator::class ,
112
107
[],
113
108
[],
114
109
'' ,
115
110
false
116
111
);
117
112
$ this ->finalPriceMock = $ this ->getMock (
118
- ' Magento\Catalog\Pricing\Price\FinalPrice ' ,
113
+ \ Magento \Catalog \Pricing \Price \FinalPrice::class ,
119
114
[],
120
115
[],
121
116
'' ,
122
117
false
123
118
);
124
119
$ this ->regularPriceMock = $ this ->getMock (
125
- ' Magento\Catalog\Pricing\Price\RegularPrice ' ,
120
+ \ Magento \Catalog \Pricing \Price \RegularPrice::class ,
126
121
[],
127
122
[],
128
123
'' ,
@@ -132,18 +127,16 @@ protected function setUp()
132
127
->method ('getPriceInfo ' )
133
128
->will ($ this ->returnValue ($ this ->priceInfoMock ));
134
129
135
- $ this ->priceCurrencyMock = $ this ->getMock ('\Magento\Framework\Pricing\PriceCurrencyInterface ' );
136
-
137
- $ this ->quantity = 1 ;
130
+ $ this ->priceCurrencyMock = $ this ->getMock (\Magento \Framework \Pricing \PriceCurrencyInterface::class);
138
131
139
132
$ this ->setupSelectionPrice ();
140
133
}
141
134
142
- protected function setupSelectionPrice ($ useRegularPrice = false )
135
+ protected function setupSelectionPrice ($ useRegularPrice = false , $ qty = 1 )
143
136
{
144
137
$ this ->selectionPrice = new \Magento \Bundle \Pricing \Price \BundleSelectionPrice (
145
138
$ this ->productMock ,
146
- $ this -> quantity ,
139
+ $ qty ,
147
140
$ this ->calculatorMock ,
148
141
$ this ->priceCurrencyMock ,
149
142
$ this ->bundleMock ,
@@ -313,6 +306,58 @@ public function testGetValueTypeFixedWithoutSelectionPriceType($useRegularPrice)
313
306
$ this ->assertEquals ($ expectedPrice , $ this ->selectionPrice ->getValue ());
314
307
}
315
308
309
+ /**
310
+ * Test for method getValue with type Fixed and selectionPriceType is empty or zero.
311
+ *
312
+ * @param bool $useRegularPrice
313
+ * @return void
314
+ *
315
+ * @dataProvider useRegularPriceDataProvider
316
+ */
317
+ public function testFixedPriceWithMultipleQty ($ useRegularPrice )
318
+ {
319
+ $ qty = 2 ;
320
+
321
+ $ this ->setupSelectionPrice ($ useRegularPrice , $ qty );
322
+ $ regularPrice = 100.125 ;
323
+ $ discountedPrice = 70.453 ;
324
+ $ convertedValue = 100.247 ;
325
+ $ actualPrice = $ useRegularPrice ? $ convertedValue : $ discountedPrice ;
326
+ $ expectedPrice = $ useRegularPrice ? round ($ convertedValue , 2 ) : round ($ discountedPrice , 2 );
327
+
328
+ $ this ->bundleMock ->expects ($ this ->once ())
329
+ ->method ('getPriceType ' )
330
+ ->will ($ this ->returnValue (\Magento \Bundle \Model \Product \Price::PRICE_TYPE_FIXED ));
331
+ $ this ->productMock ->expects ($ this ->once ())
332
+ ->method ('getSelectionPriceType ' )
333
+ ->will ($ this ->returnValue (false ));
334
+ $ this ->productMock ->expects ($ this ->any ())
335
+ ->method ('getSelectionPriceValue ' )
336
+ ->will ($ this ->returnValue ($ regularPrice ));
337
+
338
+ $ this ->priceCurrencyMock ->expects ($ this ->once ())
339
+ ->method ('convert ' )
340
+ ->with ($ regularPrice )
341
+ ->will ($ this ->returnValue ($ convertedValue ));
342
+
343
+ if (!$ useRegularPrice ) {
344
+ $ this ->discountCalculatorMock ->expects ($ this ->once ())
345
+ ->method ('calculateDiscount ' )
346
+ ->with (
347
+ $ this ->equalTo ($ this ->bundleMock ),
348
+ $ this ->equalTo ($ convertedValue )
349
+ )
350
+ ->will ($ this ->returnValue ($ discountedPrice ));
351
+ }
352
+
353
+ $ this ->priceCurrencyMock ->expects ($ this ->once ())
354
+ ->method ('round ' )
355
+ ->with ($ actualPrice )
356
+ ->will ($ this ->returnValue ($ expectedPrice ));
357
+
358
+ $ this ->assertEquals ($ expectedPrice , $ this ->selectionPrice ->getValue ());
359
+ }
360
+
316
361
public function useRegularPriceDataProvider ()
317
362
{
318
363
return [
0 commit comments