Skip to content

Commit c34af04

Browse files
author
vpaladiychuk
committed
MAGETWO-33059: Refactor CMS module
1 parent e980f1c commit c34af04

File tree

3 files changed

+21
-148
lines changed

3 files changed

+21
-148
lines changed

app/code/Magento/Cms/Helper/Page.php

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ class Page extends \Magento\Framework\App\Helper\AbstractHelper
7171
*/
7272
protected $_escaper;
7373

74-
/**
75-
* @deprecated
76-
* @TODO MAGETWO-28356: Refactor controller actions to new ResultInterface
77-
* @var \Magento\Framework\App\ViewInterface
78-
*/
79-
protected $_view;
80-
8174
/**
8275
* @var \Magento\Framework\View\Result\PageFactory
8376
*/
@@ -94,7 +87,6 @@ class Page extends \Magento\Framework\App\Helper\AbstractHelper
9487
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
9588
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
9689
* @param \Magento\Framework\Escaper $escaper
97-
* @param \Magento\Framework\App\ViewInterface $view
9890
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
9991
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
10092
*/
@@ -107,11 +99,9 @@ public function __construct(
10799
\Magento\Framework\Store\StoreManagerInterface $storeManager,
108100
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
109101
\Magento\Framework\Escaper $escaper,
110-
\Magento\Framework\App\ViewInterface $view,
111102
\Magento\Framework\View\Result\PageFactory $resultPageFactory
112103
) {
113104
$this->messageManager = $messageManager;
114-
$this->_view = $view;
115105
$this->_page = $page;
116106
$this->_design = $design;
117107
$this->_pageFactory = $pageFactory;
@@ -192,111 +182,6 @@ public function prepareResultPage(Action $action, $pageId = null)
192182
return $resultPage;
193183
}
194184

