Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NorouteTest.php
Go to the documentation of this file.
1 <?php
7 
8 class NorouteTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_controller;
14 
18  protected $_requestMock;
19 
23  protected $_viewMock;
24 
28  protected $_statusMock;
29 
30  protected function setUp()
31  {
32  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33  $this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
34  $this->_viewMock = $this->createMock(\Magento\Framework\App\ViewInterface::class);
35  $this->_statusMock =
36  $this->createPartialMock(\Magento\Framework\DataObject::class, ['getLoaded', 'getForwarded']);
37  $this->_controller = $helper->getObject(
38  \Magento\Framework\Controller\Noroute\Index::class,
39  ['request' => $this->_requestMock, 'view' => $this->_viewMock]
40  );
41  }
42 
44  {
45  $this->_requestMock->expects(
46  $this->once()
47  )->method(
48  'getParam'
49  )->with(
50  '__status__'
51  )->will(
52  $this->returnValue($this->_statusMock)
53  );
54  $this->_statusMock->expects($this->any())->method('getLoaded')->will($this->returnValue(false));
55  $this->_viewMock->expects($this->once())->method('loadLayout')->with(['default', 'noroute']);
56  $this->_viewMock->expects($this->once())->method('renderLayout');
57  $this->_controller->execute();
58  }
59 
61  {
62  $this->_requestMock->expects(
63  $this->once()
64  )->method(
65  'getParam'
66  )->with(
67  '__status__'
68  )->will(
69  $this->returnValue($this->_statusMock)
70  );
71  $this->_statusMock->expects($this->any())->method('getLoaded')->will($this->returnValue(true));
72  $this->_statusMock->expects($this->any())->method('getForwarded')->will($this->returnValue(false));
73  $this->_viewMock->expects($this->never())->method('loadLayout');
74  $this->_requestMock->expects(
75  $this->once()
76  )->method(
77  'setActionName'
78  )->will(
79  $this->returnValue($this->_requestMock)
80  );
81  $this->_controller->execute();
82  }
83 
85  {
86  $this->_requestMock->expects(
87  $this->once()
88  )->method(
89  'getParam'
90  )->with(
91  '__status__'
92  )->will(
93  $this->returnValue('string')
94  );
95  $this->_controller->execute();
96  }
97 }
$helper
Definition: iframe.phtml:13