/** * When clearing collected results, any stored quantity results should * be removed from storage, preventing them from being reused. */ public function testClearResults() { // Side-effect test: results currently stored in session, setting the // sessions quantity results to null will remove any existing results // from being reused. $this->_inventorySession->expects($this->once())->method('setQuantityResults')->with($this->identicalTo(null))->will($this->returnSelf()); $this->assertSame($this->_quantityCollector, $this->_quantityCollector->clearResults()); }
/** * When the quote no-longer has any items to check the quantity of, the * collector should have any existing results cleared to prevent them from * being re-used when items are added back to the cart. */ public function testCheckQuoteWithNoItemsClearsResults() { // Side-effect test: when no items are left to be checked, make sure // any old results are cleared out to prevent re-using cached results // when items are added back to the quote. $this->_quantityCollector->expects($this->once())->method('clearResults')->will($this->returnSelf()); // Mock the quote and item selection to return an empty list of items, // indicating there are no longer any items in the quote to check. $quoteItems = []; $this->_mockQuoteItemSelection($quoteItems); $this->assertSame($this->_quantityService, $this->_quantityService->checkQuoteInventory($this->_quote)); }
public function setUp() { // Create a mock of the quantity results for the quote. $this->_quantityResults = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_results')->disableOriginalConstructor()->setMethods(['getQuantityBySku', 'getQuantityByItemId'])->getMock(); // Create a quote object to use within tests. Expected by // default by the quantity collector when getting results for a quote. $this->_quote = $this->getModelMock('sales/quote', ['addErrorInfo', 'getAllItems']); // Mock the quantity collector to simply always return // the mocked quantity results throughout the tests. $this->_quantityCollector = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_collector')->disableOriginalConstructor()->setMethods(['getQuantityResultsForQuote', 'clearResults'])->getMock(); $this->_quantityCollector->expects($this->any())->method('getQuantityResultsForQuote')->with($this->identicalTo($this->_quote))->will($this->returnValue($this->_quantityResults)); // Mock of the item selection helper, used to filter // down quote items down to just the items that need // to be checked by the inventory service. $this->_inventoryItemSelection = $this->getHelperMock('ebayenterprise_inventory/item_selection', ['isExcludedParent', 'isStockManaged']); // Mock the inventory's data helper to control // expected results from translations doing translations. $this->_inventoryHelper = $this->getHelperMock('ebayenterprise_inventory/data', ['__', 'getRomSku']); // Mock out the translate method, while it would be nice to ensure // strings are getting translated through this method, the complexity // of doing so is not currently worth the effort. $this->_inventoryHelper->expects($this->any())->method('__')->will($this->returnArgument(0)); // Mock the SKU normalization method to just always return the given // SKU. Prevents the need for ensuring configuration is set up just so // for given SKUs to match the "normalized" SKU. $this->_inventoryHelper->expects($this->any())->method('getRomSku')->will($this->returnArgument(0)); // Mock calculations of total item quantity. $this->_quantityHelper = $this->getHelperMock('ebayenterprise_inventory/quantity', ['calculateTotalQuantityRequested']); /** @var EbayEnterprise_MageLog_Helper_Context */ $this->_context = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']); $this->_context->expects($this->any())->method('getMetaData')->will($this->returnValue([])); // Instance of the model being tested, injected // with the mocked dependencies. $this->_quantityService = Mage::getModel('ebayenterprise_inventory/quantity_service', ['quantity_collector' => $this->_quantityCollector, 'inventory_item_selection' => $this->_inventoryItemSelection, 'inventory_helper' => $this->_inventoryHelper, 'quantity_helper' => $this->_quantityHelper, 'log_context' => $this->_context]); $this->_product = Mage::getModel('catalog/product', ['stock_item' => Mage::getModel('catalogInventory/stock_item', ['backorders' => Mage_CatalogInventory_Model_Stock::BACKORDERS_NO])]); }
/** * Get the quantity results for an item. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return EbayEnterprise_Inventory_Model_Quantity|null */ protected function _getQuantityResultForItem(Mage_Sales_Model_Quote_Item_Abstract $item) { return $this->_quantityCollector->getQuantityResultsForQuote($item->getQuote())->getQuantityBySku($this->_inventoryHelper->getRomSku($item->getSku())); }