195-
/**
196-
* Renders CMS page on front end
197-
*
198-
* Call from controller action
199-
*
200-
* @param Action $action
201-
* @param int $pageId
202-
* @return bool
203-
*/
204-
public function renderPage(Action $action, $pageId = null)
205-
{
206-
return $this->_renderPage($action, $pageId);
207-
}
208-
209-
/**
210-
* Renders CMS page
211-
*
212-
* @param Action $action
213-
* @param int $pageId
214-
* @param bool $renderLayout
215-
* @return bool
216-
*/
217-
protected function _renderPage(Action $action, $pageId = null, $renderLayout = true)
218-
{
219-
if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
220-
$delimiterPosition = strrpos($pageId, '|');
221-
if ($delimiterPosition) {
222-
$pageId = substr($pageId, 0, $delimiterPosition);
223-
}
224-
225-
$this->_page->setStoreId($this->_storeManager->getStore()->getId());
226-
if (!$this->_page->load($pageId)) {
227-
return false;
228-
}
229-
}
230-
231-
if (!$this->_page->getId()) {
232-
return false;
233-
}
234-
235-
$inRange = $this->_localeDate->isScopeDateInInterval(
236-
null,
237-
$this->_page->getCustomThemeFrom(),
238-
$this->_page->getCustomThemeTo()
239-
);
240-
241-
if ($this->_page->getCustomTheme()) {
242-
if ($inRange) {
243-
$this->_design->setDesignTheme($this->_page->getCustomTheme());
244-
}
245-
}
246-
/** @var \Magento\Framework\View\Result\Page $resultPage */
247-
$resultPage = $this->_view->getPage();
248-
$this->setLayoutType($inRange, $resultPage);
249-
$resultPage->initLayout();
250-
$resultPage->addHandle('cms_page_view');
251-
$resultPage->addPageLayoutHandles(['id' => $this->_page->getIdentifier()]);
252-
253-
$this->_eventManager->dispatch(
254-
'cms_page_render',
255-
['page' => $this->_page, 'controller_action' => $action]
256-
);
257-
258-
if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
259-
$layoutUpdate = $this->_page->getCustomLayoutUpdateXml();
260-
} else {
261-
$layoutUpdate = $this->_page->getLayoutUpdateXml();
262-
}
263-
if (!empty($layoutUpdate)) {
264-
$resultPage->getLayout()->getUpdate()->addUpdate($layoutUpdate);
265-
}
266-
267-
$contentHeadingBlock = $resultPage->getLayout()->getBlock('page_content_heading');
268-
if ($contentHeadingBlock) {
269-
$contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading());
270-
$contentHeadingBlock->setContentHeading($contentHeading);
271-
}
272-
273-
/* @TODO: Move catalog and checkout storage types to appropriate modules */
274-
$messageBlock = $resultPage->getLayout()->getMessagesBlock();
275-
$messageBlock->addStorageType($this->messageManager->getDefaultGroup());
276-
$messageBlock->addMessages($this->messageManager->getMessages(true));
277-
278-
if ($renderLayout) {
279-
$this->_view->renderLayout();
280-
}
281-
282-
return true;
283-
}
284-
285-
/**
286-
* Renders CMS Page with more flexibility then original renderPage function.
287-
* Allows to use also backend action as first parameter.
288-
* Also takes third parameter which allows not run renderLayout method.
289-
*
290-
* @param Action $action
291-
* @param int $pageId
292-
* @param bool $renderLayout
293-
* @return bool
294-
*/
295-
public function renderPageExtended(Action $action, $pageId = null, $renderLayout = true)
296-
{
297-
return $this->_renderPage($action, $pageId, $renderLayout);
298-
}
299-
300185
/**
301186
* Retrieve page direct URL
302187
*

dev/tests/integration/testsuite/Magento/Cms/Helper/PageTest.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testRenderPage()
3636
// fixture
3737
/** @var $pageHelper \Magento\Cms\Helper\Page */
3838
$pageHelper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Cms\Helper\Page');
39-
$result = $pageHelper->renderPage(
39+
$result = $pageHelper->prepareResultPage(
4040
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
4141
'Magento\Framework\App\Action\Action',
4242
['context' => $context]
@@ -47,6 +47,6 @@ public function testRenderPage()
4747
'Magento\Framework\View\DesignInterface'
4848
);
4949
$this->assertEquals('Magento/blank', $design->getDesignTheme()->getThemePath());
50-
$this->assertTrue($result);
50+
$this->assertInstanceOf('Magento\Framework\View\Result\Page', $result);
5151
}
5252
}

dev/tests/unit/testsuite/Magento/Cms/Helper/PageTest.php

100644100755
Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class PageTest extends \PHPUnit_Framework_TestCase
5353
*/
5454
protected $pageConfigMock;
5555

56-
/**
57-
* @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject
58-
*/
59-
protected $viewMock;
60-
6156
/**
6257
* @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
6358
*/
@@ -113,6 +108,11 @@ class PageTest extends \PHPUnit_Framework_TestCase
113108
*/
114109
protected $messageCollectionMock;
115110

