/** * Test execute * * @return void */ public function testExecute() { $orderId = 1; $invoiceData = ['comment_text' => 'test']; $response = 'test data'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('invoice', [])->will($this->returnValue($invoiceData)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('getTotalQty')->willReturn(2); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', 'getId', 'canInvoice'])->getMock(); $orderMock->expects($this->once())->method('load')->with($orderId)->willReturnSelf(); $orderMock->expects($this->once())->method('getId')->willReturn($orderId); $orderMock->expects($this->once())->method('canInvoice')->willReturn(true); $this->invoiceServiceMock->expects($this->once())->method('prepareInvoice')->with($orderMock, [])->willReturn($invoiceMock); $this->objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($orderMock); $blockItemMock = $this->getMockBuilder('Magento\\Sales\\Block\\Order\\Items')->disableOriginalConstructor()->setMethods([])->getMock(); $blockItemMock->expects($this->once())->method('toHtml')->will($this->returnValue($response)); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock(); $layoutMock->expects($this->once())->method('getBlock')->with('order_items')->will($this->returnValue($blockItemMock)); $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock)); $this->resultPageMock->expects($this->once())->method('getConfig')->will($this->returnValue($this->pageConfigMock)); $this->pageConfigMock->expects($this->once())->method('getTitle')->will($this->returnValue($this->titleMock)); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $resultRaw = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Raw')->disableOriginalConstructor()->setMethods([])->getMock(); $resultRaw->expects($this->once())->method('setContents')->with($response); $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw)); $this->assertSame($resultRaw, $this->controller->execute()); }
public function testExecute() { $orderId = 1; $invoiceData = []; $commentText = 'comment test'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('invoice', [])->will($this->returnValue($invoiceData)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('getTotalQty')->willReturn(2); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', 'getId', 'canInvoice'])->getMock(); $orderMock->expects($this->once())->method('load')->with($orderId)->willReturnSelf(); $orderMock->expects($this->once())->method('getId')->willReturn($orderId); $orderMock->expects($this->once())->method('canInvoice')->willReturn(true); $this->invoiceServiceMock->expects($this->once())->method('prepareInvoice')->with($orderMock, [])->willReturn($invoiceMock); $menuBlockMock = $this->getMockBuilder('Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->setMethods(['getParentItems', 'getMenuModel'])->getMock(); $menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf()); $menuBlockMock->expects($this->any())->method('getParentItems')->with('Magento_Sales::sales_order')->will($this->returnValue([])); $this->sessionMock->expects($this->once())->method('getCommentText')->with(true)->will($this->returnValue($commentText)); $this->objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($orderMock); $this->objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->sessionMock)); $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order'); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $this->assertSame($this->resultPageMock, $this->controller->execute()); }