Skip to content

Commit e33293d

Browse files
author
vpaladiychuk
committed
MAGETWO-32554: Refactor Adminhtml/order/invoice directory
1 parent 7207f4c commit e33293d

File tree

5 files changed

+111
-18
lines changed

5 files changed

+111
-18
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public function __construct(
2929
Registry $registry,
3030
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
3131
RedirectFactory $resultRedirectFactory
32-
)
33-
{
32+
) {
3433
$this->resultRedirectFactory = $resultRedirectFactory;
3534
parent::__construct($context, $registry, $resultForwardFactory);
3635
}

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public function __construct(
2929
Registry $registry,
3030
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
3131
PageFactory $resultPageFactory
32-
)
33-
{
32+
) {
3433
$this->resultPageFactory = $resultPageFactory;
3534
parent::__construct($context, $registry, $resultForwardFactory);
3635
}

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Sales\Controller\Adminhtml\Order\Invoice;
88

99
use Magento\Framework\Model\Exception;
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\Registry;
1012

1113
class Void extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
1214
{

dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/ViewTest.php

100644100755
Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ViewTest extends \PHPUnit_Framework_TestCase
5555
protected $objectManagerMock;
5656

5757
/**
58-
* @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
58+
* @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
5959
*/
6060
protected $resultPageMock;
6161

@@ -74,6 +74,16 @@ class ViewTest extends \PHPUnit_Framework_TestCase
7474
*/
7575
protected $controller;
7676

77+
/**
78+
* @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
79+
*/
80+
protected $resultPageFactoryMock;
81+
82+
/**
83+
* @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject
84+
*/
85+
protected $resultForwardFactoryMock;
86+
7787
public function setUp()
7888
{
7989
$objectManager = new ObjectManager($this);
@@ -103,7 +113,7 @@ public function setUp()
103113
->setMethods(['getCommentText', 'setIsUrlNotice'])
104114
->getMock();
105115
$this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
106-
$this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
116+
$this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page')
107117
->disableOriginalConstructor()
108118
->getMock();
109119
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
@@ -148,10 +158,22 @@ public function setUp()
148158
->method('getTitle')
149159
->willReturn($this->pageTitleMock);
150160

161+
$this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
162+
->disableOriginalConstructor()
163+
->setMethods([])
164+
->getMock();
165+
166+
$this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory')
167+
->disableOriginalConstructor()
168+
->setMethods([])
169+
->getMock();
170+
151171
$this->controller = $objectManager->getObject(
152172
'Magento\Sales\Controller\Adminhtml\Order\Invoice\View',
153173
[
154-
'context' => $contextMock
174+
'context' => $contextMock,
175+
'resultPageFactory' => $this->resultPageFactoryMock,
176+
'resultForwardFactory' => $this->resultForwardFactoryMock
155177
]
156178
);
157179
}
@@ -191,15 +213,11 @@ public function testExecute()
191213
->setMethods([])
192214
->getMock();
193215
$layoutMock->expects($this->at(0))
194-
->method('getBlock')
195-
->with('menu')
196-
->will($this->returnValue($menuBlockMock));
197-
$layoutMock->expects($this->at(1))
198216
->method('getBlock')
199217
->with('sales_invoice_view')
200218
->will($this->returnValue($invoiceViewBlockMock));
201219

202-
$this->viewMock->expects($this->any())
220+
$this->resultPageMock->expects($this->any())
203221
->method('getLayout')
204222
->will($this->returnValue($layoutMock));
205223

@@ -216,7 +234,13 @@ public function testExecute()
216234
->with('Magento\Sales\Model\Order\Invoice')
217235
->willReturn($invoiceMock);
218236

219-
$this->assertNull($this->controller->execute());
237+
$this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order');
238+
239+
$this->resultPageFactoryMock->expects($this->once())
240+
->method('create')
241+
->will($this->returnValue($this->resultPageMock));
242+
243+
$this->assertSame($this->resultPageMock, $this->controller->execute());
220244
}
221245

222246
public function testExecuteNoInvoice()
@@ -240,6 +264,16 @@ public function testExecuteNoInvoice()
240264
->with('Magento\Sales\Model\Order\Invoice')
241265
->willReturn($invoiceMock);
242266

