@@ -266,12 +266,10 @@ public function testSave()
266
266
->with ('_cache_instance_used_product_attribute_ids ' )
267
267
->willReturn (true );
268
268
$ extensionAttributes = $ this ->getMockBuilder (ProductExtensionInterface::class)
269
- ->setMethods (
270
- [
271
- 'getConfigurableProductOptions ' ,
272
- 'getConfigurableProductLinks '
273
- ]
274
- )
269
+ ->setMethods ([
270
+ 'getConfigurableProductOptions ' ,
271
+ 'getConfigurableProductLinks '
272
+ ])
275
273
->getMockForAbstractClass ();
276
274
$ this ->entityMetadata ->expects ($ this ->any ())
277
275
->method ('getLinkField ' )
@@ -346,13 +344,25 @@ public function testCanUseAttribute()
346
344
347
345
public function testGetUsedProducts ()
348
346
{
349
- $ productCollectionItem = $ this ->createMock (\Magento \Catalog \Model \Product::class);
350
- $ attributeCollection = $ this ->createMock (Collection::class);
351
- $ product = $ this ->createMock (\Magento \Catalog \Model \Product::class);
352
- $ productCollection = $ this ->createMock (ProductCollection::class);
347
+ $ productCollectionItemData = ['array ' ];
353
348
349
+ $ productCollectionItem = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
350
+ ->disableOriginalConstructor ()
351
+ ->getMock ();
352
+ $ attributeCollection = $ this ->getMockBuilder (Collection::class)
353
+ ->disableOriginalConstructor ()
354
+ ->getMock ();
355
+ $ product = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
356
+ ->disableOriginalConstructor ()
357
+ ->getMock ();
358
+ $ productCollection = $ this ->getMockBuilder (ProductCollection::class)
359
+ ->disableOriginalConstructor ()
360
+ ->getMock ();
361
+
362
+ $ productCollectionItem ->expects ($ this ->once ())->method ('getData ' )->willReturn ($ productCollectionItemData );
354
363
$ attributeCollection ->expects ($ this ->any ())->method ('setProductFilter ' )->willReturnSelf ();
355
364
$ product ->expects ($ this ->atLeastOnce ())->method ('getStoreId ' )->willReturn (5 );
365
+ $ product ->expects ($ this ->once ())->method ('getIdentities ' )->willReturn (['123 ' ]);
356
366
357
367
$ product ->expects ($ this ->exactly (2 ))
358
368
->method ('hasData ' )
@@ -378,10 +388,59 @@ public function testGetUsedProducts()
378
388
$ productCollection ->expects ($ this ->once ())->method ('setStoreId ' )->with (5 )->willReturn ([]);
379
389
$ productCollection ->expects ($ this ->once ())->method ('getItems ' )->willReturn ([$ productCollectionItem ]);
380
390
391
+ $ this ->serializer ->expects ($ this ->once ())
392
+ ->method ('serialize ' )
393
+ ->with ([$ productCollectionItemData ])
394
+ ->willReturn ('result ' );
395
+
381
396
$ this ->productCollectionFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ productCollection );
382
397
$ this ->model ->getUsedProducts ($ product );
383
398
}
384
399
400
+ public function testGetUsedProductsWithDataInCache ()
401
+ {
402
+ $ product = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
403
+ ->disableOriginalConstructor ()
404
+ ->getMock ();
405
+ $ childProduct = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
406
+ ->disableOriginalConstructor ()
407
+ ->getMock ();
408
+
409
+ $ dataKey = '_cache_instance_products ' ;
410
+ $ usedProductsData = [['first ' ]];
411
+ $ usedProducts = [$ childProduct ];
412
+
413
+ $ product ->expects ($ this ->once ())
414
+ ->method ('hasData ' )
415
+ ->with ($ dataKey )
416
+ ->willReturn (false );
417
+ $ product ->expects ($ this ->once ())
418
+ ->method ('setData ' )
419
+ ->with ($ dataKey , $ usedProducts );
420
+ $ product ->expects ($ this ->any ())
421
+ ->method ('getData ' )
422
+ ->willReturnOnConsecutiveCalls (1 , $ usedProducts );
423
+
424
+ $ childProduct ->expects ($ this ->once ())
425
+ ->method ('setData ' )
426
+ ->with ($ usedProductsData [0 ]);
427
+
428
+ $ this ->productFactory ->expects ($ this ->once ())
429
+ ->method ('create ' )
430
+ ->willReturn ($ childProduct );
431
+
432
+ $ this ->cache ->expects ($ this ->once ())
433
+ ->method ('load ' )
434
+ ->willReturn ($ usedProductsData );
435
+
436
+ $ this ->serializer ->expects ($ this ->once ())
437
+ ->method ('unserialize ' )
438
+ ->with ($ usedProductsData )
439
+ ->willReturn ($ usedProductsData );
440
+
441
+ $ this ->assertEquals ($ usedProducts , $ this ->model ->getUsedProducts ($ product ));
442
+ }
443
+
385
444
/**
386
445
* @param int $productStore
387
446
*
@@ -819,12 +878,12 @@ public function testSetImageFromChildProduct()
819
878
->method ('getLinkField ' )
820
879
->willReturn ('link ' );
821
880
$ productMock ->expects ($ this ->any ())->method ('hasData ' )
822
- ->withConsecutive (['_cache_instance_products ' ])
823
- ->willReturnOnConsecutiveCalls (true );
881
+ ->withConsecutive (['store_id ' ], [ ' _cache_instance_products ' ])
882
+ ->willReturnOnConsecutiveCalls (true , true );
824
883
825
884
$ productMock ->expects ($ this ->any ())->method ('getData ' )
826
- ->withConsecutive (['image ' ], ['image ' ], ['_cache_instance_products ' ])
827
- ->willReturnOnConsecutiveCalls ('no_selection ' , 'no_selection ' , [$ childProductMock ]);
885
+ ->withConsecutive (['image ' ], ['image ' ], ['link ' ], [ ' store_id ' ], [ ' _cache_instance_products ' ])
886
+ ->willReturnOnConsecutiveCalls ('no_selection ' , 'no_selection ' , 1 , 1 , [$ childProductMock ]);
828
887
829
888
$ childProductMock ->expects ($ this ->any ())->method ('getData ' )->with ('image ' )->willReturn ('image_data ' );
830
889
$ productMock ->expects ($ this ->once ())->method ('setImage ' )->with ('image_data ' )->willReturnSelf ();
0 commit comments