diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php
index be0afdb4a043b..c5832f64547c1 100644
--- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php
+++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php
@@ -6,8 +6,9 @@
namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo;
use Magento\Backend\App\Action;
+use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
-class View extends \Magento\Backend\App\Action
+class View extends \Magento\Backend\App\Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
@@ -75,9 +76,9 @@ public function execute()
}
return $resultPage;
} else {
- $resultForward = $this->resultForwardFactory->create();
- $resultForward->forward('noroute');
- return $resultForward;
+ $resultRedirect = $this->resultRedirectFactory->create();
+ $resultRedirect->setPath('sales/creditmemo');
+ return $resultRedirect;
}
}
}
diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/CreditmemoLoader.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/CreditmemoLoader.php
index 0c5864e954a4f..dbcf22bc7bcf9 100644
--- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CreditmemoLoader.php
+++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CreditmemoLoader.php
@@ -181,7 +181,11 @@ public function load()
$creditmemoId = $this->getCreditmemoId();
$orderId = $this->getOrderId();
if ($creditmemoId) {
- $creditmemo = $this->creditmemoRepository->get($creditmemoId);
+ try {
+ $creditmemo = $this->creditmemoRepository->get($creditmemoId);
+ } catch (\Exception $e) {
+ $this->messageManager->addErrorMessage(__('This creditmemo no longer exists.'));
+ return false;
} elseif ($orderId) {
$data = $this->getCreditmemo();
$order = $this->orderFactory->create()->load($orderId);
diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php
index da700aae2f78a..b0e860d7f2e2d 100644
--- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php
+++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php
@@ -44,9 +44,10 @@ public function execute()
{
$invoice = $this->getInvoice();
if (!$invoice) {
- /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
- $resultForward = $this->resultForwardFactory->create();
- return $resultForward->forward('noroute');
+ /** @var \Magento\Framework\Controller\Result\RedirectFactory $resultRedirect */
+ $resultRedirect = $this->resultRedirectFactory->create();
+ $resultRedirect->setPath('sales/invoice');
+ return $resultRedirect;
}
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
diff --git a/app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminGoToCreditmemoViewActionGroup.xml b/app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminGoToCreditmemoViewActionGroup.xml
new file mode 100644
index 0000000000000..b55a7e8d6e5ed
--- /dev/null
+++ b/app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminGoToCreditmemoViewActionGroup.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ Goes to the Order Creditmemo View Page.
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminOpenShipmentViewPageWithWrongCreditmemoIdTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminOpenShipmentViewPageWithWrongCreditmemoIdTest.xml
new file mode 100644
index 0000000000000..f04629708e0cd
--- /dev/null
+++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminOpenShipmentViewPageWithWrongCreditmemoIdTest.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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 46c3113c8edc2..e7556fe309ecf 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
@@ -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\Message\Manager;
@@ -105,6 +107,17 @@ class ViewTest extends TestCase
*/
protected $pageTitleMock;
+ /**
+ * @var \Magento\Shipping\Controller\Adminhtml\Order\Creditmemo\View
+ * @var RedirectFactory|MockObject
+ */
+ protected $resultRedirectFactoryMock;
+
+ /**
+ * @var Redirect|MockObject
+ */
+ protected $resultRedirectMock;
+
/**
* @var PageFactory|MockObject
*/
@@ -239,7 +252,8 @@ protected function setUp(): void
'context' => $this->contextMock,
'creditmemoLoader' => $this->loaderMock,
'resultPageFactory' => $this->resultPageFactoryMock,
- 'resultForwardFactory' => $this->resultForwardFactoryMock
+ 'resultForwardFactory' => $this->resultForwardFactoryMock,
+ 'resultRedirectFactory' => $this->resultRedirectFactoryMock
]
);
}
@@ -252,16 +266,11 @@ public function testExecuteNoCreditMemo()
$this->loaderMock->expects($this->once())
->method('load')
->willReturn(false);
- $this->resultForwardFactoryMock->expects($this->once())
- ->method('create')
- ->willReturn($this->resultForwardMock);
- $this->resultForwardMock->expects($this->once())
- ->method('forward')
- ->with('noroute')
- ->willReturnSelf();
-
+
+ $this->prepareRedirect();
+ $this->setPath('sales/creditmemo');
$this->assertInstanceOf(
- Forward::class,
+ Redirect::class,
$this->controller->execute()
);
}
@@ -322,4 +331,25 @@ public function executeDataProvider()
[$this->invoiceMock]
];
}
+
+ /**
+ * prepareRedirect
+ */
+ protected function prepareRedirect()
+ {
+ $this->resultRedirectFactoryMock->expects($this->once())
+ ->method('create')
+ ->willReturn($this->resultRedirectMock);
+ }
+
+ /**
+ * @param string $path
+ * @param array $params
+ */
+ protected function setPath($path, $params = [])
+ {
+ $this->resultRedirectMock->expects($this->once())
+ ->method('setPath')
+ ->with($path, $params);
+ }
}
diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/View.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/View.php
index d8fda0bfe781b..d903a1a7d5889 100644
--- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/View.php
+++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/View.php
@@ -7,8 +7,9 @@
namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
use Magento\Backend\App\Action;
+use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
-class View extends \Magento\Backend\App\Action
+class View extends \Magento\Backend\App\Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
@@ -71,9 +72,9 @@ public function execute()
$resultPage->getConfig()->getTitle()->prepend("#" . $shipment->getIncrementId());
return $resultPage;
} else {
- $resultForward = $this->resultForwardFactory->create();
- $resultForward->forward('noroute');
- return $resultForward;
+ $resultRedirect = $this->resultRedirectFactory->create();
+ $resultRedirect->setPath('sales/shipment');
+ return $resultRedirect;
}
}
}
diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/ShipmentLoader.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/ShipmentLoader.php
index c4094a63ec527..4f44bfb6458b1 100644
--- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/ShipmentLoader.php
+++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/ShipmentLoader.php
@@ -110,7 +110,12 @@ public function load()
$orderId = $this->getOrderId();
$shipmentId = $this->getShipmentId();
if ($shipmentId) {
- $shipment = $this->shipmentRepository->get($shipmentId);
+ try {
+ $shipment = $this->shipmentRepository->get($shipmentId);
+ } catch (\Exception $e) {
+ $this->messageManager->addErrorMessage(__('This shipment no longer exists.'));
+ return false;
+ }
} elseif ($orderId) {
$order = $this->orderRepository->get($orderId);
diff --git a/app/code/Magento/Shipping/Test/Mftf/ActionGroup/AdminGoToShipmentViewActionGroup.xml b/app/code/Magento/Shipping/Test/Mftf/ActionGroup/AdminGoToShipmentViewActionGroup.xml
new file mode 100644
index 0000000000000..09f74839b3a30
--- /dev/null
+++ b/app/code/Magento/Shipping/Test/Mftf/ActionGroup/AdminGoToShipmentViewActionGroup.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ Goes to the Order Shipment View Page.
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/code/Magento/Shipping/Test/Mftf/Page/AdminShipmentViewPage.xml b/app/code/Magento/Shipping/Test/Mftf/Page/AdminShipmentViewPage.xml
new file mode 100644
index 0000000000000..5a965db2b4efe
--- /dev/null
+++ b/app/code/Magento/Shipping/Test/Mftf/Page/AdminShipmentViewPage.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/code/Magento/Shipping/Test/Mftf/Test/AdminOpenShipmentViewPageWithWrongShipmentIdTest.xml b/app/code/Magento/Shipping/Test/Mftf/Test/AdminOpenShipmentViewPageWithWrongShipmentIdTest.xml
new file mode 100644
index 0000000000000..0311ebc320b59
--- /dev/null
+++ b/app/code/Magento/Shipping/Test/Mftf/Test/AdminOpenShipmentViewPageWithWrongShipmentIdTest.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/ViewTest.php b/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/ViewTest.php
index 04b357eeaefca..d99ce83d91de2 100644
--- a/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/ViewTest.php
+++ b/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/ViewTest.php
@@ -11,6 +11,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\RequestInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -21,6 +23,7 @@
use Magento\Sales\Model\Order\Shipment;
use Magento\Shipping\Block\Adminhtml\View;
use Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader;
+use Magento\Shipping\Controller\Adminhtml\Order\Shipment\View as OrderShipmentView;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -84,11 +87,24 @@ class ViewTest extends TestCase
*/
protected $pageTitleMock;
+
/**
* @var \Magento\Shipping\Controller\Adminhtml\Order\Shipment\View
+ * @var RedirectFactory|MockObject
+ */
+ protected $resultRedirectFactoryMock;
+
+ /**
+ * @var Redirect|MockObject
+ */
+ protected $resultRedirectMock;
+
+ /**
+ * @var OrderShipmentView
*/
protected $controller;
+
protected function setUp(): void
{
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
@@ -130,16 +146,25 @@ protected function setUp(): void
['updateBackButtonUrl']
);
+ $this->resultRedirectFactoryMock = $this->getMockBuilder(RedirectFactory::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['create'])
+ ->getMock();
+ $this->resultRedirectMock = $this->getMockBuilder(Redirect::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
$objectManager = new ObjectManager($this);
$context = $objectManager->getObject(
Context::class,
[
'request' => $this->requestMock,
- 'objectManager' => $this->objectManagerMock
+ 'objectManager' => $this->objectManagerMock,
+ 'resultRedirectFactory' => $this->resultRedirectFactoryMock
]
);
$this->controller = $objectManager->getObject(
- \Magento\Shipping\Controller\Adminhtml\Order\Shipment\View::class,
+ OrderShipmentView::class,
[
'context' => $context,
'shipmentLoader' => $this->shipmentLoaderMock,
@@ -216,15 +241,12 @@ public function testExecuteNoShipment()
$tracking = [];
$this->loadShipment($orderId, $shipmentId, $shipment, $tracking, null, false);
- $this->resultForwardFactoryMock->expects($this->once())
- ->method('create')
- ->willReturn($this->resultForwardMock);
- $this->resultForwardMock->expects($this->once())
- ->method('forward')
- ->with('noroute')
- ->willReturnSelf();
-
- $this->assertEquals($this->resultForwardMock, $this->controller->execute());
+ $this->prepareRedirect();
+ $this->setPath('sales/shipment');
+ $this->assertInstanceOf(
+ Redirect::class,
+ $this->controller->execute()
+ );
}
/**
@@ -255,4 +277,25 @@ protected function loadShipment($orderId, $shipmentId, $shipment, $tracking, $co
->method('load')
->willReturn($returnShipment);
}
+
+ /**
+ * prepareRedirect
+ */
+ protected function prepareRedirect()
+ {
+ $this->resultRedirectFactoryMock->expects($this->once())
+ ->method('create')
+ ->willReturn($this->resultRedirectMock);
+ }
+
+ /**
+ * @param string $path
+ * @param array $params
+ */
+ protected function setPath($path, $params = [])
+ {
+ $this->resultRedirectMock->expects($this->once())
+ ->method('setPath')
+ ->with($path, $params);
+ }
}