@@ -30,21 +30,11 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
30
30
*/
31
31
protected $ responseMock ;
32
32
33
- /**
34
- * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
35
- */
36
- protected $ titleMock ;
37
-
38
33
/**
39
34
* @var \PHPUnit_Framework_MockObject_MockObject
40
35
*/
41
36
protected $ resultPageMock ;
42
37
43
- /**
44
- * @var \PHPUnit_Framework_MockObject_MockObject
45
- */
46
- protected $ pageConfigMock ;
47
-
48
38
/**
49
39
* @var \Magento\Sales\Model\Order\Shipment|\PHPUnit_Framework_MockObject_MockObject
50
40
*/
@@ -55,6 +45,11 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
55
45
*/
56
46
protected $ viewInterfaceMock ;
57
47
48
+ /**
49
+ * @var \Magento\Framework\View\Result\LayoutFactory|\PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ protected $ resultLayoutFactoryMock ;
52
+
58
53
/**
59
54
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60
55
*/
@@ -95,9 +90,9 @@ protected function setUp()
95
90
'' ,
96
91
false
97
92
);
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 ' ],
101
96
[],
102
97
'' ,
103
98
false
@@ -106,9 +101,6 @@ protected function setUp()
106
101
$ this ->resultPageMock = $ this ->getMockBuilder ('Magento\Framework\View\Result\Page ' )
107
102
->disableOriginalConstructor ()
108
103
->getMock ();
109
- $ this ->pageConfigMock = $ this ->getMockBuilder ('Magento\Framework\View\Page\Config ' )
110
- ->disableOriginalConstructor ()
111
- ->getMock ();
112
104
113
105
$ this ->shipmentMock = $ this ->getMock (
114
106
'Magento\Sales\Model\Order\Shipment ' ,
@@ -136,15 +128,9 @@ protected function setUp()
136
128
$ this ->viewInterfaceMock ->expects ($ this ->any ())->method ('getPage ' )->will (
137
129
$ this ->returnValue ($ this ->resultPageMock )
138
130
);
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 ));
144
131
145
132
$ contextMock ->expects ($ this ->any ())->method ('getRequest ' )->will ($ this ->returnValue ($ this ->requestMock ));
146
133
$ contextMock ->expects ($ this ->any ())->method ('getResponse ' )->will ($ this ->returnValue ($ this ->responseMock ));
147
- $ contextMock ->expects ($ this ->any ())->method ('getTitle ' )->will ($ this ->returnValue ($ this ->titleMock ));
148
134
$ contextMock ->expects ($ this ->any ())->method ('getView ' )->will ($ this ->returnValue ($ this ->viewInterfaceMock ));
149
135
$ contextMock ->expects ($ this ->any ())
150
136
->method ('getObjectManager ' )
@@ -153,7 +139,8 @@ protected function setUp()
153
139
$ this ->controller = new \Magento \Shipping \Controller \Adminhtml \Order \Shipment \AddComment (
154
140
$ contextMock ,
155
141
$ this ->shipmentLoaderMock ,
156
- $ this ->shipmentSenderMock
142
+ $ this ->shipmentSenderMock ,
143
+ $ this ->resultLayoutFactoryMock
157
144
);
158
145
}
159
146
@@ -189,15 +176,19 @@ public function testExecute()
189
176
$ shipment = [];
190
177
$ tracking = [];
191
178
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
+ );
194
186
195
187
$ this ->requestMock ->expects ($ this ->once ())->method ('setParam ' )->with ('shipment_id ' , $ shipmentId );
196
188
$ this ->requestMock ->expects ($ this ->once ())
197
189
->method ('getPost ' )
198
190
->with ('comment ' )
199
191
->will ($ this ->returnValue ($ data ));
200
- $ this ->titleMock ->expects ($ this ->once ())->method ('prepend ' );
201
192
$ this ->requestMock ->expects ($ this ->any ())
202
193
->method ('getParam ' )
203
194
->will (
@@ -221,10 +212,15 @@ public function testExecute()
221
212
$ this ->shipmentMock ->expects ($ this ->once ())->method ('addComment ' );
222
213
$ this ->shipmentSenderMock ->expects ($ this ->once ())->method ('send ' );
223
214
$ 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 ));
228
224
$ this ->responseMock ->expects ($ this ->once ())->method ('setBody ' )->with ($ result );
229
225
230
226
$ this ->assertNull ($ this ->controller ->execute ());
0 commit comments