Example #1
0
 public function testSaveInventoryData()
 {
     $productId = 4;
     $websiteId = 5;
     $stockData = null;
     $websitesChanged = true;
     $statusChanged = true;
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getStockData', 'getIsChangedWebsites', 'dataHasChangedFor', 'getId', 'getStore', '__wakeup'], [], '', false);
     $product->expects($this->once())->method('getStockData')->will($this->returnValue($stockData));
     if ($stockData === null) {
         $product->expects($this->any())->method('getIsChangedWebsites')->will($this->returnValue($websitesChanged));
         $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue($statusChanged));
         if ($websitesChanged || $statusChanged) {
             $product->expects($this->once())->method('getId')->will($this->returnValue($productId));
             $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId', '__wakeup'], [], '', false);
             $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
             $product->expects($this->once())->method('getStore')->will($this->returnValue($store));
             $this->stockIndex->expects($this->once())->method('rebuild')->will($this->returnValue(true));
         }
     } else {
         $stockItem = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockItem', ['__wakeup'], '', false);
         $this->stockRegistry->expects($this->once())->method('getStockItem')->with($productId, $websiteId)->will($this->returnValue($stockItem));
     }
     $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product));
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
     $this->assertEquals($this->observer, $this->observer->saveInventoryData($this->eventObserver));
 }
 public function testSaveInventoryData()
 {
     $productId = 4;
     $websiteId = 5;
     $stockData = null;
     $websitesChanged = true;
     $statusChanged = true;
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
     $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getStockData', 'getIsChangedWebsites', 'dataHasChangedFor', 'getId', 'getStore'], [], '', false);
     $product->expects($this->once())->method('getStockData')->will($this->returnValue($stockData));
     $product->expects($this->any())->method('getIsChangedWebsites')->will($this->returnValue($websitesChanged));
     $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue($statusChanged));
     $product->expects($this->once())->method('getId')->will($this->returnValue($productId));
     $product->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->stockIndex->expects($this->once())->method('rebuild')->will($this->returnValue(true));
     $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product));
     $this->observer->execute($this->eventObserver);
 }