/** * @param int $productStockQty * @param int|null $productId * @param int|null $dataQty * @param int $expectedQty * @dataProvider getStockQtyDataProvider */ public function testGetStockQty($productStockQty, $productId, $dataQty, $expectedQty) { $this->assertNull($this->block->getData('product_stock_qty')); if ($dataQty) { $this->setDataArrayValue('product_stock_qty', $dataQty); } else { $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', '__wakeup'], [], '', false); $product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $this->registryMock->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product)); if ($productId) { $this->stockItemService->expects($this->once())->method('getStockQty')->with($this->equalTo($productId))->will($this->returnValue($productStockQty)); } } $this->assertSame($expectedQty, $this->block->getStockQty()); $this->assertSame($expectedQty, $this->block->getData('product_stock_qty')); }
public function te1stGetStockQtyLeft() { $productId = 1; $minQty = 0; $websiteId = 1; $stockQty = 2; $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->any())->method('getId')->willReturn($productId); $product->expects($this->once())->method('getStore')->willReturn($storeMock); $this->registryMock->expects($this->once())->method('registry')->with('current_product')->will($this->returnValue($product)); $stockItemMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->disableOriginalConstructor()->getMock(); $stockItemMock->expects($this->once())->method('getMinQty')->willReturn($minQty); $this->stockRegistryMock->expects($this->once())->method('getStockItem')->with($productId)->willReturn($stockItemMock); $this->stockState->expects($this->once())->method('getStockQty')->with($productId, $storeMock)->willReturn($stockQty); $this->assertEquals($stockQty, $this->block->getStockQtyLeft()); }
public function testGetThresholdQty() { $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(5); $this->assertEquals(5, $this->block->getThresholdQty()); }