From ade5168bb1a2228e5b18b65d4e295be4be74af4c Mon Sep 17 00:00:00 2001 From: govindasharma974 Date: Thu, 29 Oct 2020 17:29:42 +0530 Subject: [PATCH] updated test files --- .../Adminhtml/Order/Creditmemo/ViewTest.php | 2 +- .../Adminhtml/Order/Invoice/ViewTest.php | 55 ++++++++++++++++--- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/ViewTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/ViewTest.php index b6935269e3da7..6e04f4caadc8f 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/ViewTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/ViewTest.php @@ -108,7 +108,7 @@ class ViewTest extends TestCase protected $pageTitleMock; /** - * @var \Magento\Shipping\Controller\Adminhtml\Order\Creditmemo\View + * @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\View * @var RedirectFactory|MockObject */ protected $resultRedirectFactoryMock; diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/ViewTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/ViewTest.php index c8376ab379b6f..a29ab201e0bd9 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/ViewTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/ViewTest.php @@ -13,6 +13,8 @@ use Magento\Backend\Model\View\Result\Forward; use Magento\Backend\Model\View\Result\ForwardFactory; use Magento\Backend\Model\View\Result\Page; +use Magento\Backend\Model\View\Result\Redirect; +use Magento\Backend\Model\View\Result\RedirectFactory; use Magento\Framework\App\ActionFlag; use Magento\Framework\App\Request\Http; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; @@ -82,6 +84,17 @@ class ViewTest extends TestCase */ protected $pageTitleMock; + /** + * @var \Magento\Sales\Controller\Adminhtml\Order\Invoice\View + * @var RedirectFactory|MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var Redirect|MockObject + */ + protected $resultRedirectMock; + /** * @var View */ @@ -194,6 +207,13 @@ protected function setUp(): void )->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder(RedirectFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder(Redirect::class) + ->disableOriginalConstructor() + ->getMock(); $this->invoiceRepository = $this->getMockBuilder(InvoiceRepositoryInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -203,7 +223,8 @@ protected function setUp(): void [ 'context' => $contextMock, 'resultPageFactory' => $this->resultPageFactoryMock, - 'resultForwardFactory' => $this->resultForwardFactoryMock + 'resultForwardFactory' => $this->resultForwardFactoryMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); @@ -287,16 +308,32 @@ public function testExecuteNoInvoice() ->method('get') ->willReturn(null); - $resultForward = $this->getMockBuilder(Forward::class) - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $resultForward->expects($this->once())->method('forward')->with(('noroute'))->willReturnSelf(); + $this->prepareRedirect(); + $this->setPath('sales/invoice'); + $this->assertInstanceOf( + Redirect::class, + $this->controller->execute() + ); + } - $this->resultForwardFactoryMock->expects($this->once()) + /** + * prepareRedirect + */ + protected function prepareRedirect() + { + $this->resultRedirectFactoryMock->expects($this->once()) ->method('create') - ->willReturn($resultForward); + ->willReturn($this->resultRedirectMock); + } - $this->assertSame($resultForward, $this->controller->execute()); + /** + * @param string $path + * @param array $params + */ + protected function setPath($path, $params = []) + { + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with($path, $params); } }