Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions app/code/Magento/Sales/Helper/Reorder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2015 Adobe
* All Rights Reserved.
*/

namespace Magento\Sales\Helper;
Expand All @@ -11,12 +11,7 @@
*/
class Reorder extends \Magento\Framework\App\Helper\AbstractHelper
{
const XML_PATH_SALES_REORDER_ALLOW = 'sales/reorder/allow';

/**
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;
public const XML_PATH_SALES_REORDER_ALLOW = 'sales/reorder/allow';

/**
* @var \Magento\Sales\Api\OrderRepositoryInterface
Expand All @@ -25,22 +20,21 @@ class Reorder extends \Magento\Framework\App\Helper\AbstractHelper

/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository
) {
$this->orderRepository = $orderRepository;
$this->customerSession = $customerSession;
parent::__construct(
$context
);
}

/**
* Check if reorder is allowed
*
* @return bool
*/
public function isAllow()
Expand Down Expand Up @@ -78,10 +72,6 @@ public function canReorder($orderId)
if (!$this->isAllowed($order->getStore())) {
return false;
}
if ($this->customerSession->isLoggedIn()) {
return $order->canReorder();
} else {
return true;
}
return $order->canReorder();
}
}
40 changes: 3 additions & 37 deletions app/code/Magento/Sales/Test/Unit/Helper/ReorderTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2015 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Sales\Test\Unit\Helper;

use Magento\Customer\Model\Session;
use Magento\Framework\App\Config;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Helper\Context;
Expand Down Expand Up @@ -40,11 +39,6 @@ class ReorderTest extends TestCase
*/
protected $orderMock;

/**
* @var MockObject|Session
*/
protected $customerSessionMock;

/**
* @var OrderRepositoryInterface|MockObject
*/
Expand All @@ -66,15 +60,10 @@ protected function setUp(): void
->method('getScopeConfig')
->willReturn($this->scopeConfigMock);

$this->customerSessionMock = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->getMock();

$this->repositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class)
->getMockForAbstractClass();
$this->helper = new Reorder(
$contextMock,
$this->customerSessionMock,
$this->repositoryMock
);

Expand Down Expand Up @@ -156,40 +145,17 @@ public function testCanReorderStoreNotAllowed()
$this->assertFalse($this->helper->canReorder(1));
}

/**
* Tests what happens if the customer is not logged in and the store does allow re-orders.
*
* @return void
*/
public function testCanReorderCustomerNotLoggedIn()
{
$this->setupOrderMock(true);

$this->customerSessionMock->expects($this->once())
->method('isLoggedIn')
->willReturn(false);
$this->repositoryMock->expects($this->once())
->method('get')
->with(1)
->willReturn($this->orderMock);
$this->assertTrue($this->helper->canReorder(1));
}

/**
* Tests what happens if the customer is logged in and the order does or does not allow reorders.
*
* @param bool $orderCanReorder
* @return void
* @dataProvider getOrderCanReorder
*/
public function testCanReorderCustomerLoggedInAndOrderCanReorder($orderCanReorder)
public function testCanReorder($orderCanReorder)
{
$this->setupOrderMock(true);

$this->customerSessionMock->expects($this->once())
->method('isLoggedIn')
->willReturn(true);

$this->orderMock->expects($this->once())
->method('canReorder')
->willReturn($orderCanReorder);
Expand Down