111+
/**
112+
* @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
113+
*/
114+
protected $resultPageFactory;
115+
116116
protected function setUp()
117117
{
118118
$this->actionMock = $this->getMockBuilder('Magento\Framework\App\Action\Action')
@@ -150,8 +150,6 @@ protected function setUp()
150150
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
151151
->disableOriginalConstructor()
152152
->getMock();
153-
$this->viewMock = $this->getMockBuilder('Magento\Framework\App\ViewInterface')
154-
->getMockForAbstractClass();
155153
$this->escaperMock = $this->getMockBuilder('Magento\Framework\Escaper')
156154
->disableOriginalConstructor()
157155
->getMock();
@@ -189,6 +187,9 @@ protected function setUp()
189187
'urlBuilder' => $this->urlBuilderMock
190188
]
191189
);
190+
191+
$this->resultPageFactory = $this->getMock('Magento\Framework\View\Result\PageFactory', [], [], '', false);
192+
192193
$this->object = $objectManager->getObject(
193194
'Magento\Cms\Helper\Page',
194195
[
@@ -199,9 +200,9 @@ protected function setUp()
199200
'localeDate' => $this->localeDateMock,
200201
'design' => $this->designMock,
201202
'pageConfig' => $this->pageConfigMock,
202-
'view' => $this->viewMock,
203203
'escaper' => $this->escaperMock,
204-
'messageManager' => $this->messageManagerMock
204+
'messageManager' => $this->messageManagerMock,
205+
'resultPageFactory' => $this->resultPageFactory
205206
]
206207
);
207208
}
@@ -221,7 +222,7 @@ protected function setUp()
221222
*
222223
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
223224
*/
224-
public function testRenderPageExtended(
225+
public function testPrepareResultPage(
225226
$pageId,
226227
$internalPageId,
227228
$pageLoadResultIndex,
@@ -287,16 +288,15 @@ public function testRenderPageExtended(
287288
$this->pageMock->expects($this->any())
288289
->method('getCustomPageLayout')
289290
->willReturn($customPageLayout);
291+
$this->resultPageFactory->expects($this->any())->method('create')
292+
->will($this->returnValue($this->resultPageMock));
290293
$this->resultPageMock->expects($this->any())
291294
->method('getConfig')
292295
->willReturn($this->pageConfigMock);
293296
$this->pageConfigMock->expects($this->any())
294297
->method('setPageLayout')
295298
->with($handle)
296299
->willReturnSelf();
297-
$this->viewMock->expects($this->any())
298-
->method('getPage')
299-
->willReturn($this->resultPageMock);
300300
$this->resultPageMock->expects($this->any())
301301
->method('initLayout')
302302
->willReturnSelf();
@@ -313,10 +313,6 @@ public function testRenderPageExtended(
313313
$this->pageMock->expects($this->any())
314314
->method('getIdentifier')
315315
->willReturn($pageIdentifier);
316-
$this->viewMock->expects($this->any())
317-
->method('addPageLayoutHandles')
318-
->with(['id' => $pageIdentifier])
319-
->willReturn(true);
320316
$this->eventManagerMock->expects($this->any())
321317
->method('dispatch')
322318
->with(
@@ -326,9 +322,6 @@ public function testRenderPageExtended(
326322
'controller_action' => $this->actionMock
327323
]
328324
);
329-
$this->viewMock->expects($this->any())
330-
->method('loadLayoutUpdates')
331-
->willReturnSelf();
332325
$this->pageMock->expects($this->any())
333326
->method('getCustomLayoutUpdateXml')
334327
->willReturn($customLayoutUpdateXml);
@@ -339,12 +332,6 @@ public function testRenderPageExtended(
339332
->method('addUpdate')
340333
->with($layoutUpdate)
341334
->willReturnSelf();
342-
$this->viewMock->expects($this->any())
343-
->method('generateLayoutXml')
344-
->willReturnSelf();
345-
$this->viewMock->expects($this->any())
346-
->method('generateLayoutBlocks')
347-
->willReturnSelf();
348335
$this->layoutMock->expects($this->any())
349336
->method('getBlock')
350337
->with('page_content_heading')
@@ -377,13 +364,14 @@ public function testRenderPageExtended(
377364
->method('addMessages')
378365
->with($this->messageCollectionMock)
379366
->willReturnSelf();
380-
$this->viewMock->expects($this->any())
381-
->method('renderLayout')
382-
->willReturnSelf();
383367

384-
$this->assertEquals(
368+
if ($expectedResult) {
369+
$expectedResult = $this->resultPageMock;
370+
}
371+
372+
$this->assertSame(
385373
$expectedResult,
386-
$this->object->renderPageExtended($this->actionMock, $pageId)
374+
$this->object->prepareResultPage($this->actionMock, $pageId)
387375
);
388376
}
389377

0 commit comments

Comments
 (0)