public function testModifyData() { $modelId = 1; $this->productMock->expects($this->any())->method('getId')->willReturn($modelId); $this->stockItemMock->expects($this->once())->method('getData')->willReturn($this->getSampleData()); $this->assertArrayHasKey($modelId, $this->getModel()->modifyData([])); }
/** * @param bool $canReturnToStock * @param bool $manageStock * @param bool $result * @dataProvider canReturnItemsToStockDataProvider */ public function testCanReturnItemsToStock($canReturnToStock, $manageStock, $result) { $productId = 7; $property = new \ReflectionProperty($this->items, '_canReturnToStock'); $property->setAccessible(true); $this->assertNull($property->getValue($this->items)); $this->stockConfiguration->expects($this->once())->method('canSubtractQty')->will($this->returnValue($canReturnToStock)); if ($canReturnToStock) { $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup', 'getStore'], [], '', false); $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false); $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10)); $orderItem->expects($this->any())->method('getStore')->will($this->returnValue($store)); $orderItem->expects($this->once())->method('getProductId')->will($this->returnValue($productId)); $creditMemoItem = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', ['setCanReturnToStock', 'getOrderItem', '__wakeup'], [], '', false); $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false); $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue([$creditMemoItem])); $creditMemoItem->expects($this->any())->method('getOrderItem')->will($this->returnValue($orderItem)); $this->stockItemMock->expects($this->once())->method('getManageStock')->will($this->returnValue($manageStock)); $creditMemoItem->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCanReturnToStock', '__wakeup'], [], '', false); $order->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $creditMemo->expects($this->once())->method('getOrder')->will($this->returnValue($order)); $this->registryMock->expects($this->any())->method('registry')->with('current_creditmemo')->will($this->returnValue($creditMemo)); } $this->assertSame($result, $this->items->canReturnItemsToStock()); $this->assertSame($result, $property->getValue($this->items)); // lazy load test $this->assertSame($result, $this->items->canReturnItemsToStock()); }
/** * @param int $productId * @param int $qtyInc * @param bool $isSaleable * @param int|bool $result * @dataProvider getProductQtyIncrementsDataProvider */ public function testGetProductQtyIncrements($productId, $qtyInc, $isSaleable, $result) { $this->stockItem->expects($this->once())->method('getQtyIncrements')->will($this->returnValue($qtyInc)); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->once())->method('getId')->will($this->returnValue($productId)); $product->expects($this->once())->method('isSaleable')->will($this->returnValue($isSaleable)); $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId', '__wakeup'], [], '', false); $store->expects($this->any())->method('getWebsiteId')->willReturn(0); $product->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->registryMock->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product)); $this->assertSame($result, $this->block->getProductQtyIncrements()); // test lazy load $this->assertSame($result, $this->block->getProductQtyIncrements()); }
public function testAfterGetQuantityValidators() { $result = ['validate-item-quantity' => ['minAllowed' => 2, 'maxAllowed' => 5, 'qtyIncrements' => 3]]; $validators = []; $productViewBlock = $this->getMockBuilder('Magento\\Catalog\\Block\\Product\\View')->disableOriginalConstructor()->getMock(); $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId', 'getStore'])->getMock(); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getWebsiteId', '_wakeup'])->getMock(); $productViewBlock->expects($this->any())->method('getProduct')->willReturn($productMock); $productMock->expects($this->once())->method('getId')->willReturn('productId'); $productMock->expects($this->once())->method('getStore')->willReturn($storeMock); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn('websiteId'); $this->stockRegistry->expects($this->once())->method('getStockItem')->with('productId', 'websiteId')->willReturn($this->stockItem); $this->stockItem->expects($this->once())->method('getQtyMinAllowed')->willReturn(2); $this->stockItem->expects($this->any())->method('getQtyMaxAllowed')->willReturn(5); $this->stockItem->expects($this->any())->method('getQtyIncrements')->willReturn(3); $this->assertEquals($result, $this->block->afterGetQuantityValidators($productViewBlock, $validators)); }
public function testUpdateStockItemBySku() { $itemId = 1; $this->stockItem->expects($this->once())->method('setProductId')->willReturnSelf(); $this->stockItem->expects($this->once())->method('getData')->willReturn([]); $this->stockItem->expects($this->once())->method('addData')->willReturnSelf(); $this->stockItem->expects($this->atLeastOnce())->method('getItemId')->willReturn($itemId); $this->assertEquals($itemId, $this->stockRegistry->updateStockItemBySku($this->productSku, $this->stockItem)); }
public function testGetStockItem() { $this->stockItemCriteriaFactory->expects($this->once())->method('create')->willReturn($this->stockItemCriteria); $this->stockItemCriteria->expects($this->once())->method('setProductsFilter')->willReturn(null); $stockItemCollection = $this->getMock('\\Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Item\\Collection', ['getFirstItem', '__wakeup', 'getItems'], [], '', false); $stockItemCollection->expects($this->once())->method('getItems')->willReturn([$this->stockItem]); $this->stockItemRepository->expects($this->once())->method('getList')->willReturn($stockItemCollection); $this->stockItem->expects($this->once())->method('getItemId')->willReturn(true); $this->assertEquals($this->stockItem, $this->stockRegistryProvider->getStockItem($this->productId, $this->scopeId)); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid stock item id: 35. Assigned stock item id is 40 */ public function testAroundSaveWithNotAssignedStockItemId() { $stockId = 80; $stockItemId = 35; $defaultScopeId = 100; $defaultStockId = 80; $storedStockitemId = 40; $this->stockItem->expects($this->once())->method('getStockId')->willReturn($stockId); $this->stockRegistry->expects($this->once())->method('getStock')->with($defaultScopeId)->willReturn($this->defaultStock); $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn($defaultScopeId); $this->defaultStock->expects($this->once())->method('getStockId')->willReturn($defaultStockId); $this->product->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtension); $this->productExtension->expects($this->once())->method('getStockItem')->willReturn($this->stockItem); $this->stockItem->expects($this->once())->method('getItemId')->willReturn($stockItemId); $storedStockItem = $this->getMockBuilder(StockItemInterface::class)->setMethods(['getItemId'])->getMockForAbstractClass(); $storedStockItem->expects($this->once())->method('getItemId')->willReturn($storedStockitemId); $this->stockRegistry->expects($this->once())->method('getStockItem')->willReturn($storedStockItem); $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product); }
public function testAroundSave() { $productId = 5494; $websiteId = 1; $storeId = 2; $sku = 'my product that needs saving'; $this->productMock->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtensionMock); $this->productExtensionMock->expects($this->once())->method('getStockItem')->willReturn($this->stockItemMock); $storeMock = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock); $this->savedProductMock->expects($this->once())->method('getId')->willReturn($productId); $this->savedProductMock->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId); $this->savedProductMock->expects($this->atLeastOnce())->method('getSku')->willReturn($sku); $this->stockItemMock->expects($this->once())->method('setProductId')->with($productId); $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with($websiteId); $this->stockRegistry->expects($this->once())->method('updateStockItemBySku')->with($sku, $this->stockItemMock); $newProductMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->disableOriginalConstructor()->getMock(); $this->productRepositoryMock->expects($this->once())->method('get')->with($sku, false, $storeId, true)->willReturn($newProductMock); $this->assertEquals($newProductMock, $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock)); }
public function testModifyData() { $modelId = 1; $someData = 1; $this->productMock->expects($this->any())->method('getId')->willReturn($modelId); $this->stockConfigurationMock->expects($this->any())->method('getDefaultConfigValue')->willReturn("a:0:{}"); $this->stockItemMock->expects($this->once())->method('getData')->willReturn(['someData']); $this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getMinQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getMinSaleQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getMaxSaleQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getIsQtyDecimal')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getIsDecimalDivided')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getBackorders')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getNotifyStockQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getEnableQtyIncrements')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getQtyIncrements')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getIsInStock')->willReturn($someData); $this->arrayManagerMock->expects($this->once())->method('set')->with('1/product/stock_data/min_qty_allowed_in_shopping_cart')->willReturnArgument(1); $this->assertArrayHasKey($modelId, $this->getModel()->modifyData([])); }
public function testModifyData() { $modelId = 1; $someData = 1; $this->productMock->expects($this->any())->method('getId')->willReturn($modelId); $this->stockItemMock->expects($this->once())->method('getData')->willReturn(['someData']); $this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getMinQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getMinSaleQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getMaxSaleQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getIsQtyDecimal')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getIsDecimalDivided')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getBackorders')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getNotifyStockQty')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getEnableQtyIncrements')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getQtyIncrements')->willReturn($someData); $this->stockItemMock->expects($this->once())->method('getIsInStock')->willReturn($someData); $this->assertArrayHasKey($modelId, $this->getModel()->modifyData([])); }