/** * @covers \Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid::getItems */ public function testGetItems() { $productId = 8; $itemQty = 23; $layoutMock = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $blockMock = $this->getMock('Magento\\Framework\\View\\Element\\AbstractBlock', ['getItems'], [], '', false); $itemMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Item', array('getProduct', 'setHasError', 'setQty', 'getQty', '__sleep', '__wakeup'), array(), '', false); $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', array('getStockItem', 'getID', '__sleep', '__wakeup'), array(), '', false); $checkMock = $this->getMock('Magento\\Framework\\Object', ['getMessage', 'getHasError'], [], '', false); $layoutMock->expects($this->once())->method('getParentName')->will($this->returnValue('parentBlock')); $layoutMock->expects($this->once())->method('getBlock')->with('parentBlock')->will($this->returnValue($blockMock)); $blockMock->expects($this->once())->method('getItems')->will($this->returnValue(array($itemMock))); $itemMock->expects($this->any())->method('getChildren')->will($this->returnValue(array($itemMock))); $itemMock->expects($this->any())->method('getProduct')->will($this->returnValue($productMock)); $itemMock->expects($this->any())->method('getQty')->will($this->returnValue($itemQty)); $productMock->expects($this->any())->method('getId')->will($this->returnValue($productId)); $productMock->expects($this->any())->method('getStatus')->will($this->returnValue(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)); $checkMock->expects($this->any())->method('getMessage')->will($this->returnValue('Message')); $checkMock->expects($this->any())->method('getHasError')->will($this->returnValue(false)); $this->stockItemService->expects($this->once())->method('checkQuoteItemQty')->with($this->equalTo($productId), $this->equalTo($itemQty), $this->equalTo($itemQty))->will($this->returnValue($checkMock)); $this->block->getQuote()->setIsSuperMode(true); $items = $this->block->setLayout($layoutMock)->getItems(); $this->assertEquals('Message', $items[0]->getMessage()); $this->assertEquals(true, $this->block->getQuote()->getIsSuperMode()); }
/** * Run test getQuote method * * @return void * @dataProvider getQuoteDataProvider */ public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expectedNumberOfInvokes) { $quoteId = 22; $storeId = 10; $this->quote->expects($this->any())->method('getQuoteId')->will($this->returnValue($quoteId)); $this->quote->expects($this->any())->method('setQuoteId')->with($quoteId); $this->quote->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->quote->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId)); $dataCustomerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerRepositoryMock->expects($this->{$expectedNumberOfInvokes}())->method('getById')->with($customerId)->willReturn($dataCustomerMock); $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['setStoreId', 'setCustomerGroupId', 'setIsActive', 'getId', 'assignCustomer', 'setIgnoreOldQty', 'setIsSuperMode', 'getCustomerId', '__wakeup'], [], '', false); $quoteMock->expects($this->once())->method('setStoreId')->with($storeId); $quoteMock->expects($this->{$expectedNumberOfInvokes}())->method('assignCustomer')->with($dataCustomerMock); $quoteMock->expects($this->once())->method('setIgnoreOldQty')->with(true); $quoteMock->expects($this->once())->method('setIsSuperMode')->with(true); $quoteMock->expects($this->once())->method('getCustomerId')->will($this->returnValue($quoteCustomerId)); $this->quoteRepositoryMock->expects($this->once())->method('get')->with($quoteId)->willReturn($quoteMock); $this->assertEquals($quoteMock, $this->quote->getQuote()); }