@@ -300,20 +300,82 @@ public function testGetChildrenMsrpWhenNoChildrenWithMsrp()
300
300
301
301
public function testPrepareForCartAdvancedEmpty ()
302
302
{
303
+ $ this ->product = $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false );
303
304
$ buyRequest = new \Magento \Framework \Object ();
304
305
$ expectedMsg = "Please specify the quantity of product(s). " ;
305
306
306
- $ this ->assertEquals (
307
- $ expectedMsg ,
308
- $ this ->_model ->prepareForCartAdvanced ($ buyRequest , $ this ->product )
307
+ $ productCollection = $ this ->getMock (
308
+ 'Magento\Catalog\Model\Resource\Product\Link\Product\Collection ' ,
309
+ [],
310
+ [],
311
+ '' ,
312
+ false
309
313
);
314
+ $ productCollection
315
+ ->expects ($ this ->atLeastOnce ())
316
+ ->method ('setFlag ' )
317
+ ->willReturnSelf ();
318
+ $ productCollection
319
+ ->expects ($ this ->atLeastOnce ())
320
+ ->method ('setIsStrongMode ' )
321
+ ->willReturnSelf ();
322
+ $ productCollection
323
+ ->expects ($ this ->atLeastOnce ())
324
+ ->method ('setProduct ' );
325
+ $ productCollection
326
+ ->expects ($ this ->atLeastOnce ())
327
+ ->method ('addAttributeToSelect ' )
328
+ ->willReturnSelf ();
329
+ $ productCollection
330
+ ->expects ($ this ->atLeastOnce ())
331
+ ->method ('addFilterByRequiredOptions ' )
332
+ ->willReturnSelf ();
333
+ $ productCollection
334
+ ->expects ($ this ->atLeastOnce ())
335
+ ->method ('setPositionOrder ' )
336
+ ->willReturnSelf ();
337
+ $ productCollection
338
+ ->expects ($ this ->atLeastOnce ())
339
+ ->method ('addStoreFilter ' )
340
+ ->willReturnSelf ();
341
+ $ productCollection
342
+ ->expects ($ this ->atLeastOnce ())
343
+ ->method ('addAttributeToFilter ' )
344
+ ->willReturnSelf ();
345
+ $ items = [
346
+ $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false ),
347
+ $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false )
348
+ ];
349
+ $ productCollection
350
+ ->expects ($ this ->atLeastOnce ())
351
+ ->method ('getIterator ' )
352
+ ->willReturn (new \ArrayIterator ($ items ));
353
+
354
+ $ link = $ this ->getMock ('Magento\Catalog\Model\Product\Link ' , [], [], '' , false );
355
+ $ link
356
+ ->expects ($ this ->any ())
357
+ ->method ('setLinkTypeId ' );
358
+ $ link
359
+ ->expects ($ this ->atLeastOnce ())
360
+ ->method ('getProductCollection ' )
361
+ ->willReturn ($ productCollection );
362
+
363
+ $ this ->product
364
+ ->expects ($ this ->atLeastOnce ())
365
+ ->method ('getLinkInstance ' )
366
+ ->willReturn ($ link );
367
+
368
+ $ this ->product
369
+ ->expects ($ this ->any ())
370
+ ->method ('getData ' )
371
+ ->willReturn ($ items );
310
372
311
- $ buyRequest ->setSuperGroup ([]);
312
373
$ this ->assertEquals (
313
374
$ expectedMsg ,
314
375
$ this ->_model ->prepareForCartAdvanced ($ buyRequest , $ this ->product )
315
376
);
316
377
378
+
317
379
$ buyRequest ->setSuperGroup (1 );
318
380
$ this ->assertEquals (
319
381
$ expectedMsg ,
@@ -329,8 +391,8 @@ public function testPrepareForCartAdvancedNoProductsStrictTrue()
329
391
330
392
$ cached = true ;
331
393
$ associatedProducts = [];
332
- $ this ->product ->expects ($ this ->once ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
333
- $ this ->product ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ($ associatedProducts ));
394
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
395
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('getData ' )->will ($ this ->returnValue ($ associatedProducts ));
334
396
335
397
$ this ->assertEquals (
336
398
$ expectedMsg ,
@@ -345,8 +407,8 @@ public function testPrepareForCartAdvancedNoProductsStrictFalse()
345
407
346
408
$ cached = true ;
347
409
$ associatedProducts = [];
348
- $ this ->product ->expects ($ this ->once ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
349
- $ this ->product ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ($ associatedProducts ));
410
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
411
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('getData ' )->will ($ this ->returnValue ($ associatedProducts ));
350
412
351
413
$ this ->assertEquals (
352
414
[0 => $ this ->product ],
@@ -358,7 +420,7 @@ public function testPrepareForCartAdvancedWithProductsStrictFalseStringResult()
358
420
{
359
421
$ associatedProduct = $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false );
360
422
$ associatedId = 9384 ;
361
- $ associatedProduct ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
423
+ $ associatedProduct ->expects ($ this ->atLeastOnce ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
362
424
363
425
$ typeMock = $ this ->getMock (
364
426
'Magento\Catalog\Model\Product\Type\AbstractType ' ,
@@ -376,8 +438,8 @@ public function testPrepareForCartAdvancedWithProductsStrictFalseStringResult()
376
438
$ buyRequest ->setSuperGroup ([$ associatedId => 1 ]);
377
439
378
440
$ cached = true ;
379
- $ this ->product ->expects ($ this ->once ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
380
- $ this ->product ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
441
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
442
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
381
443
382
444
$ this ->assertEquals (
383
445
$ associatedPrepareResult ,
@@ -387,10 +449,10 @@ public function testPrepareForCartAdvancedWithProductsStrictFalseStringResult()
387
449
388
450
public function testPrepareForCartAdvancedWithProductsStrictFalseEmptyArrayResult ()
389
451
{
390
- $ expectedMsg = "We cannot process the item. " ;
452
+ $ expectedMsg = "Cannot process the item. " ;
391
453
$ associatedProduct = $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false );
392
454
$ associatedId = 9384 ;
393
- $ associatedProduct ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
455
+ $ associatedProduct ->expects ($ this ->atLeastOnce ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
394
456
395
457
$ typeMock = $ this ->getMock (
396
458
'Magento\Catalog\Model\Product\Type\AbstractType ' ,
@@ -408,8 +470,8 @@ public function testPrepareForCartAdvancedWithProductsStrictFalseEmptyArrayResul
408
470
$ buyRequest ->setSuperGroup ([$ associatedId => 1 ]);
409
471
410
472
$ cached = true ;
411
- $ this ->product ->expects ($ this ->once ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
412
- $ this ->product ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
473
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
474
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
413
475
414
476
$ this ->assertEquals (
415
477
$ expectedMsg ,
@@ -421,7 +483,7 @@ public function testPrepareForCartAdvancedWithProductsStrictFalse()
421
483
{
422
484
$ associatedProduct = $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false );
423
485
$ associatedId = 9384 ;
424
- $ associatedProduct ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
486
+ $ associatedProduct ->expects ($ this ->atLeastOnce ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
425
487
426
488
$ typeMock = $ this ->getMock (
427
489
'Magento\Catalog\Model\Product\Type\AbstractType ' ,
@@ -439,8 +501,8 @@ public function testPrepareForCartAdvancedWithProductsStrictFalse()
439
501
$ buyRequest ->setSuperGroup ([$ associatedId => 1 ]);
440
502
441
503
$ cached = true ;
442
- $ this ->product ->expects ($ this ->once ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
443
- $ this ->product ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
504
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
505
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
444
506
445
507
$ this ->assertEquals (
446
508
[$ this ->product ],
@@ -452,7 +514,7 @@ public function testPrepareForCartAdvancedWithProductsStrictTrue()
452
514
{
453
515
$ associatedProduct = $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false );
454
516
$ associatedId = 9384 ;
455
- $ associatedProduct ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
517
+ $ associatedProduct ->expects ($ this ->atLeastOnce ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
456
518
457
519
$ typeMock = $ this ->getMock (
458
520
'Magento\Catalog\Model\Product\Type\AbstractType ' ,
@@ -470,8 +532,8 @@ public function testPrepareForCartAdvancedWithProductsStrictTrue()
470
532
$ buyRequest ->setSuperGroup ([$ associatedId => 1 ]);
471
533
472
534
$ cached = true ;
473
- $ this ->product ->expects ($ this ->once ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
474
- $ this ->product ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
535
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('hasData ' )->will ($ this ->returnValue ($ cached ));
536
+ $ this ->product ->expects ($ this ->atLeastOnce ())->method ('getData ' )->will ($ this ->returnValue ([$ associatedProduct ]));
475
537
476
538
$ this ->assertEquals (
477
539
$ associatedPrepareResult ,
0 commit comments