@@ -32,11 +32,19 @@ class IndexTest extends \PHPUnit_Framework_TestCase
32
32
*/
33
33
protected $ forwardMock ;
34
34
35
+ /**
36
+ * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
37
+ */
38
+ protected $ resultPageMock ;
39
+
35
40
protected function setUp ()
36
41
{
37
42
$ helper = new \Magento \TestFramework \Helper \ObjectManager ($ this );
38
43
$ objectManagerMock = $ this ->getMock ('Magento\Framework\ObjectManagerInterface ' );
39
44
$ responseMock = $ this ->getMock ('Magento\Framework\App\Response\Http ' , [], [], '' , false );
45
+ $ this ->resultPageMock = $ this ->getMockBuilder ('\Magento\Framework\View\Result\Page ' )
46
+ ->disableOriginalConstructor ()
47
+ ->getMock ();
40
48
$ this ->forwardFactoryMock = $ this ->getMockBuilder ('Magento\Backend\Model\View\Result\ForwardFactory ' )
41
49
->setMethods (['create ' ])
42
50
->disableOriginalConstructor ()
@@ -47,26 +55,6 @@ protected function setUp()
47
55
$ this ->forwardFactoryMock ->expects ($ this ->any ())
48
56
->method ('create ' )
49
57
->willReturn ($ this ->forwardMock );
50
- $ this ->forwardMock ->expects (
51
- $ this ->at (0 )
52
- )->method (
53
- 'setHeader '
54
- )->with (
55
- 'HTTP/1.1 ' ,
56
- '404 Not Found '
57
- )->will (
58
- $ this ->returnSelf ()
59
- );
60
- $ this ->forwardMock ->expects (
61
- $ this ->at (1 )
62
- )->method (
63
- 'setHeader '
64
- )->with (
65
- 'Status ' ,
66
- '404 File not found '
67
- )->will (
68
- $ this ->returnSelf ()
69
- );
70
58
71
59
$ scopeConfigMock = $ this ->getMock ('Magento\Framework\App\Config\ScopeConfigInterface ' );
72
60
$ this ->_requestMock = $ this ->getMock ('Magento\Framework\App\Request\Http ' , [], [], '' , false );
@@ -97,25 +85,63 @@ protected function setUp()
97
85
);
98
86
}
99
87
100
- /**
101
- * @param bool $renderPage
102
- * @dataProvider indexActionDataProvider
103
- */
104
- public function testIndexAction ($ renderPage )
88
+ public function testExecuteResultPage ()
105
89
{
90
+ $ this ->resultPageMock ->expects (
91
+ $ this ->at (0 )
92
+ )->method (
93
+ 'setHeader '
94
+ )->with (
95
+ 'HTTP/1.1 ' , '404 Not Found '
96
+ )->will (
97
+ $ this ->returnSelf ()
98
+ );
99
+ $ this ->resultPageMock ->expects (
100
+ $ this ->at (1 )
101
+ )->method (
102
+ 'setHeader '
103
+ )->with (
104
+ 'Status ' , '404 File not found '
105
+ )->will (
106
+ $ this ->returnSelf ()
107
+ );
106
108
$ this ->_cmsHelperMock ->expects (
107
109
$ this ->once ()
108
110
)->method (
109
111
'prepareResultPage '
110
112
)->will (
111
- $ this ->returnValue ($ renderPage )
113
+ $ this ->returnValue ($ this -> resultPageMock )
112
114
);
113
- $ this ->_requestMock ->expects ($ this ->any ())->method ('setActionName ' )->with ('defaultNoRoute ' );
114
- $ this ->_controller ->execute ();
115
+ $ this ->assertInstanceOf ('Magento\Framework\View\Result\Page ' , $ this ->_controller ->execute ());
115
116
}
116
117
117
- public function indexActionDataProvider ()
118
+ public function testExecuteResultForward ()
118
119
{
119
- return ['renderPage_return_true ' => [true ], 'renderPage_return_false ' => [false ]];
120
+ $ this ->forwardMock ->expects (
121
+ $ this ->once ()
122
+ )->method (
123
+ 'setController '
124
+ )->with (
125
+ 'index '
126
+ )->will (
127
+ $ this ->returnSelf ()
128
+ );
129
+ $ this ->forwardMock ->expects (
130
+ $ this ->once ()
131
+ )->method (
132
+ 'forward '
133
+ )->with (
134
+ 'defaultNoRoute '
135
+ )->will (
136
+ $ this ->returnSelf ()
137
+ );
138
+ $ this ->_cmsHelperMock ->expects (
139
+ $ this ->once ()
140
+ )->method (
141
+ 'prepareResultPage '
142
+ )->will (
143
+ $ this ->returnValue (false )
144
+ );
145
+ $ this ->assertInstanceOf ('Magento\Backend\Model\View\Result\Forward ' , $ this ->_controller ->execute ());
120
146
}
121
147
}
0 commit comments