Skip to content

Commit 084fc7a

Browse files
author
Evgeniy Miskov
committed
MAGETWO-33059: Refactor CMS module
1 parent b645fe5 commit 084fc7a

File tree

3 files changed

+66
-28
lines changed

3 files changed

+66
-28
lines changed

app/code/Magento/Cms/Controller/Noroute/Index.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,27 @@
88

99
class Index extends \Magento\Framework\App\Action\Action
1010
{
11-
/**
12-
* @var \Magento\Framework\View\Result\LayoutFactory
13-
*/
14-
protected $resultLayoutFactory;
15-
1611
/**
1712
* @var \Magento\Backend\Model\View\Result\ForwardFactory
1813
*/
1914
protected $resultForwardFactory;
2015

2116
/**
2217
* @param \Magento\Framework\App\Action\Context $context
23-
* @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
2418
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
2519
*/
2620
public function __construct(
2721
\Magento\Framework\App\Action\Context $context,
28-
\Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
2922
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
3023
) {
31-
$this->resultLayoutFactory = $resultLayoutFactory;
3224
$this->resultForwardFactory = $resultForwardFactory;
3325
parent::__construct($context);
3426
}
3527

3628
/**
3729
* Render CMS 404 Not found page
3830
*
39-
* @return void
31+
* @return \Magento\Backend\Model\View\Result\Forward
4032
*/
4133
public function execute()
4234
{

dev/tests/unit/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/DirectiveTest.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ class DirectiveTest extends \PHPUnit_Framework_TestCase
6868
*/
6969
protected $loggerMock;
7070

71+
/**
72+
* @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject
73+
*/
74+
protected $rawFactoryMock;
75+
76+
/**
77+
* @var \Magento\Framework\Controller\Result\Raw|\PHPUnit_Framework_MockObject_MockObject
78+
*/
79+
protected $rawMock;
80+
7181
protected function setUp()
7282
{
7383
$this->actionContextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context')
@@ -117,6 +127,13 @@ protected function setUp()
117127
$this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface')
118128
->disableOriginalConstructor()
119129
->getMock();
130+
$this->rawFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\RawFactory')
131+
->setMethods(['create'])
132+
->disableOriginalConstructor()
133+
->getMock();
134+
$this->rawMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw')
135+
->disableOriginalConstructor()
136+
->getMock();
120137

121138
$this->actionContextMock->expects($this->any())
122139
->method('getRequest')
@@ -133,7 +150,8 @@ protected function setUp()
133150
'Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive',
134151
[
135152
'context' => $this->actionContextMock,
136-
'urlDecoder' => $this->urlDecoderMock
153+
'urlDecoder' => $this->urlDecoderMock,
154+
'resultRawFactory' => $this->rawFactoryMock
137155
]
138156
);
139157
}
@@ -153,17 +171,20 @@ public function testExecute()
153171
$this->imageAdapterMock->expects($this->once())
154172
->method('getMimeType')
155173
->willReturn($mimeType);
156-
$this->responseMock->expects($this->once())
174+
$this->rawMock->expects($this->once())
157175
->method('setHeader')
158176
->with('Content-Type', $mimeType)
159177
->willReturnSelf();
178+
$this->rawMock->expects($this->once())
179+
->method('setContents')
180+
->with($imageBody)
181+
->willReturnSelf();
160182
$this->imageAdapterMock->expects($this->once())
161183
->method('getImage')
162184
->willReturn($imageBody);
163-
$this->responseMock->expects($this->once())
164-
->method('setBody')
165-
->with($imageBody)
166-
->willReturnSelf();
185+
$this->rawFactoryMock->expects($this->any())
186+
->method('create')
187+
->willReturn($this->rawMock);
167188

168189
$this->wysiwygDirective->execute();
169190
}
@@ -192,20 +213,23 @@ public function testExecuteException()
192213
$this->imageAdapterMock->expects($this->once())
193214
->method('getMimeType')
194215
->willReturn($mimeType);
195-
$this->responseMock->expects($this->once())
216+
$this->rawMock->expects($this->once())
196217
->method('setHeader')
197218
->with('Content-Type', $mimeType)
198219
->willReturnSelf();
220+
$this->rawMock->expects($this->once())
221+
->method('setContents')
222+
->with($imageBody)
223+
->willReturnSelf();
199224
$this->imageAdapterMock->expects($this->once())
200225
->method('getImage')
201226
->willReturn($imageBody);
202-
$this->responseMock->expects($this->once())
203-
->method('setBody')
204-
->with($imageBody)
205-
->willReturnSelf();
206227
$this->loggerMock->expects($this->once())
207228
->method('critical')
208229
->with($exception);
230+
$this->rawFactoryMock->expects($this->any())
231+
->method('create')
232+
->willReturn($this->rawMock);
209233

210234
$this->wysiwygDirective->execute();
211235
}

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Cms\Controller;
6+
namespace Magento\Cms\Controller\Noroute;
77

8-
class NorouteTest extends \PHPUnit_Framework_TestCase
8+
class IndexTest extends \PHPUnit_Framework_TestCase
99
{
1010
/**
11-
* @var \Magento\Cms\Controller\Noroute
11+
* @var \Magento\Cms\Controller\Noroute\Index
1212
*/
1313
protected $_controller;
1414

@@ -22,30 +22,50 @@ class NorouteTest extends \PHPUnit_Framework_TestCase
2222
*/
2323
protected $_requestMock;
2424

25+
/**
26+
* @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $forwardFactoryMock;
29+
30+
/**
31+
* @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $forwardMock;
34+
2535
protected function setUp()
2636
{
2737
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
2838
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
2939
$responseMock = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
30-
$responseMock->expects(
40+
$this->forwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory')
41+
->setMethods(['create'])
42+
->disableOriginalConstructor()
43+
->getMock();
44+
$this->forwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward')
45+
->disableOriginalConstructor()
46+
->getMock();
47+
$this->forwardFactoryMock->expects($this->any())
48+
->method('create')
49+
->willReturn($this->forwardMock);
50+
$this->forwardMock->expects(
3151
$this->at(0)
3252
)->method(
3353
'setHeader'
3454
)->with(
3555
'HTTP/1.1',
3656
'404 Not Found'
3757
)->will(
38-
$this->returnValue($responseMock)
58+
$this->returnSelf()
3959
);
40-
$responseMock->expects(
60+
$this->forwardMock->expects(
4161
$this->at(1)
4262
)->method(
4363
'setHeader'
4464
)->with(
4565
'Status',
4666
'404 File not found'
4767
)->will(
48-
$this->returnValue($responseMock)
68+
$this->returnSelf()
4969
);
5070

5171
$scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
@@ -71,7 +91,9 @@ protected function setUp()
7191
);
7292
$this->_controller = $helper->getObject(
7393
'Magento\Cms\Controller\Noroute\Index',
74-
['response' => $responseMock, 'objectManager' => $objectManagerMock, 'request' => $this->_requestMock]
94+
['response' => $responseMock, 'objectManager' => $objectManagerMock, 'request' => $this->_requestMock,
95+
'resultForwardFactory' => $this->forwardFactoryMock
96+
]
7597
);
7698
}
7799

0 commit comments

Comments
 (0)