243-
$this->assertNull($this->controller->execute());
267+
$resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward')
268+
->disableOriginalConstructor()
269+
->setMethods([])
270+
->getMock();
271+
$resultForward->expects($this->once())->method('forward')->with(('noroute'))->will($this->returnSelf());
272+
273+
$this->resultForwardFactoryMock->expects($this->once())
274+
->method('create')
275+
->will($this->returnValue($resultForward));
276+
277+
$this->assertSame($resultForward, $this->controller->execute());
244278
}
245279
}

dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/VoidTest.php

100644100755
Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ class VoidTest extends \PHPUnit_Framework_TestCase
5959
*/
6060
protected $controller;
6161

62+
/**
63+
* @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject
64+
*/
65+
protected $resultRedirectFactoryMock;
66+
67+
/**
68+
* @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject
69+
*/
70+
protected $resultForwardFactoryMock;
71+
6272
public function setUp()
6373
{
6474
$objectManager = new ObjectManager($this);
@@ -128,10 +138,22 @@ public function setUp()
128138
->method('getHelper')
129139
->will($this->returnValue($this->helperMock));
130140

141+
$this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory')
142+
->disableOriginalConstructor()
143+
->setMethods([])
144+
->getMock();
145+
146+
$this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory')
147+
->disableOriginalConstructor()
148+
->setMethods([])
149+
->getMock();
150+
131151
$this->controller = $objectManager->getObject(
132152
'Magento\Sales\Controller\Adminhtml\Order\Invoice\Void',
133153
[
134-
'context' => $contextMock
154+
'context' => $contextMock,
155+
'resultRedirectFactory' => $this->resultRedirectFactoryMock,
156+
'resultForwardFactory' => $this->resultForwardFactoryMock
135157
]
136158
);
137159
}
@@ -163,6 +185,9 @@ public function testExecute()
163185
$invoiceMock->expects($this->any())
164186
->method('getOrder')
165187
->will($this->returnValue($orderMock));
188+
$invoiceMock->expects($this->once())
189+
->method('getId')
190+
->will($this->returnValue($invoiceId));
166191

167192
$transactionMock = $this->getMockBuilder('Magento\Framework\DB\Transaction')
168193
->disableOriginalConstructor()
@@ -192,7 +217,17 @@ public function testExecute()
192217
->method('addSuccess')
193218
->with('The invoice has been voided.');
194219

195-
$this->controller->execute();
220+
$resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect')
221+
->disableOriginalConstructor()
222+
->setMethods([])
223+
->getMock();
224+
$resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]);
225+
226+
$this->resultRedirectFactoryMock->expects($this->once())
227+
->method('create')
228+
->will($this->returnValue($resultRedirect));
229+
230+
$this->assertSame($resultRedirect, $this->controller->execute());
196231
}
197232

198233
public function testExecuteNoInvoice()
@@ -222,7 +257,17 @@ public function testExecuteNoInvoice()
222257
$this->messageManagerMock->expects($this->never())
223258
->method('addSuccess');
224259

225-
$this->controller->execute();
260+
$resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward')
261+
->disableOriginalConstructor()
262+
->setMethods([])
263+
->getMock();
264+
$resultForward->expects($this->once())->method('forward')->with(('noroute'))->will($this->returnSelf());
265+
266+
$this->resultForwardFactoryMock->expects($this->once())
267+
->method('create')
268+
->will($this->returnValue($resultForward));
269+
270+
$this->assertSame($resultForward, $this->controller->execute());
226271
}
227272

228273
public function testExecuteModelException()
@@ -247,6 +292,9 @@ public function testExecuteModelException()
247292
$invoiceMock->expects($this->once())
248293
->method('void')
249294
->will($this->throwException($e));
295+
$invoiceMock->expects($this->once())
296+
->method('getId')
297+
->will($this->returnValue($invoiceId));
250298

251299
$this->objectManagerMock->expects($this->once())
252300
->method('create')
@@ -255,6 +303,17 @@ public function testExecuteModelException()
255303

256304
$this->messageManagerMock->expects($this->once())
257305
->method('addError');
258-
$this->controller->execute();
306+
307+
$resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect')
308+
->disableOriginalConstructor()
309+
->setMethods([])
310+
->getMock();
311+
$resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]);
312+
313+
$this->resultRedirectFactoryMock->expects($this->once())
314+
->method('create')
315+
->will($this->returnValue($resultRedirect));
316+
317+
$this->assertSame($resultRedirect, $this->controller->execute());
259318
}
260319
}

0 commit comments

Comments
 (0)