1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Test\Unit\Controller\Adminhtml\Order;
use Magento\Framework\App\Action\Context;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
/**
* Class UnholdTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class UnholdTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Sales\Controller\Adminhtml\Order\Unhold
*/
protected $controller;
/**
* @var Context|\PHPUnit_Framework_MockObject_MockObject
*/
protected $context;
/**
* @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject
*/
protected $resultRedirect;
/**
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
*/
protected $request;
/**
* @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $response;
/**
* @var \Magento\Framework\Message\Manager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $messageManager;
/**
* @var \Magento\Sales\Api\OrderRepositoryInterface
*/
protected $orderRepositoryMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $validatorMock;
/**
* @var \Magento\Framework\ObjectManager\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $objectManager;
/**
* Test setup
*/
protected function setUp()
{
$objectManagerHelper = new ObjectManagerHelper($this);
$this->context = $this->createMock(\Magento\Backend\App\Action\Context::class);
$resultRedirectFactory = $this->createPartialMock(
\Magento\Backend\Model\View\Result\RedirectFactory::class,
['create']
);
$this->response = $this->createPartialMock(
\Magento\Framework\App\ResponseInterface::class,
['setRedirect', 'sendResponse']
);
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
->disableOriginalConstructor()->getMock();
$this->messageManager = $this->createPartialMock(
\Magento\Framework\Message\Manager::class,
['addSuccessMessage', 'addErrorMessage']
);
$this->orderRepositoryMock = $this->getMockBuilder(\Magento\Sales\Api\OrderRepositoryInterface::class)
->disableOriginalConstructor()
->getMock();
$this->validatorMock = $this->getMockBuilder(\Magento\Framework\Data\Form\FormKey\Validator::class)
->disableOriginalConstructor()
->getMock();
$this->resultRedirect = $this->createMock(\Magento\Backend\Model\View\Result\Redirect::class);
$resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
$this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager);
$this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
$this->context->expects($this->once())->method('getResponse')->willReturn($this->response);
$this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager);
$this->context->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory);
$this->context->expects($this->once())->method('getFormKeyValidator')->willReturn($this->validatorMock);
$this->controller = $objectManagerHelper->getObject(
\Magento\Sales\Controller\Adminhtml\Order\Unhold::class,
[
'context' => $this->context,
'request' => $this->request,
'response' => $this->response,
'orderRepository' => $this->orderRepositoryMock
]
);
}
/**
* testExecuteNotPost
*/
public function testExecuteNotPost()
{
$this->validatorMock->expects($this->once())
->method('validate')
->willReturn(false);
$this->request->expects($this->once())
->method('isPost')
->willReturn(false);
$this->messageManager->expects($this->once())
->method('addErrorMessage')
->with('Can\'t unhold order.');
$this->resultRedirect->expects($this->once())
->method('setPath')
->with('sales/*/')
->willReturnSelf();
$this->assertEquals($this->resultRedirect, $this->controller->execute());
}
}