Skip to content

Commit

Permalink
Fixed issue related with wrong invoice id ,creditmemo id and shipmen …
Browse files Browse the repository at this point in the history
…id in url of view page.
  • Loading branch information
govindasharma974 committed Oct 10, 2020
1 parent 68770fc commit ff1a003
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminGoToCreditmemoViewActionGroup">
<annotations>
<description>Goes to the Order Creditmemo View Page.</description>
</annotations>
<arguments>
<argument name="identifier" type="string"/>
</arguments>

<amOnPage url="{{AdminCreditmemoViewPage.url}}/{{identifier}}" stepKey="amOnCreditmemoViewPage"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminOpenCreditmemoViewPageWithWrongCreditmemoIdTest">
<annotations>
<stories value="Creditmemo Page With Wrong Creditmemo Id"/>
<title value="Open Creditmemo View Page with Wrong Creditmemo Id"/>
<description value="Open Creditmemo View Page with Wrong Creditmemo Id."/>
<severity value="MAJOR"/>
<group value="sales"/>
</annotations>

<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
</before>

<after>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

<actionGroup ref="AdminGoToCreditmemoViewActionGroup" stepKey="navigateOpenCreditmemoViewPage">
<argument name="identifier" value="test"/>
</actionGroup>

<waitForPageLoad stepKey="waitForPageLoad"/>

<seeInCurrentUrl url="{{AdminCreditmemosGridPage.url}}" stepKey="redirectToCreditmemosGridPage"/>

<see selector="{{AdminMessagesSection.error}}" userInput='This creditmemo no longer exists.'
stepKey="seeErrorMessage"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
]
);
}
Expand All @@ -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()
);
}
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminGoToShipmentViewActionGroup">
<annotations>
<description>Goes to the Order Shipment View Page.</description>
</annotations>
<arguments>
<argument name="identifier" type="string"/>
</arguments>

<amOnPage url="{{AdminShipmentViewPage.url}}/{{identifier}}" stepKey="amOnShipmentViewPage"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
</actionGroup>
</actionGroups>
13 changes: 13 additions & 0 deletions app/code/Magento/Shipping/Test/Mftf/Page/AdminShipmentViewPage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
<page name="AdminShipmentViewPage" url="sales/shipment/view/shipment_id" area="admin" module="Shipping">
</page>
</pages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminOpenShipmentViewPageWithWrongShipmentIdTest">
<annotations>
<stories value="Shipment Page With Wrong Shipment Id"/>
<title value="Open Shipment View Page with Wrong Shipment Id"/>
<description value="Open Shipment View Page with Wrong Shipment Id."/>
<severity value="MAJOR"/>
<group value="shipping"/>
</annotations>

<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
</before>

<after>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

<actionGroup ref="AdminGoToShipmentViewActionGroup" stepKey="navigateOpenShipmentViewPage">
<argument name="identifier" value="test"/>
</actionGroup>

<waitForPageLoad stepKey="waitForPageLoad"/>

<seeInCurrentUrl url="{{AdminShipmentsGridPage.url}}" stepKey="redirectToShipmentsGridPage"/>

<see selector="{{AdminMessagesSection.error}}" userInput='This shipment no longer exists.'
stepKey="seeErrorMessage"/>
</test>
</tests>
Loading

0 comments on commit ff1a003

Please sign in to comment.