Exemplo n.º 1
0
    /**
     * 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()
        );
    }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function dispatch(\Magento\Framework\App\RequestInterface $request)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'dispatch');
     if (!$pluginInfo) {
         return parent::dispatch($request);
     } else {
         return $this->___callPlugins('dispatch', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 3
0
 public function testExecute()
 {
     $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0);
     $this->loaderMock->expects($this->once())->method('load')->willReturn($this->creditmemoMock);
     $transactionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\DB\\Transaction')->willReturn($transactionMock);
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->creditmemoMock->expects($this->any())->method('getOrder')->willReturn($orderMock);
     $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->creditmemoMock->expects($this->any())->method('getInvoice')->willReturn($invoiceMock);
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('You voided the credit memo.');
     $this->assertNull($this->controller->execute());
 }
Exemplo n.º 4
0
    /**
     * @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()
        );
    }
Exemplo n.º 5
0
 public function testExecute()
 {
     $comment = 'Test comment';
     $data = ['comment' => $comment];
     $html = 'test output';
     $this->requestMock->expects($this->once())->method('getPost')->with('comment')->willReturn($data);
     $this->requestMock->expects($this->any())->method('getParam')->withAnyParameters()->willReturnArgument(0);
     $creditmemoMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->setMethods([])->getMock();
     $commentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo\\Comment')->disableOriginalConstructor()->setMethods([])->getMock();
     $creditmemoMock->expects($this->once())->method('addComment')->withAnyParameters()->willReturn($commentMock);
     $this->loaderMock->expects($this->once())->method('load')->willReturn($creditmemoMock);
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock();
     $blockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Creditmemo\\View\\Comments')->disableOriginalConstructor()->setMethods([])->getMock();
     $blockMock->expects($this->once())->method('toHtml')->willReturn($html);
     $layoutMock->expects($this->once())->method('getBlock')->with('creditmemo_comments')->willReturn($blockMock);
     $this->viewMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
     $this->assertNull($this->controller->execute());
 }