Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UnholdTest.php
Go to the documentation of this file.
1 <?php
8 
11 
17 class UnholdTest extends \PHPUnit\Framework\TestCase
18 {
22  protected $controller;
23 
27  protected $context;
28 
32  protected $resultRedirect;
33 
37  protected $request;
38 
42  protected $response;
43 
47  protected $messageManager;
48 
53 
57  protected $validatorMock;
58 
62  protected $objectManager;
63 
67  protected function setUp()
68  {
69  $objectManagerHelper = new ObjectManagerHelper($this);
70  $this->context = $this->createMock(\Magento\Backend\App\Action\Context::class);
71  $resultRedirectFactory = $this->createPartialMock(
72  \Magento\Backend\Model\View\Result\RedirectFactory::class,
73  ['create']
74  );
75  $this->response = $this->createPartialMock(
76  \Magento\Framework\App\ResponseInterface::class,
77  ['setRedirect', 'sendResponse']
78  );
79  $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
80  ->disableOriginalConstructor()->getMock();
81  $this->messageManager = $this->createPartialMock(
82  \Magento\Framework\Message\Manager::class,
83  ['addSuccessMessage', 'addErrorMessage']
84  );
85  $this->orderRepositoryMock = $this->getMockBuilder(\Magento\Sales\Api\OrderRepositoryInterface::class)
86  ->disableOriginalConstructor()
87  ->getMock();
88 
89  $this->validatorMock = $this->getMockBuilder(\Magento\Framework\Data\Form\FormKey\Validator::class)
90  ->disableOriginalConstructor()
91  ->getMock();
92 
93  $this->resultRedirect = $this->createMock(\Magento\Backend\Model\View\Result\Redirect::class);
94  $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
95 
96  $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager);
97  $this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
98  $this->context->expects($this->once())->method('getResponse')->willReturn($this->response);
99  $this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager);
100  $this->context->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory);
101  $this->context->expects($this->once())->method('getFormKeyValidator')->willReturn($this->validatorMock);
102 
103  $this->controller = $objectManagerHelper->getObject(
104  \Magento\Sales\Controller\Adminhtml\Order\Unhold::class,
105  [
106  'context' => $this->context,
107  'request' => $this->request,
108  'response' => $this->response,
109  'orderRepository' => $this->orderRepositoryMock
110  ]
111  );
112  }
113 
117  public function testExecuteNotPost()
118  {
119  $this->validatorMock->expects($this->once())
120  ->method('validate')
121  ->willReturn(false);
122  $this->request->expects($this->once())
123  ->method('isPost')
124  ->willReturn(false);
125  $this->messageManager->expects($this->once())
126  ->method('addErrorMessage')
127  ->with('Can\'t unhold order.');
128  $this->resultRedirect->expects($this->once())
129  ->method('setPath')
130  ->with('sales/*/')
131  ->willReturnSelf();
132 
133  $this->assertEquals($this->resultRedirect, $this->controller->execute());
134  }
135 }