Skip to content

Commit 453f2df

Browse files
author
Dmytro Poperechnyy
committed
Merge remote-tracking branch 'tango/MAGETWO-31522' into MAGETWO-31522
2 parents 21a5dc9 + 7207f4c commit 453f2df

File tree

2 files changed

+126
-41
lines changed

2 files changed

+126
-41
lines changed

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

100644100755
Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class NewActionTest extends \PHPUnit_Framework_TestCase
4949
protected $sessionMock;
5050

5151
/**
52-
* @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
52+
* @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
5353
*/
5454
protected $resultPageMock;
5555

@@ -73,6 +73,17 @@ class NewActionTest extends \PHPUnit_Framework_TestCase
7373
*/
7474
protected $messageManagerMock;
7575

76+
/**
77+
* @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
78+
*/
79+
protected $resultPageFactoryMock;
80+
81+
/**
82+
* @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject
83+
*/
84+
protected $resultRedirectFactoryMock;
85+
86+
7687
public function setUp()
7788
{
7889
$objectManager = new ObjectManager($this);
@@ -112,8 +123,9 @@ public function setUp()
112123
->disableOriginalConstructor()
113124
->setMethods(['getCommentText', 'setIsUrlNotice'])
114125
->getMock();
115-
$this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
126+
$this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page')
116127
->disableOriginalConstructor()
128+
->setMethods([])
117129
->getMock();
118130
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
119131
->disableOriginalConstructor()
@@ -166,9 +178,23 @@ public function setUp()
166178
->method('getTitle')
167179
->willReturn($this->pageTitleMock);
168180

181+
$this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
182+
->disableOriginalConstructor()
183+
->setMethods([])
184+
->getMock();
185+
186+
$this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory')
187+
->disableOriginalConstructor()
188+
->setMethods([])
189+
->getMock();
190+
169191
$this->controller = $objectManager->getObject(
170192
'Magento\Sales\Controller\Adminhtml\Order\Invoice\NewAction',
171-
['context' => $contextMock]
193+
[
194+
'context' => $contextMock,
195+
'resultRedirectFactory' => $this->resultRedirectFactoryMock,
196+
'resultPageFactory' => $this->resultPageFactoryMock
197+
]
172198
);
173199
}
174200

@@ -230,19 +256,6 @@ public function testExecute()
230256
->with('Magento_Sales::sales_order')
231257
->will($this->returnValue([]));
232258

233-
$layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout')
234-
->disableOriginalConstructor()
235-
->setMethods([])
236-
->getMock();
237-
$layoutMock->expects($this->once())
238-
->method('getBlock')
239-
->with('menu')
240-
->will($this->returnValue($menuBlockMock));
241-
242-
$this->viewMock->expects($this->once())
243-
->method('getLayout')
244-
->will($this->returnValue($layoutMock));
245-
246259
$this->sessionMock->expects($this->once())
247260
->method('getCommentText')
248261
->with(true)
@@ -261,7 +274,12 @@ public function testExecute()
261274
->with('Magento\Backend\Model\Session')
262275
->will($this->returnValue($this->sessionMock));
263276

264-
$this->assertNull($this->controller->execute());
277+
$this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order');
278+
$this->resultPageFactoryMock->expects($this->once())
279+
->method('create')
280+
->will($this->returnValue($this->resultPageMock));
281+
282+
$this->assertSame($this->resultPageMock, $this->controller->execute());
265283
}
266284

267285
public function testExecuteNoOrder()
@@ -295,6 +313,16 @@ public function testExecuteNoOrder()
295313
->with('Magento\Sales\Model\Order')
296314
->willReturn($orderMock);
297315

298-
$this->assertNull($this->controller->execute());
316+
$resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect')
317+
->disableOriginalConstructor()
318+
->setMethods([])
319+
->getMock();
320+
$resultRedirect->expects($this->once())->method('setPath')->with('sales/order/view', ['order_id' => $orderId]);
321+
322+
$this->resultRedirectFactoryMock->expects($this->once())
323+
->method('create')
324+
->will($this->returnValue($resultRedirect));
325+
326+
$this->assertSame($resultRedirect, $this->controller->execute());
299327
}
300328
}

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

100644100755
Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ class UpdateQtyTest extends \PHPUnit_Framework_TestCase
5555
*/
5656
protected $controller;
5757

