87 $this->titleMock = $this->getMockBuilder(\
Magento\Framework\View\Page\Title::class)
88 ->disableOriginalConstructor()
90 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
91 ->disableOriginalConstructor()
94 $this->responseMock = $this->getMockBuilder(\
Magento\Framework\
App\
Response\Http::class)
95 ->disableOriginalConstructor()
97 $this->resultPageMock = $this->getMockBuilder(\
Magento\Backend\Model\View\Result\Page::class)
99 ->disableOriginalConstructor()
101 $this->pageConfigMock = $this->getMockBuilder(\
Magento\Framework\View\Page\Config::class)
102 ->disableOriginalConstructor()
105 $this->viewMock = $this->getMockBuilder(\
Magento\Framework\
App\ViewInterface::class)
106 ->disableOriginalConstructor()
109 $this->viewMock->expects($this->any())->method(
'loadLayout')->will($this->returnSelf());
111 $this->objectManagerMock = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
113 $this->pageConfigMock->expects($this->any())->method(
'getTitle')->will($this->returnValue($this->titleMock));
115 $this->objectManagerMock = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)
116 ->disableOriginalConstructor()
119 $contextMock = $this->getMockBuilder(\
Magento\Backend\
App\
Action\Context::class)
120 ->disableOriginalConstructor()
131 'getResultRedirectFactory',
136 $contextMock->expects($this->any())
137 ->method(
'getRequest')
138 ->will($this->returnValue($this->requestMock));
139 $contextMock->expects($this->any())
140 ->method(
'getResponse')
141 ->will($this->returnValue($this->responseMock));
142 $contextMock->expects($this->any())
144 ->will($this->returnValue($this->titleMock));
145 $contextMock->expects($this->any())
147 ->will($this->returnValue($this->viewMock));
148 $contextMock->expects($this->any())
149 ->method(
'getObjectManager')
150 ->will($this->returnValue($this->objectManagerMock));
152 $this->resultPageFactoryMock = $this->getMockBuilder(\
Magento\Framework\View\Result\PageFactory::class)
153 ->disableOriginalConstructor()
154 ->setMethods([
'create'])
157 $this->resultRawFactoryMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\RawFactory::class)
158 ->disableOriginalConstructor()
159 ->setMethods([
'create'])
162 $this->resultJsonFactoryMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\JsonFactory::class)
163 ->disableOriginalConstructor()
164 ->setMethods([
'create'])
167 $this->invoiceServiceMock = $this->getMockBuilder(\
Magento\Sales\Model\Service\InvoiceService::class)
168 ->disableOriginalConstructor()
172 \
Magento\Sales\Controller\Adminhtml\Order\Invoice\UpdateQty::class,
174 'context' => $contextMock,
175 'resultPageFactory' => $this->resultPageFactoryMock,
176 'resultRawFactory' => $this->resultRawFactoryMock,
177 'resultJsonFactory' => $this->resultJsonFactoryMock,
178 'invoiceService' => $this->invoiceServiceMock
191 $invoiceData = [
'comment_text' =>
'test'];
194 $this->requestMock->expects($this->at(0))
197 ->will($this->returnValue($orderId));
198 $this->requestMock->expects($this->at(1))
200 ->with(
'invoice', [])
201 ->will($this->returnValue($invoiceData));
203 $invoiceMock = $this->getMockBuilder(\
Magento\Sales\Model\Order\Invoice::class)
204 ->disableOriginalConstructor()
207 $invoiceMock->expects($this->once())
208 ->method(
'getTotalQty')
211 $orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
212 ->disableOriginalConstructor()
213 ->setMethods([
'load',
'getId',
'canInvoice'])
215 $orderMock->expects($this->once())
219 $orderMock->expects($this->once())
221 ->willReturn($orderId);
222 $orderMock->expects($this->once())
223 ->method(
'canInvoice')
226 $this->invoiceServiceMock->expects($this->once())
227 ->method(
'prepareInvoice')
228 ->with($orderMock, [])
229 ->willReturn($invoiceMock);
231 $this->objectManagerMock->expects($this->at(0))
233 ->with(\
Magento\Sales\Model\Order::class)
234 ->willReturn($orderMock);
236 $blockItemMock = $this->getMockBuilder(\
Magento\Sales\Block\Order\Items::class)
237 ->disableOriginalConstructor()
240 $blockItemMock->expects($this->once())
244 $layoutMock = $this->getMockBuilder(\
Magento\Framework\View\Layout::class)
245 ->disableOriginalConstructor()
248 $layoutMock->expects($this->once())
250 ->with(
'order_items')
251 ->will($this->returnValue($blockItemMock));
253 $this->resultPageMock->expects($this->once())
254 ->method(
'getLayout')
255 ->will($this->returnValue($layoutMock));
256 $this->resultPageMock->expects($this->once())
257 ->method(
'getConfig')
258 ->will($this->returnValue($this->pageConfigMock));
260 $this->pageConfigMock->expects($this->once())->method(
'getTitle')->will($this->returnValue($this->titleMock));
262 $this->resultPageFactoryMock->expects($this->once())
264 ->will($this->returnValue($this->resultPageMock));
266 $resultRaw = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Raw::class)
267 ->disableOriginalConstructor()
270 $resultRaw->expects($this->once())->method(
'setContents')->with(
$response);
272 $this->resultRawFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($resultRaw));
274 $this->assertSame($resultRaw, $this->controller->execute());
282 public function testExecuteModelException()
284 $message =
'The order no longer exists.';
287 $orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
288 ->disableOriginalConstructor()
289 ->setMethods([
'load',
'getId',
'canInvoice'])
291 $orderMock->expects($this->once())
293 ->will($this->returnSelf());
294 $orderMock->expects($this->once())
297 $this->objectManagerMock->expects($this->at(0))
299 ->with(\
Magento\Sales\Model\Order::class)
300 ->willReturn($orderMock);
302 $this->titleMock->expects($this->never())
307 $resultJsonMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
308 ->disableOriginalConstructor()
311 $resultJsonMock->expects($this->once())->method(
'setData')->with(
$response);
313 $this->resultJsonFactoryMock->expects($this->once())
315 ->will($this->returnValue($resultJsonMock));
317 $this->assertSame($resultJsonMock, $this->controller->execute());
325 public function testExecuteException()
327 $message =
'The order no longer exists.';
330 $orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
331 ->disableOriginalConstructor()
332 ->setMethods([
'load',
'getId',
'canInvoice'])
334 $orderMock->expects($this->once())
336 ->will($this->returnSelf());
337 $orderMock->expects($this->once())
340 $this->objectManagerMock->expects($this->at(0))
342 ->with(\
Magento\Sales\Model\Order::class)
343 ->willReturn($orderMock);
345 $this->titleMock->expects($this->never())
350 $resultJsonMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
351 ->disableOriginalConstructor()
354 $resultJsonMock->expects($this->once())->method(
'setData')->with(
$response);
356 $this->resultJsonFactoryMock->expects($this->once())
358 ->will($this->returnValue($resultJsonMock));
360 $this->assertSame($resultJsonMock, $this->controller->execute());