public function testInitializeWhenResultNotDecimalGetBackordersMessageHasOptionQtyUpdate()
 {
     $optionValue = 5;
     $qtyForCheck = 50;
     $qty = 10;
     $this->optionMock->expects($this->once())->method('getValue')->will($this->returnValue($optionValue));
     $this->quoteItemMock->expects($this->once())->method('getQtyToAdd')->will($this->returnValue(false));
     $this->optionMock->expects($this->any())->method('getProduct')->will($this->returnValue($this->productMock));
     $this->stockItemMock->expects($this->once())->method('setIsChildItem')->with(true);
     $this->stockItemMock->expects($this->once())->method('setSuppressCheckQtyIncrements')->with(true);
     $this->stockItemMock->expects($this->once())->method('getItemId')->will($this->returnValue(true));
     $this->stockRegistry->expects($this->once())->method('getStockItem')->will($this->returnValue($this->stockItemMock));
     $this->productMock->expects($this->any())->method('getId')->will($this->returnValue($this->productId));
     $this->quoteItemMock->expects($this->any())->method('getId')->will($this->returnValue('quote_item_id'));
     $this->quoteItemMock->expects($this->once())->method('getQuoteId')->will($this->returnValue('quote_id'));
     $this->qtyItemListMock->expects($this->once())->method('getQty')->with($this->productId, 'quote_item_id', 'quote_id', $qty * $optionValue)->will($this->returnValue($qtyForCheck));
     $this->stockState->expects($this->once())->method('checkQuoteItemQty')->with($this->productId, $qty * $optionValue, $qtyForCheck, $optionValue, $this->websiteId)->will($this->returnValue($this->resultMock));
     $this->resultMock->expects($this->once())->method('getItemIsQtyDecimal')->will($this->returnValue(null));
     $this->optionMock->expects($this->never())->method('setIsQtyDecimal');
     $this->resultMock->expects($this->once())->method('getHasQtyOptionUpdate')->will($this->returnValue(null));
     $this->optionMock->expects($this->never())->method('setHasQtyOptionUpdate');
     $this->resultMock->expects($this->once())->method('getMessage')->will($this->returnValue(null));
     $this->resultMock->expects($this->once())->method('getItemBackorders')->will($this->returnValue(null));
     $this->optionMock->expects($this->never())->method('setBackorders');
     $this->stockItemMock->expects($this->once())->method('unsIsChildItem');
     $this->validator->initialize($this->optionMock, $this->quoteItemMock, $qty);
 }
示例#2
0
 public function testIsSalableNoManageStock()
 {
     $option1 = $this->getRequiredOptionMock(10, 10);
     $option2 = $this->getRequiredOptionMock(20, 10);
     $stockItem = $this->getStockItem(true);
     $this->stockRegistry->method('getStockItem')->willReturn($stockItem);
     $this->stockState->expects($this->at(0))->method('getStockQty')->with(10)->willReturn(10);
     $this->stockState->expects($this->at(1))->method('getStockQty')->with(20)->willReturn(10);
     $optionCollectionMock = $this->getOptionCollectionMock([$option1, $option2]);
     $selectionCollectionMock = $this->getSelectionCollectionMock([$option1, $option2]);
     $product = new \Magento\Framework\Object(['is_salable' => true, '_cache_instance_options_collection' => $optionCollectionMock, 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, '_cache_instance_selections_collection10_20' => $selectionCollectionMock]);
     $this->assertTrue($this->model->isSalable($product));
 }
示例#3
0
 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());
 }