58+
/**
59+
* @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
protected $resultPageFactoryMock;
62+
63+
/**
64+
* @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject
65+
*/
66+
protected $resultRawFactoryMock;
67+
68+
/**
69+
* @var \Magento\Framework\Controller\Result\JSONFactory|\PHPUnit_Framework_MockObject_MockObject
70+
*/
71+
protected $resultJsonFactoryMock;
72+
5873
public function setUp()
5974
{
6075
$objectManager = new ObjectManager($this);
@@ -69,8 +84,8 @@ public function setUp()
6984
$this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http')
7085
->disableOriginalConstructor()
7186
->getMock();
72-
$this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
73-
->setMethods(['getConfig'])
87+
$this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page')
88+
->setMethods([])
7489
->disableOriginalConstructor()
7590
->getMock();
7691
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
@@ -110,10 +125,28 @@ public function setUp()
110125
->method('getObjectManager')
111126
->will($this->returnValue($this->objectManagerMock));
112127

128+
$this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
129+
->disableOriginalConstructor()
130+
->setMethods([])
131+
->getMock();
132+
133+
$this->resultRawFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\RawFactory')
134+
->disableOriginalConstructor()
135+
->setMethods([])
136+
->getMock();
137+
138+
$this->resultJsonFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSONFactory')
139+
->disableOriginalConstructor()
140+
->setMethods([])
141+
->getMock();
142+
113143
$this->controller = $objectManager->getObject(
114144
'Magento\Sales\Controller\Adminhtml\Order\Invoice\UpdateQty',
115145
[
116-
'context' => $contextMock
146+
'context' => $contextMock,
147+
'resultPageFactory' => $this->resultPageFactoryMock,
148+
'resultRawFactory' => $this->resultRawFactoryMock,
149+
'resultJsonFactory' => $this->resultJsonFactoryMock
117150
]
118151
);
119152
}
@@ -173,10 +206,6 @@ public function testExecute()
173206
->with('Magento\Sales\Model\Service\Order')
174207
->willReturn($orderService);
175208

176-
$this->responseMock->expects($this->once())
177-
->method('setBody')
178-
->with($response);
179-
180209
$blockItemMock = $this->getMockBuilder('Magento\Sales\Block\Order\Items')
181210
->disableOriginalConstructor()
182211
->setMethods([])
@@ -193,16 +222,29 @@ public function testExecute()
193222
->method('getBlock')
194223
->with('order_items')
195224
->will($this->returnValue($blockItemMock));
196-
$this->viewMock->expects($this->once())->method('getPage')->will($this->returnValue($this->resultPageMock));
197-
$this->viewMock->expects($this->once())
225+
226+
$this->resultPageMock->expects($this->once())
198227
->method('getLayout')
199228
->will($this->returnValue($layoutMock));
200-
$this->resultPageMock->expects($this->once())->method('getConfig')->will(
201-
$this->returnValue($this->pageConfigMock)
202-
);
229+
$this->resultPageMock->expects($this->once())
230+
->method('getConfig')
231+
->will($this->returnValue($this->pageConfigMock));
232+
203233
$this->pageConfigMock->expects($this->once())->method('getTitle')->will($this->returnValue($this->titleMock));
204234

205-
$this->assertNull($this->controller->execute());
235+
$this->resultPageFactoryMock->expects($this->once())
236+
->method('create')
237+
->will($this->returnValue($this->resultPageMock));
238+
239+
$resultRaw = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw')
240+
->disableOriginalConstructor()
241+
->setMethods([])
242+
->getMock();
243+
$resultRaw->expects($this->once())->method('setContents')->with($response);
244+
245+
$this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw));
246+
247+
$this->assertSame($resultRaw, $this->controller->execute());
206248
}
207249

208250
public function testExecuteModelException()
@@ -229,10 +271,6 @@ public function testExecuteModelException()
229271
->method('prepend')
230272
->with('Invoices');
231273

232-
$this->responseMock->expects($this->once())
233-
->method('representJson')
234-
->with(json_encode($response));
235-
236274
$helperMock = $this->getMockBuilder('Magento\Core\Helper\Data')
237275
->disableOriginalConstructor()
238276
->setMethods([])
@@ -247,7 +285,18 @@ public function testExecuteModelException()
247285
->with('Magento\Core\Helper\Data')
248286
->will($this->returnValue($helperMock));
249287

250-
$this->assertNull($this->controller->execute());
288+
/** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */
289+
$resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON')
290+
->disableOriginalConstructor()
291+
->setMethods([])
292+
->getMock();
293+
$resultJsonMock->expects($this->once())->method('setJsonData')->with(json_encode($response));
294+
295+
$this->resultJsonFactoryMock->expects($this->once())
296+
->method('create')
297+
->will($this->returnValue($resultJsonMock));
298+
299+
$this->assertSame($resultJsonMock, $this->controller->execute());
251300
}
252301

253302
public function testExecuteException()
@@ -269,14 +318,11 @@ public function testExecuteException()
269318
->method('create')
270319
->with('Magento\Sales\Model\Order')
271320
->willReturn($orderMock);
321+
272322
$this->titleMock->expects($this->never())
273323
->method('prepend')
274324
->with('Invoices');
275325

276-
$this->responseMock->expects($this->once())
277-
->method('representJson')
278-
->with(json_encode($response));
279-
280326
$helperMock = $this->getMockBuilder('Magento\Core\Helper\Data')
281327
->disableOriginalConstructor()
282328
->setMethods([])
@@ -291,6 +337,17 @@ public function testExecuteException()
291337
->with('Magento\Core\Helper\Data')
292338
->will($this->returnValue($helperMock));
293339

294-
$this->assertNull($this->controller->execute());
340+
/** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */
341+
$resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON')
342+
->disableOriginalConstructor()
343+
->setMethods([])
344+
->getMock();
345+
$resultJsonMock->expects($this->once())->method('setJsonData')->with(json_encode($response));
346+
347+
$this->resultJsonFactoryMock->expects($this->once())
348+
->method('create')
349+
->will($this->returnValue($resultJsonMock));
350+
351+
$this->assertSame($resultJsonMock, $this->controller->execute());
295352
}
296353
}

0 commit comments

Comments
 (0)