@@ -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