35 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36 $this->registryMock = $this->createMock(\
Magento\Framework\Registry::class);
37 $this->stockRegistryMock = $this->getMockBuilder(\
Magento\CatalogInventory\Api\StockRegistryInterface::class)
38 ->disableOriginalConstructor()
40 $this->scopeConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\Config\ScopeConfigInterface::class)
41 ->disableOriginalConstructor()
44 \
Magento\CatalogInventory\Block\Stockqty\DefaultStockqty::class,
46 'registry' => $this->registryMock,
47 'stockRegistry' => $this->stockRegistryMock,
48 'scopeConfig' => $this->scopeConfigMock
60 $productTags = [
'catalog_product_1'];
62 $product->expects($this->once())->method(
'getIdentities')->will($this->returnValue($productTags));
63 $this->registryMock->expects($this->once())
65 ->with(
'current_product')
66 ->will($this->returnValue(
$product));
67 $this->assertEquals($productTags, $this->block->getIdentities());
80 $this->assertNull($this->block->getData(
'product_stock_qty'));
85 \
Magento\Catalog\Model\Product::class,
86 [
'getId',
'getStore',
'__wakeup']
88 $product->expects($this->any())->method(
'getId')->will($this->returnValue(
$productId));
89 $store = $this->createPartialMock(\
Magento\Store\Model\Store::class, [
'getWebsiteId',
'__wakeup']);
90 $store->expects($this->any())->method(
'getWebsiteId')->willReturn(
$websiteId);
91 $product->expects($this->any())->method(
'getStore')->will($this->returnValue(
$store));
93 $this->registryMock->expects($this->any())
95 ->with(
'current_product')
96 ->will($this->returnValue(
$product));
99 $stockStatus = $this->getMockBuilder(\
Magento\CatalogInventory\Api\Data\StockStatusInterface::class)
100 ->getMockForAbstractClass();
101 $stockStatus->expects($this->any())->method(
'getQty')->willReturn($productStockQty);
102 $this->stockRegistryMock->expects($this->once())
103 ->method(
'getStockStatus')
105 ->will($this->returnValue($stockStatus));
108 $this->assertSame($expectedQty, $this->block->getStockQty());
109 $this->assertSame($expectedQty, $this->block->getData(
'product_stock_qty'));
119 $storeMock = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
120 ->disableOriginalConstructor()
122 $storeMock->expects($this->once())
123 ->method(
'getWebsiteId')
131 ->willReturn($storeMock);
132 $this->registryMock->expects($this->once())
134 ->with(
'current_product')
135 ->will($this->returnValue(
$product));
137 $stockItemMock = $this->getMockBuilder(\
Magento\CatalogInventory\Api\Data\StockItemInterface::class)
138 ->disableOriginalConstructor()
140 $stockItemMock->expects($this->once())
141 ->method(
'getMinQty')
142 ->willReturn($minQty);
143 $this->stockRegistryMock->expects($this->once())
144 ->method(
'getStockItem')
146 ->willReturn($stockItemMock);
148 $this->assertEquals($stockQty, $this->block->getStockQtyLeft());
158 'product qty' => 100,
161 'default qty' =>
null,
162 'expected qty' => 100,
165 'product qty' => 100,
166 'product id' =>
null,
167 'website id' =>
null,
168 'default qty' =>
null,
172 'product qty' =>
null,
173 'product id' =>
null,
174 'website id' =>
null,
187 $property = new \ReflectionProperty($this->block,
'_data');
188 $property->setAccessible(
true);
189 $dataArray = $property->getValue($this->block);
190 $dataArray[$key] =
$value;
191 $property->setValue($this->block, $dataArray);
196 $this->scopeConfigMock->expects($this->once())->method(
'getValue')->willReturn(5);
197 $this->assertEquals(5, $this->block->getThresholdQty());
getStockQtyDataProvider()
testGetStockQty($productStockQty, $productId, $websiteId, $dataQty, $expectedQty)
setDataArrayValue($key, $value)