Skip to content

Commit 36c80c8

Browse files
committed
MC-19672: Simple product disappearing in the configurable grid after qty set to 0
1 parent 70f04c0 commit 36c80c8

File tree

1 file changed

+73
-14
lines changed

1 file changed

+73
-14
lines changed

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,10 @@ public function testSave()
266266
->with('_cache_instance_used_product_attribute_ids')
267267
->willReturn(true);
268268
$extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)
269-
->setMethods(
270-
[
271-
'getConfigurableProductOptions',
272-
'getConfigurableProductLinks'
273-
]
274-
)
269+
->setMethods([
270+
'getConfigurableProductOptions',
271+
'getConfigurableProductLinks'
272+
])
275273
->getMockForAbstractClass();
276274
$this->entityMetadata->expects($this->any())
277275
->method('getLinkField')
@@ -346,13 +344,25 @@ public function testCanUseAttribute()
346344

347345
public function testGetUsedProducts()
348346
{
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'];
353348

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);
354363
$attributeCollection->expects($this->any())->method('setProductFilter')->willReturnSelf();
355364
$product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(5);
365+
$product->expects($this->once())->method('getIdentities')->willReturn(['123']);
356366

357367
$product->expects($this->exactly(2))
358368
->method('hasData')
@@ -378,10 +388,59 @@ public function testGetUsedProducts()
378388
$productCollection->expects($this->once())->method('setStoreId')->with(5)->willReturn([]);
379389
$productCollection->expects($this->once())->method('getItems')->willReturn([$productCollectionItem]);
380390

391+
$this->serializer->expects($this->once())
392+
->method('serialize')
393+
->with([$productCollectionItemData])
394+
->willReturn('result');
395+
381396
$this->productCollectionFactory->expects($this->any())->method('create')->willReturn($productCollection);
382397
$this->model->getUsedProducts($product);
383398
}
384399

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+
385444
/**
386445
* @param int $productStore
387446
*
@@ -819,12 +878,12 @@ public function testSetImageFromChildProduct()
819878
->method('getLinkField')
820879
->willReturn('link');
821880
$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);
824883

825884
$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]);
828887

829888
$childProductMock->expects($this->any())->method('getData')->with('image')->willReturn('image_data');
830889
$productMock->expects($this->once())->method('setImage')->with('image_data')->willReturnSelf();

0 commit comments

Comments
 (0)