/** * Test execute * * @return void */ public function testExecute() { $comment = 'Test comment'; $data = ['comment' => $comment]; $html = 'test output'; $creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') ->disableOriginalConstructor() ->getMock(); $commentMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo\Comment') ->disableOriginalConstructor() ->getMock(); $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') ->disableOriginalConstructor() ->getMock(); $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Comments') ->disableOriginalConstructor() ->getMock(); $this->requestMock->expects($this->once()) ->method('getPost') ->with('comment') ->willReturn($data); $this->requestMock->expects($this->any()) ->method('getParam') ->willReturnArgument(0); $creditmemoMock->expects($this->once()) ->method('addComment') ->willReturn($commentMock); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($creditmemoMock); $this->resultPageFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->atLeastOnce()) ->method('getLayout') ->willReturn($layoutMock); $layoutMock->expects($this->once()) ->method('getBlock') ->with('creditmemo_comments') ->willReturn($blockMock); $blockMock->expects($this->once()) ->method('toHtml') ->willReturn($html); $this->resultRawFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultRawMock); $this->resultRawMock->expects($this->once()) ->method('setContents') ->with($html) ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Framework\Controller\Result\Raw', $this->controller->executeInternal() ); }
/** * @return void */ public function testExecute() { $id = '111'; $transactionMock = $this->getMockBuilder('Magento\Framework\DB\Transaction') ->disableOriginalConstructor() ->getMock(); $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); $invoiceMock = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') ->disableOriginalConstructor() ->getMock(); $this->requestMock->expects($this->any()) ->method('getParam') ->withAnyParameters() ->willReturnArgument(0); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($this->creditmemoMock); $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Framework\DB\Transaction') ->willReturn($transactionMock); $this->creditmemoMock->expects($this->any()) ->method('getOrder') ->willReturn($orderMock); $this->creditmemoMock->expects($this->any()) ->method('getInvoice') ->willReturn($invoiceMock); $this->messageManagerMock->expects($this->once()) ->method('addSuccess') ->with('You voided the credit memo.'); $this->resultRedirectFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultRedirectMock); $this->creditmemoMock->expects($this->atLeastOnce()) ->method('getId') ->willReturn($id); $this->resultRedirectMock->expects($this->once()) ->method('setPath') ->with('sales/*/view', ['creditmemo_id' => $id]) ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Redirect', $this->controller->executeInternal() ); }