13
13
use Magento \Backend \Model \View \Result \Forward ;
14
14
use Magento \Backend \Model \View \Result \ForwardFactory ;
15
15
use Magento \Backend \Model \View \Result \Page ;
16
+ use Magento \Backend \Model \View \Result \Redirect ;
17
+ use Magento \Backend \Model \View \Result \RedirectFactory ;
16
18
use Magento \Framework \App \ActionFlag ;
17
19
use Magento \Framework \App \Request \Http ;
18
20
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
@@ -82,6 +84,17 @@ class ViewTest extends TestCase
82
84
*/
83
85
protected $ pageTitleMock ;
84
86
87
+ /**
88
+ * @var \Magento\Sales\Controller\Adminhtml\Order\Invoice\View
89
+ * @var RedirectFactory|MockObject
90
+ */
91
+ protected $ resultRedirectFactoryMock ;
92
+
93
+ /**
94
+ * @var Redirect|MockObject
95
+ */
96
+ protected $ resultRedirectMock ;
97
+
85
98
/**
86
99
* @var View
87
100
*/
@@ -194,6 +207,13 @@ protected function setUp(): void
194
207
)->disableOriginalConstructor ()
195
208
->setMethods (['create ' ])
196
209
->getMock ();
210
+ $ this ->resultRedirectFactoryMock = $ this ->getMockBuilder (RedirectFactory::class)
211
+ ->disableOriginalConstructor ()
212
+ ->setMethods (['create ' ])
213
+ ->getMock ();
214
+ $ this ->resultRedirectMock = $ this ->getMockBuilder (Redirect::class)
215
+ ->disableOriginalConstructor ()
216
+ ->getMock ();
197
217
$ this ->invoiceRepository = $ this ->getMockBuilder (InvoiceRepositoryInterface::class)
198
218
->disableOriginalConstructor ()
199
219
->getMockForAbstractClass ();
@@ -203,7 +223,8 @@ protected function setUp(): void
203
223
[
204
224
'context ' => $ contextMock ,
205
225
'resultPageFactory ' => $ this ->resultPageFactoryMock ,
206
- 'resultForwardFactory ' => $ this ->resultForwardFactoryMock
226
+ 'resultForwardFactory ' => $ this ->resultForwardFactoryMock ,
227
+ 'resultRedirectFactory ' => $ this ->resultRedirectFactoryMock
207
228
]
208
229
);
209
230
@@ -287,16 +308,32 @@ public function testExecuteNoInvoice()
287
308
->method ('get ' )
288
309
->willReturn (null );
289
310
290
- $ resultForward = $ this ->getMockBuilder (Forward::class)
291
- ->disableOriginalConstructor ()
292
- ->setMethods ([])
293
- ->getMock ();
294
- $ resultForward ->expects ($ this ->once ())->method ('forward ' )->with (('noroute ' ))->willReturnSelf ();
311
+ $ this ->prepareRedirect ();
312
+ $ this ->setPath ('sales/invoice ' );
313
+ $ this ->assertInstanceOf (
314
+ Redirect::class,
315
+ $ this ->controller ->execute ()
316
+ );
317
+ }
295
318
296
- $ this ->resultForwardFactoryMock ->expects ($ this ->once ())
319
+ /**
320
+ * prepareRedirect
321
+ */
322
+ protected function prepareRedirect ()
323
+ {
324
+ $ this ->resultRedirectFactoryMock ->expects ($ this ->once ())
297
325
->method ('create ' )
298
- ->willReturn ($ resultForward );
326
+ ->willReturn ($ this ->resultRedirectMock );
327
+ }
299
328
300
- $ this ->assertSame ($ resultForward , $ this ->controller ->execute ());
329
+ /**
330
+ * @param string $path
331
+ * @param array $params
332
+ */
333
+ protected function setPath ($ path , $ params = [])
334
+ {
335
+ $ this ->resultRedirectMock ->expects ($ this ->once ())
336
+ ->method ('setPath ' )
337
+ ->with ($ path , $ params );
301
338
}
302
339
}
0 commit comments