Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReorderTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Sales\Helper\Reorder;
10 
11 class ReorderTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $helper;
17 
21  protected $scopeConfigMock;
22 
26  protected $storeParam;
27 
31  protected $orderMock;
32 
37 
41  protected $repositoryMock;
42 
46  protected function setUp()
47  {
48  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config::class)
49  ->setMethods(['getValue'])
50  ->disableOriginalConstructor()
51  ->getMock();
52  $contextMock = $this->getMockBuilder(\Magento\Framework\App\Helper\Context::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $contextMock->expects($this->any())
56  ->method('getScopeConfig')
57  ->willReturn($this->scopeConfigMock);
58 
59  $this->customerSessionMock = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62 
63  $this->repositoryMock = $this->getMockBuilder(\Magento\Sales\Api\OrderRepositoryInterface::class)
64  ->getMockForAbstractClass();
65  $this->helper = new \Magento\Sales\Helper\Reorder(
66  $contextMock,
67  $this->customerSessionMock,
68  $this->repositoryMock
69  );
70 
71  $this->storeParam = $this->getMockBuilder(\Magento\Sales\Model\Store::class)
72  ->disableOriginalConstructor()
73  ->getMock();
74 
75  $this->orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
76  ->disableOriginalConstructor()
77  ->getMock();
78  }
79 
86  public function testIsAllowedScopeConfigReorder($scopeConfigValue)
87  {
88  $this->setupScopeConfigMock($scopeConfigValue);
89  $this->assertEquals($scopeConfigValue, $this->helper->isAllowed($this->storeParam));
90  }
91 
98  public function testIsAllowScopeConfigReorderNotAllowWithStore($scopeConfigValue)
99  {
100  $this->storeParam = null;
101  $this->setupScopeConfigMock($scopeConfigValue);
102  $this->assertEquals($scopeConfigValue, $this->helper->isAllow());
103  }
104 
108  public function getScopeConfigValue()
109  {
110  return [
111  [true],
112  [false]
113  ];
114  }
115 
122  protected function setupScopeConfigMock($returnValue)
123  {
124  $this->scopeConfigMock->expects($this->once())
125  ->method('getValue')
126  ->with(
128  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
129  $this->storeParam
130  )
131  ->will($this->returnValue($returnValue));
132  }
133 
140  {
141  $this->setupOrderMock(false);
142  $this->repositoryMock->expects($this->once())
143  ->method('get')
144  ->with(1)
145  ->willReturn($this->orderMock);
146  $this->assertFalse($this->helper->canReorder(1));
147  }
148 
155  {
156  $this->setupOrderMock(true);
157 
158  $this->customerSessionMock->expects($this->once())
159  ->method('isLoggedIn')
160  ->will($this->returnValue(false));
161  $this->repositoryMock->expects($this->once())
162  ->method('get')
163  ->with(1)
164  ->willReturn($this->orderMock);
165  $this->assertTrue($this->helper->canReorder(1));
166  }
167 
175  public function testCanReorderCustomerLoggedInAndOrderCanReorder($orderCanReorder)
176  {
177  $this->setupOrderMock(true);
178 
179  $this->customerSessionMock->expects($this->once())
180  ->method('isLoggedIn')
181  ->will($this->returnValue(true));
182 
183  $this->orderMock->expects($this->once())
184  ->method('canReorder')
185  ->will($this->returnValue($orderCanReorder));
186  $this->repositoryMock->expects($this->once())
187  ->method('get')
188  ->with(1)
189  ->willReturn($this->orderMock);
190  $this->assertEquals($orderCanReorder, $this->helper->canReorder(1));
191  }
192 
199  protected function setupOrderMock($storeScopeReturnValue)
200  {
201  $this->setupScopeConfigMock($storeScopeReturnValue);
202  $this->orderMock->expects($this->once())
203  ->method('getStore')
204  ->will($this->returnValue($this->storeParam));
205  }
206 
210  public function getOrderCanReorder()
211  {
212  return [
213  [true],
214  [false]
215  ];
216  }
217 }
testIsAllowedScopeConfigReorder($scopeConfigValue)
Definition: ReorderTest.php:86
testIsAllowScopeConfigReorderNotAllowWithStore($scopeConfigValue)
Definition: ReorderTest.php:98
testCanReorderCustomerLoggedInAndOrderCanReorder($orderCanReorder)