@@ -73,6 +73,11 @@ class ConfigurableTest extends \PHPUnit\Framework\TestCase
73
73
*/
74
74
private $ customerSession ;
75
75
76
+ /**
77
+ * @var \PHPUnit_Framework_MockObject_MockObject
78
+ */
79
+ private $ variationPricesMock ;
80
+
76
81
protected function setUp ()
77
82
{
78
83
$ this ->mockContextObject ();
@@ -136,6 +141,10 @@ protected function setUp()
136
141
->disableOriginalConstructor ()
137
142
->getMock ();
138
143
144
+ $ this ->variationPricesMock = $ this ->createMock (
145
+ \Magento \ConfigurableProduct \Model \Product \Type \Configurable \Variations \Prices::class
146
+ );
147
+
139
148
$ this ->block = new \Magento \ConfigurableProduct \Block \Product \View \Type \Configurable (
140
149
$ this ->context ,
141
150
$ this ->arrayUtils ,
@@ -147,7 +156,8 @@ protected function setUp()
147
156
$ this ->configurableAttributeData ,
148
157
[],
149
158
$ this ->localeFormat ,
150
- $ this ->customerSession
159
+ $ this ->customerSession ,
160
+ $ this ->variationPricesMock
151
161
);
152
162
}
153
163
@@ -249,12 +259,8 @@ public function testGetJsonConfig()
249
259
'getAmount ' ,
250
260
])
251
261
->getMockForAbstractClass ();
252
- $ priceMock ->expects ($ this ->any ())
253
- ->method ('getAmount ' )
254
- ->willReturn ($ amountMock );
255
-
262
+ $ priceMock ->expects ($ this ->any ())->method ('getAmount ' )->willReturn ($ amountMock );
256
263
$ tierPriceMock = $ this ->getTierPriceMock ($ amountMock , $ priceQty , $ percentage );
257
-
258
264
$ productMock = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
259
265
->disableOriginalConstructor ()
260
266
->getMock ();
@@ -272,27 +278,16 @@ public function testGetJsonConfig()
272
278
['tier_price ' , $ tierPriceMock ],
273
279
]);
274
280
275
- $ productMock ->expects ($ this ->any ())
276
- ->method ('getTypeInstance ' )
277
- ->willReturn ($ productTypeMock );
278
- $ productMock ->expects ($ this ->any ())
279
- ->method ('getPriceInfo ' )
280
- ->willReturn ($ priceInfoMock );
281
- $ productMock ->expects ($ this ->any ())
282
- ->method ('isSaleable ' )
283
- ->willReturn (true );
284
- $ productMock ->expects ($ this ->any ())
285
- ->method ('getId ' )
286
- ->willReturn ($ productId );
281
+ $ productMock ->expects ($ this ->any ())->method ('getTypeInstance ' )->willReturn ($ productTypeMock );
282
+ $ productMock ->expects ($ this ->any ())->method ('getPriceInfo ' )->willReturn ($ priceInfoMock );
283
+ $ productMock ->expects ($ this ->any ())->method ('isSaleable ' )->willReturn (true );
284
+ $ productMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ productId );
287
285
288
286
$ this ->helper ->expects ($ this ->any ())
289
287
->method ('getOptions ' )
290
288
->with ($ productMock , [$ productMock ])
291
289
->willReturn ([]);
292
-
293
- $ this ->product ->expects ($ this ->any ())
294
- ->method ('getSkipSaleableCheck ' )
295
- ->willReturn (true );
290
+ $ this ->product ->expects ($ this ->any ())->method ('getSkipSaleableCheck ' )->willReturn (true );
296
291
297
292
$ attributesData = [
298
293
'attributes ' => [],
@@ -304,9 +299,7 @@ public function testGetJsonConfig()
304
299
->with ($ productMock , [])
305
300
->willReturn ($ attributesData );
306
301
307
- $ this ->localeFormat ->expects ($ this ->any ())
308
- ->method ('getPriceFormat ' )
309
- ->willReturn ([]);
302
+ $ this ->localeFormat ->expects ($ this ->atLeastOnce ())->method ('getPriceFormat ' )->willReturn ([]);
310
303
$ this ->localeFormat ->expects ($ this ->any ())
311
304
->method ('getNumber ' )
312
305
->willReturnMap ([
@@ -315,16 +308,29 @@ public function testGetJsonConfig()
315
308
[$ percentage , $ percentage ],
316
309
]);
317
310
311
+ $ this ->variationPricesMock ->expects ($ this ->once ())
312
+ ->method ('getFormattedPrices ' )
313
+ ->with ($ priceInfoMock )
314
+ ->willReturn (
315
+ [
316
+ 'oldPrice ' => [
317
+ 'amount ' => $ amount ,
318
+ ],
319
+ 'basePrice ' => [
320
+ 'amount ' => $ amount ,
321
+ ],
322
+ 'finalPrice ' => [
323
+ 'amount ' => $ amount ,
324
+ ],
325
+ ]
326
+ );
327
+
318
328
$ expectedArray = $ this ->getExpectedArray ($ productId , $ amount , $ priceQty , $ percentage );
319
329
$ expectedJson = json_encode ($ expectedArray );
320
330
321
- $ this ->jsonEncoder ->expects ($ this ->once ())
322
- ->method ('encode ' )
323
- ->with ($ expectedArray )
324
- ->willReturn ($ expectedJson );
331
+ $ this ->jsonEncoder ->expects ($ this ->once ())->method ('encode ' )->with ($ expectedArray )->willReturn ($ expectedJson );
325
332
326
333
$ this ->block ->setData ('product ' , $ productMock );
327
-
328
334
$ result = $ this ->block ->getJsonConfig ();
329
335
$ this ->assertEquals ($ expectedJson , $ result );
330
336
}
0 commit comments