-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Issue with reorder when disabled reorder setting from admin issue25130 #26051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 5 commits into
magento:2.4-develop
from
edenduong:2.4-bugfix/reoder_with_disable_issue25130
Jan 17, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
app/code/Magento/Sales/Test/Unit/Controller/Guest/ReorderTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Sales\Test\Unit\Controller\Guest; | ||
|
||
use Magento\Framework\App\Action\Context; | ||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Controller\Result\RedirectFactory; | ||
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Framework\Registry; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
use Magento\Sales\Controller\Guest\OrderLoader; | ||
use Magento\Sales\Controller\Guest\Reorder; | ||
use Magento\Sales\Helper\Reorder as ReorderHelper; | ||
use Magento\Sales\Model\Order; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test class for Reorder | ||
* | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class ReorderTest extends TestCase | ||
{ | ||
/** | ||
* Stub Order Id | ||
*/ | ||
private const STUB_ORDER_ID = 1; | ||
|
||
/** | ||
* @var Reorder | ||
*/ | ||
private $reorder; | ||
|
||
/** | ||
* @var Registry|MockObject | ||
*/ | ||
private $registryMock; | ||
|
||
/** | ||
* @var OrderLoader|MockObject | ||
*/ | ||
private $orderLoaderMock; | ||
|
||
/** | ||
* @var RequestInterface|MockObject | ||
*/ | ||
private $requestMock; | ||
|
||
/** | ||
* @var RedirectFactory|MockObject | ||
*/ | ||
private $resultRedirectFactoryMock; | ||
|
||
/** | ||
* @var ReorderHelper|MockObject | ||
*/ | ||
private $reorderHelperMock; | ||
|
||
/** | ||
* @var MessageManagerInterface|MockObject | ||
*/ | ||
private $messageManagerMock; | ||
|
||
/** | ||
* Setup environment for test | ||
*/ | ||
protected function setUp() | ||
{ | ||
$contextMock = $this->createMock(Context::class); | ||
$this->registryMock = $this->createMock(Registry::class); | ||
$this->orderLoaderMock = $this->createMock(OrderLoader::class); | ||
$this->requestMock = $this->createMock(RequestInterface::class); | ||
$this->resultRedirectFactoryMock = $this->createMock(RedirectFactory::class); | ||
$this->reorderHelperMock = $this->createMock(ReorderHelper::class); | ||
$this->messageManagerMock = $this->createMock(MessageManagerInterface::class); | ||
|
||
$contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); | ||
$contextMock->expects($this->once())->method('getResultRedirectFactory') | ||
->willReturn($this->resultRedirectFactoryMock); | ||
$contextMock->expects($this->once())->method('getMessageManager') | ||
->willReturn($this->messageManagerMock); | ||
|
||
$objectManagerMock = $this->createMock(ObjectManagerInterface::class); | ||
$objectManagerMock->expects($this->once())->method('get') | ||
->with(ReorderHelper::class) | ||
->willReturn($this->reorderHelperMock); | ||
|
||
ObjectManager::setInstance($objectManagerMock); | ||
|
||
$objectManager = new ObjectManagerHelper($this); | ||
$this->reorder = $objectManager->getObject( | ||
Reorder::class, | ||
[ | ||
'context' => $contextMock, | ||
'orderLoader' => $this->orderLoaderMock, | ||
'registry' => $this->registryMock | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test execute() with the reorder is not allowed | ||
*/ | ||
public function testExecuteWithReorderIsNotAllowed() | ||
edenduong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$orderMock = $this->createMock(Order::class); | ||
$orderMock->method('getId')->willReturn(self::STUB_ORDER_ID); | ||
|
||
$this->orderLoaderMock->method('load') | ||
->with($this->requestMock) | ||
->willReturn($this->resultRedirectFactoryMock); | ||
|
||
$this->registryMock->expects($this->once())->method('registry') | ||
->with('current_order') | ||
->willReturn($orderMock); | ||
|
||
$this->reorderHelperMock->method('canReorder')->with(self::STUB_ORDER_ID) | ||
->willReturn(false); | ||
|
||
$resultRedirectMock = $this->createMock(Redirect::class); | ||
$this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($resultRedirectMock); | ||
|
||
$this->reorderHelperMock->method('canReorder')->with(self::STUB_ORDER_ID) | ||
->willReturn(false); | ||
|
||
/** Expected Error Message */ | ||
$this->messageManagerMock->expects($this->once()) | ||
->method('addErrorMessage') | ||
->with('Reorder is not available.')->willReturnSelf(); | ||
$resultRedirectMock->expects($this->once()) | ||
->method('setPath') | ||
->with('checkout/cart')->willReturnSelf(); | ||
|
||
/** Assert result */ | ||
$this->assertEquals($resultRedirectMock, $this->reorder->execute()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.