Ejemplo n.º 1
0
 public function testSave()
 {
     $productId = 1;
     $this->stockItemMock->expects($this->any())->method('getProductId')->willReturn($productId);
     $this->productMock->expects($this->once())->method('load')->with($productId)->willReturnSelf();
     $this->productMock->expects($this->once())->method('getId')->willReturn($productId);
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('typeId');
     $this->stockConfigurationMock->expects($this->once())->method('isQty')->with('typeId')->willReturn(true);
     $this->stockStateProviderMock->expects($this->once())->method('verifyStock')->with($this->stockItemMock)->willReturn(false);
     $this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn(true);
     $this->stockItemMock->expects($this->once())->method('setIsInStock')->with(false)->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('setStockStatusChangedAutomaticallyFlag')->with(true)->willReturnSelf();
     $this->stockItemMock->expects($this->any())->method('setLowStockDate')->willReturnSelf();
     $this->stockStateProviderMock->expects($this->once())->method('verifyNotification')->with($this->stockItemMock)->willReturn(true);
     $this->stockItemMock->expects($this->atLeastOnce())->method('setStockStatusChangedAuto')->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('hasStockStatusChangedAutomaticallyFlag')->willReturn(true);
     $this->stockItemMock->expects($this->once())->method('getStockStatusChangedAutomaticallyFlag')->willReturn(true);
     $this->stockItemMock->expects($this->once())->method('getWebsiteId')->willReturn(1);
     $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with(1)->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('getStockId')->willReturn(1);
     $this->stockItemMock->expects($this->once())->method('setStockId')->with(1)->willReturnSelf();
     $this->stockItemResourceMock->expects($this->once())->method('save')->with($this->stockItemMock)->willReturnSelf();
     $this->indexProcessorMock->expects($this->once())->method('reindexRow')->with($productId);
     $this->assertEquals($this->stockItemMock, $this->model->save($this->stockItemMock));
 }
Ejemplo n.º 2
0
 /**
  * Test if stock state properly changed after import
  *
  * @magentoDataFixture Magento/Catalog/_files/multiple_products.php
  * @magentoAppIsolation enabled
  */
 public function testStockState()
 {
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem');
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = new \Magento\ImportExport\Model\Import\Source\Csv(__DIR__ . '/_files/products_to_import_with_qty.csv', $directory);
     $this->assertTrue($this->_model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE, 'entity' => 'catalog_product'])->setSource($source)->isDataValid());
     $this->_stockStateProvider->expects($this->atLeastOnce())->method('verifyStock')->willReturn(true);
     $this->_model->importData();
 }
Ejemplo n.º 3
0
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->stock = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockInterface', [], [], '', false);
     $this->stockItem = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface', [], [], '', false);
     $this->stockStatus = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface', [], [], '', false);
     $this->objectResult = $this->getMock('\\Magento\\Framework\\Object', [], [], '', false);
     $this->stockStateProvider = $this->getMock('Magento\\CatalogInventory\\Model\\Spi\\StockStateProviderInterface', ['verifyStock', 'verifyNotification', 'checkQty', 'suggestQty', 'getStockQty', 'checkQtyIncrements', 'checkQuoteItemQty'], [], '', false);
     $this->stockStateProvider->expects($this->any())->method('verifyStock')->willReturn(true);
     $this->stockStateProvider->expects($this->any())->method('verifyNotification')->willReturn(true);
     $this->stockStateProvider->expects($this->any())->method('checkQty')->willReturn(true);
     $this->stockStateProvider->expects($this->any())->method('suggestQty')->willReturn($this->qty);
     $this->stockStateProvider->expects($this->any())->method('getStockQty')->willReturn($this->qty);
     $this->stockStateProvider->expects($this->any())->method('checkQtyIncrements')->willReturn($this->objectResult);
     $this->stockStateProvider->expects($this->any())->method('checkQuoteItemQty')->willReturn($this->objectResult);
     $this->stockRegistryProvider = $this->getMock('Magento\\CatalogInventory\\Model\\Spi\\StockRegistryProviderInterface', ['getStock', 'getStockItem', 'getStockStatus'], [], '', false);
     $this->stockRegistryProvider->expects($this->any())->method('getStock')->will($this->returnValue($this->stock));
     $this->stockRegistryProvider->expects($this->any())->method('getStockItem')->will($this->returnValue($this->stockItem));
     $this->stockRegistryProvider->expects($this->any())->method('getStockStatus')->will($this->returnValue($this->stockStatus));
     $this->stockState = $this->objectManagerHelper->getObject('\\Magento\\CatalogInventory\\Model\\StockState', ['stockStateProvider' => $this->stockStateProvider, 'stockRegistryProvider' => $this->stockRegistryProvider]);
 }