@@ -68,15 +68,18 @@ function ($value) {
68
68
}
69
69
)
70
70
);
71
- $ this ->productPriceProvider = $ this ->getMockBuilder ('Oro\Bundle\PricingBundle\Provider\ProductPriceProvider ' )
71
+
72
+ $ this ->productPriceProvider = $ this
73
+ ->getMockBuilder ('Oro\Bundle\PricingBundle\Provider\ProductPriceProvider ' )
72
74
->disableOriginalConstructor ()
73
75
->getMock ();
74
76
75
77
$ this ->doctrineHelper = $ this ->getMockBuilder ('Oro\Bundle\EntityBundle\ORM\DoctrineHelper ' )
76
78
->disableOriginalConstructor ()
77
79
->getMock ();
78
80
79
- $ this ->priceListTreeHandler = $ this ->getMockBuilder ('Oro\Bundle\PricingBundle\Model\PriceListTreeHandler ' )
81
+ $ this ->priceListTreeHandler = $ this
82
+ ->getMockBuilder ('Oro\Bundle\PricingBundle\Model\PriceListTreeHandler ' )
80
83
->disableOriginalConstructor ()
81
84
->getMock ();
82
85
@@ -95,27 +98,42 @@ protected function tearDown()
95
98
unset($ this ->translator , $ this ->provider );
96
99
}
97
100
98
- public function testGetSubtotal ()
99
- {
100
- $ value = 142.0 ;
101
+ /**
102
+ * @dataProvider getPriceDataProvider
103
+ * @param float $value
104
+ * @param string $identifier
105
+ * @param float $defaultQuantity
106
+ * @param float $quantity
107
+ * @param float $expectedValue
108
+ * @param int $precision
109
+ * @param string $code
110
+ */
111
+ public function testGetSubtotal (
112
+ $ value ,
113
+ $ identifier ,
114
+ $ defaultQuantity ,
115
+ $ quantity ,
116
+ $ expectedValue ,
117
+ $ precision ,
118
+ $ code
119
+ ) {
101
120
$ currency = 'USD ' ;
102
- $ identifier = '1-code-2-USD ' ;
103
121
104
122
$ this ->translator ->expects ($ this ->once ())
105
123
->method ('trans ' )
106
124
->with (LineItemNotPricedSubtotalProvider::NAME . '.label ' )
107
125
->willReturn ('test ' );
108
126
109
127
$ product = $ this ->prepareProduct ();
110
- $ productUnit = $ this ->prepareProductUnit ();
128
+ $ productUnit = $ this ->prepareProductUnit ($ code , $ precision );
111
129
$ this ->prepareEntityManager ($ product , $ productUnit );
112
- $ this ->preparePrice ($ value , $ identifier );
130
+ $ this ->preparePrice ($ value , $ identifier, $ defaultQuantity );
113
131
114
132
$ entity = new EntityNotPricedStub ();
115
133
$ lineItem = new LineItemNotPricedStub ();
116
134
$ lineItem ->setProduct ($ product );
117
135
$ lineItem ->setProductUnit ($ productUnit );
118
- $ lineItem ->setQuantity (2 );
136
+ $ lineItem ->setQuantity ($ quantity );
119
137
120
138
$ entity ->addLineItem ($ lineItem );
121
139
@@ -135,7 +153,7 @@ public function testGetSubtotal()
135
153
$ this ->assertEquals ('test ' , $ subtotal ->getLabel ());
136
154
$ this ->assertEquals ($ entity ->getCurrency (), $ subtotal ->getCurrency ());
137
155
$ this ->assertInternalType ('float ' , $ subtotal ->getAmount ());
138
- $ this ->assertEquals ($ value * 2 , $ subtotal ->getAmount ());
156
+ $ this ->assertEquals ($ expectedValue , ( float ) $ subtotal ->getAmount ());
139
157
$ this ->assertTrue ($ subtotal ->isVisible ());
140
158
}
141
159
@@ -178,15 +196,18 @@ public function testIsNotSupported()
178
196
/**
179
197
* @return ProductUnit|\PHPUnit_Framework_MockObject_MockObject
180
198
*/
181
- protected function prepareProductUnit ()
199
+ protected function prepareProductUnit ($ code , $ precision )
182
200
{
183
201
/** @var ProductUnit|\PHPUnit_Framework_MockObject_MockObject $productUnit */
184
202
$ productUnit = $ this ->getMockBuilder ('Oro\Bundle\ProductBundle\Entity\ProductUnit ' )
185
203
->disableOriginalConstructor ()
186
204
->getMock ();
187
205
$ productUnit ->expects ($ this ->any ())
188
206
->method ('getCode ' )
189
- ->willReturn ('code ' );
207
+ ->willReturn ($ code );
208
+ $ productUnit ->expects ($ this ->any ())
209
+ ->method ('getDefaultPrecision ' )
210
+ ->willReturn ($ precision );
190
211
191
212
return $ productUnit ;
192
213
}
@@ -208,7 +229,7 @@ protected function prepareProduct()
208
229
}
209
230
210
231
/**
211
- * @param Product$product
232
+ * @param Product $product
212
233
* @param ProductUnit $productUnit
213
234
*/
214
235
protected function prepareEntityManager (Product $ product , ProductUnit $ productUnit )
@@ -229,20 +250,49 @@ protected function prepareEntityManager(Product $product, ProductUnit $productUn
229
250
}
230
251
231
252
/**
232
- * @param float $value
233
- * @param string $identifier
253
+ * @param $value
254
+ * @param $identifier
255
+ * @param $defaultQuantity
234
256
*/
235
- protected function preparePrice ($ value , $ identifier )
257
+ protected function preparePrice ($ value , $ identifier, $ defaultQuantity )
236
258
{
237
259
/** @var Price|\PHPUnit_Framework_MockObject_MockObject $price */
238
260
$ price = $ this ->getMockBuilder ('Oro\Bundle\CurrencyBundle\Entity\Price ' )
239
261
->disableOriginalConstructor ()
240
262
->getMock ();
241
263
$ price ->expects ($ this ->any ())
242
264
->method ('getValue ' )
243
- ->willReturn ($ value );
265
+ ->willReturn ($ value / $ defaultQuantity );
266
+
244
267
$ this ->productPriceProvider ->expects ($ this ->any ())
245
268
->method ('getMatchedPrices ' )
246
269
->willReturn ([$ identifier => $ price ]);
247
270
}
271
+
272
+ /**
273
+ * @return array
274
+ */
275
+ public function getPriceDataProvider ()
276
+ {
277
+ return [
278
+ 'kilogram ' => [
279
+ 'value ' => 25.0 ,
280
+ 'identifier ' => '1-kg-3-USD ' ,
281
+ 'defaultQuantity ' => 0.5 ,
282
+ 'quantity ' => 3 ,
283
+ 'expectedValue ' => 150 ,
284
+ 'precision ' => 3 ,
285
+ 'code ' => 'kg '
286
+ ],
287
+ 'item ' => [
288
+ 'value ' => 142.0 ,
289
+ 'identifier ' => '1-item-2-USD ' ,
290
+ 'defaultQuantity ' => 1 ,
291
+ 'quantity ' => 2 ,
292
+ 'expectedValue ' => 284 ,
293
+ 'precision ' => 0 ,
294
+ 'code ' => 'item '
295
+ ],
296
+ ];
297
+ }
248
298
}
0 commit comments