Skip to content

Commit 2d689e2

Browse files
author
Evgeniy Miskov
committed
MAGETWO-33059: Refactor CMS module
1 parent 9317114 commit 2d689e2

File tree

1 file changed

+56
-30
lines changed
  • dev/tests/unit/testsuite/Magento/Cms/Controller/Noroute

1 file changed

+56
-30
lines changed

dev/tests/unit/testsuite/Magento/Cms/Controller/Noroute/IndexTest.php

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ class IndexTest extends \PHPUnit_Framework_TestCase
3232
*/
3333
protected $forwardMock;
3434

35+
/**
36+
* @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $resultPageMock;
39+
3540
protected function setUp()
3641
{
3742
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
3843
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
3944
$responseMock = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
45+
$this->resultPageMock = $this->getMockBuilder('\Magento\Framework\View\Result\Page')
46+
->disableOriginalConstructor()
47+
->getMock();
4048
$this->forwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory')
4149
->setMethods(['create'])
4250
->disableOriginalConstructor()
@@ -47,26 +55,6 @@ protected function setUp()
4755
$this->forwardFactoryMock->expects($this->any())
4856
->method('create')
4957
->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-
);
7058

7159
$scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
7260
$this->_requestMock = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false);
@@ -97,25 +85,63 @@ protected function setUp()
9785
);
9886
}
9987

100-
/**
101-
* @param bool $renderPage
102-
* @dataProvider indexActionDataProvider
103-
*/
104-
public function testIndexAction($renderPage)
88+
public function testExecuteResultPage()
10589
{
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+
);
106108
$this->_cmsHelperMock->expects(
107109
$this->once()
108110
)->method(
109111
'prepareResultPage'
110112
)->will(
111-
$this->returnValue($renderPage)
113+
$this->returnValue($this->resultPageMock)
112114
);
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());
115116
}
116117

117-
public function indexActionDataProvider()
118+
public function testExecuteResultForward()
118119
{
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());
120146
}
121147
}

0 commit comments

Comments
 (0)