Skip to content

Commit 08b6497

Browse files
committed
Merge pull request #190 from magento-mpi/MAGETWO-35385
[MPI] Bug fix
2 parents 7f98433 + 1550d51 commit 08b6497

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/AddComment.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Sales\Model\Order\Email\Sender\ShipmentSender;
1010
use Magento\Backend\App\Action;
11+
use Magento\Framework\View\Result\LayoutFactory;
1112

1213
class AddComment extends \Magento\Backend\App\Action
1314
{
@@ -21,18 +22,26 @@ class AddComment extends \Magento\Backend\App\Action
2122
*/
2223
protected $shipmentSender;
2324

25+
/**
26+
* @var LayoutFactory
27+
*/
28+
protected $resultLayoutFactory;
29+
2430
/**
2531
* @param Action\Context $context
2632
* @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
2733
* @param ShipmentSender $shipmentSender
34+
* @param LayoutFactory $resultLayoutFactory
2835
*/
2936
public function __construct(
3037
Action\Context $context,
3138
\Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader,
32-
ShipmentSender $shipmentSender
39+
ShipmentSender $shipmentSender,
40+
LayoutFactory $resultLayoutFactory
3341
) {
3442
$this->shipmentLoader = $shipmentLoader;
3543
$this->shipmentSender = $shipmentSender;
44+
$this->resultLayoutFactory = $resultLayoutFactory;
3645
parent::__construct($context);
3746
}
3847

@@ -72,10 +81,9 @@ public function execute()
7281

7382
$this->shipmentSender->send($shipment, !empty($data['is_customer_notified']), $data['comment']);
7483
$shipment->save();
75-
76-
$this->_view->loadLayout(false);
77-
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
78-
$response = $this->_view->getLayout()->getBlock('shipment_comments')->toHtml();
84+
$resultLayout = $this->resultLayoutFactory->create();
85+
$resultLayout->addDefaultHandle();
86+
$response = $resultLayout->getLayout()->getBlock('shipment_comments')->toHtml();
7987
} catch (\Magento\Framework\Exception\LocalizedException $e) {
8088
$response = ['error' => true, 'message' => $e->getMessage()];
8189
} catch (\Exception $e) {

app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/AddCommentTest.php

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,11 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
3030
*/
3131
protected $responseMock;
3232

33-
/**
34-
* @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
35-
*/
36-
protected $titleMock;
37-
3833
/**
3934
* @var \PHPUnit_Framework_MockObject_MockObject
4035
*/
4136
protected $resultPageMock;
4237

43-
/**
44-
* @var \PHPUnit_Framework_MockObject_MockObject
45-
*/
46-
protected $pageConfigMock;
47-
4838
/**
4939
* @var \Magento\Sales\Model\Order\Shipment|\PHPUnit_Framework_MockObject_MockObject
5040
*/
@@ -55,6 +45,11 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
5545
*/
5646
protected $viewInterfaceMock;
5747

48+
/**
49+
* @var \Magento\Framework\View\Result\LayoutFactory|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
protected $resultLayoutFactoryMock;
52+
5853
/**
5954
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
6055
*/
@@ -95,9 +90,9 @@ protected function setUp()
9590
'',
9691
false
9792
);
98-
$this->titleMock = $this->getMock(
99-
'Magento\Framework\View\Page\Title',
100-
['prepend', '__wakeup'],
93+
$this->resultLayoutFactoryMock = $this->getMock(
94+
'Magento\Framework\View\Result\LayoutFactory',
95+
['create'],
10196
[],
10297
'',
10398
false
@@ -106,9 +101,6 @@ protected function setUp()
106101
$this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
107102
->disableOriginalConstructor()
108103
->getMock();
109-
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
110-
->disableOriginalConstructor()
111-
->getMock();
112104

113105
$this->shipmentMock = $this->getMock(
114106
'Magento\Sales\Model\Order\Shipment',
@@ -136,15 +128,9 @@ protected function setUp()
136128
$this->viewInterfaceMock->expects($this->any())->method('getPage')->will(
137129
$this->returnValue($this->resultPageMock)
138130
);
139-
$this->resultPageMock->expects($this->any())->method('getConfig')->will(
140-
$this->returnValue($this->pageConfigMock)
141-
);
142-
143-
$this->pageConfigMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock));
144131

145132
$contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
146133
$contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
147-
$contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock));
148134
$contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewInterfaceMock));
149135
$contextMock->expects($this->any())
150136
->method('getObjectManager')
@@ -153,7 +139,8 @@ protected function setUp()
153139
$this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\AddComment(
154140
$contextMock,
155141
$this->shipmentLoaderMock,
156-
$this->shipmentSenderMock
142+
$this->shipmentSenderMock,
143+
$this->resultLayoutFactoryMock
157144
);
158145
}
159146

@@ -189,15 +176,19 @@ public function testExecute()
189176
$shipment = [];
190177
$tracking = [];
191178

192-
$layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock'], [], '', false);
193-
$blockMock = $this->getMock('Magento\Shipping\Block\Adminhtml\View\Comments', ['toHtml'], [], '', false);
179+
$resultLayoutMock = $this->getMock(
180+
'Magento\Framework\View\Result\Layout',
181+
['getBlock', 'getDefaultLayoutHandle', 'addDefaultHandle', 'getLayout'],
182+
[],
183+
'',
184+
false
185+
);
194186

195187
$this->requestMock->expects($this->once())->method('setParam')->with('shipment_id', $shipmentId);
196188
$this->requestMock->expects($this->once())
197189
->method('getPost')
198190
->with('comment')
199191
->will($this->returnValue($data));
200-
$this->titleMock->expects($this->once())->method('prepend');
201192
$this->requestMock->expects($this->any())
202193
->method('getParam')
203194
->will(
@@ -221,10 +212,15 @@ public function testExecute()
221212
$this->shipmentMock->expects($this->once())->method('addComment');
222213
$this->shipmentSenderMock->expects($this->once())->method('send');
223214
$this->shipmentMock->expects($this->once())->method('save');
224-
$this->viewInterfaceMock->expects($this->once())->method('loadLayout')->with(false);
225-
$this->viewInterfaceMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
226-
$layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($blockMock));
227-
$blockMock->expects($this->once())->method('toHtml')->will($this->returnValue($result));
215+
$layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock'], [], '', false);
216+
$blockMock = $this->getMock('Magento\Shipping\Block\Adminhtml\View\Comments', ['toHtml'], [], '', false);
217+
$blockMock->expects($this->once())->method('toHtml')->willReturn($result);
218+
$layoutMock->expects($this->once())->method('getBlock')
219+
->with('shipment_comments')->willReturn($blockMock);
220+
$resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
221+
$resultLayoutMock->expects($this->once())->method('addDefaultHandle');
222+
$this->resultLayoutFactoryMock->expects($this->once())->method('create')
223+
->will($this->returnValue($resultLayoutMock));
228224
$this->responseMock->expects($this->once())->method('setBody')->with($result);
229225

230226
$this->assertNull($this->controller->execute());

0 commit comments

Comments
 (0)