14 class PageTest extends \PHPUnit\Framework\TestCase
119 private $httpRequestMock;
126 $this->actionMock = $this->getMockBuilder(\
Magento\Framework\
App\Action\Action::class)
127 ->disableOriginalConstructor()
129 $this->pageFactoryMock = $this->getMockBuilder(\
Magento\Cms\Model\PageFactory::class)
130 ->disableOriginalConstructor()
131 ->setMethods([
'create'])
133 $this->pageMock = $this->getMockBuilder(\
Magento\Cms\Model\Page::class)
134 ->disableOriginalConstructor()
140 'getCustomThemeFrom',
145 'getCustomPageLayout',
146 'getCustomLayoutUpdateXml',
147 'getLayoutUpdateXml',
152 $this->storeManagerMock = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
153 ->getMockForAbstractClass();
154 $this->localeDateMock = $this->getMockBuilder(\
Magento\Framework\Stdlib\DateTime\TimezoneInterface::class)
155 ->getMockForAbstractClass();
156 $this->designMock = $this->getMockBuilder(\
Magento\Framework\View\DesignInterface::class)
157 ->getMockForAbstractClass();
158 $this->pageConfigMock = $this->getMockBuilder(\
Magento\Framework\View\Page\Config::class)
159 ->disableOriginalConstructor()
161 $this->escaperMock = $this->getMockBuilder(\
Magento\Framework\Escaper::class)
162 ->disableOriginalConstructor()
164 $this->eventManagerMock = $this->getMockBuilder(\
Magento\Framework\Event\ManagerInterface::class)
165 ->getMockForAbstractClass();
166 $this->urlBuilderMock = $this->getMockBuilder(\
Magento\Framework\UrlInterface::class)
167 ->getMockForAbstractClass();
168 $this->httpRequestMock = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)
169 ->getMockForAbstractClass();
170 $this->storeMock = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
171 ->disableOriginalConstructor()
173 $this->resultPageMock = $this->getMockBuilder(\
Magento\Framework\View\Result\Page::class)
174 ->disableOriginalConstructor()
176 $this->layoutMock = $this->getMockBuilder(\
Magento\Framework\View\LayoutInterface::class)
177 ->getMockForAbstractClass();
178 $this->layoutProcessorMock = $this->getMockBuilder(\
Magento\Framework\View\Layout\ProcessorInterface::class)
179 ->getMockForAbstractClass();
180 $this->blockMock = $this->getMockBuilder(\
Magento\Framework\View\Element\AbstractBlock::class)
181 ->setMethods([
'setContentHeading'])
182 ->disableOriginalConstructor()
183 ->getMockForAbstractClass();
184 $this->messagesBlockMock = $this->getMockBuilder(\
Magento\Framework\View\Element\Messages::class)
185 ->disableOriginalConstructor()
187 $this->messageManagerMock = $this->getMockBuilder(\
Magento\Framework\Message\ManagerInterface::class)
188 ->getMockForAbstractClass();
189 $this->messageCollectionMock = $this->getMockBuilder(\
Magento\Framework\Message\Collection::class)
190 ->disableOriginalConstructor()
193 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
197 'eventManager' => $this->eventManagerMock,
198 'urlBuilder' => $this->urlBuilderMock,
199 'httpRequest' => $this->httpRequestMock,
203 $this->resultPageFactory = $this->createMock(\
Magento\Framework\View\Result\PageFactory::class);
206 \
Magento\Cms\Helper\Page::class,
208 'context' => $context,
209 'pageFactory' => $this->pageFactoryMock,
210 'page' => $this->pageMock,
211 'storeManager' => $this->storeManagerMock,
212 'localeDate' => $this->localeDateMock,
213 'design' => $this->designMock,
214 'pageConfig' => $this->pageConfigMock,
215 'escaper' => $this->escaperMock,
216 'messageManager' => $this->messageManagerMock,
217 'resultPageFactory' => $this->resultPageFactory
240 $pageLoadResultIndex,
243 $customLayoutUpdateXml,
248 $customThemeFrom =
'customThemeFrom';
249 $customThemeTo =
'customThemeTo';
250 $isScopeDateInInterval =
true;
251 $customTheme =
'customTheme';
252 $pageLayout =
'pageLayout';
253 $pageIdentifier = 111;
254 $layoutUpdateXml =
'layoutUpdateXml';
255 $contentHeading =
'contentHeading';
256 $escapedContentHeading =
'escapedContentHeading';
257 $pageLoadResultCollection = [
262 $this->pageMock->expects($this->any())
264 ->willReturn($internalPageId);
265 $this->storeManagerMock->expects($this->any())
267 ->willReturn($this->storeMock);
268 $this->storeMock->expects($this->any())
271 $this->pageMock->expects($this->any())
272 ->method(
'setStoreId')
275 $this->pageMock->expects($this->any())
278 ->willReturn($pageLoadResultCollection[$pageLoadResultIndex]);
279 $this->pageMock->expects($this->any())
280 ->method(
'getCustomThemeFrom')
281 ->willReturn($customThemeFrom);
282 $this->pageMock->expects($this->any())
283 ->method(
'getCustomThemeTo')
284 ->willReturn($customThemeTo);
285 $this->localeDateMock->expects($this->any())
286 ->method(
'isScopeDateInInterval')
287 ->with(
null, $customThemeFrom, $customThemeTo)
288 ->willReturn($isScopeDateInInterval);
289 $this->pageMock->expects($this->any())
290 ->method(
'getCustomTheme')
291 ->willReturn($customTheme);
292 $this->designMock->expects($this->any())
293 ->method(
'setDesignTheme')
296 $this->pageMock->expects($this->any())
297 ->method(
'getPageLayout')
298 ->willReturn($pageLayout);
299 $this->pageMock->expects($this->any())
300 ->method(
'getCustomPageLayout')
301 ->willReturn($customPageLayout);
302 $this->resultPageFactory->expects($this->any())->method(
'create')
303 ->will($this->returnValue($this->resultPageMock));
304 $this->resultPageMock->expects($this->any())
305 ->method(
'getConfig')
306 ->willReturn($this->pageConfigMock);
307 $this->pageConfigMock->expects($this->any())
308 ->method(
'setPageLayout')
311 $this->resultPageMock->expects($this->any())
312 ->method(
'initLayout')
314 $this->resultPageMock->expects($this->any())
315 ->method(
'getLayout')
316 ->willReturn($this->layoutMock);
317 $this->layoutMock->expects($this->any())
318 ->method(
'getUpdate')
319 ->willReturn($this->layoutProcessorMock);
320 $this->layoutProcessorMock->expects($this->any())
321 ->method(
'addHandle')
322 ->with(
'cms_page_view')
324 $this->pageMock->expects($this->any())
325 ->method(
'getIdentifier')
326 ->willReturn($pageIdentifier);
327 $this->eventManagerMock->expects($this->any())
332 'page' => $this->pageMock,
333 'controller_action' => $this->actionMock,
334 'request' => $this->httpRequestMock,
337 $this->pageMock->expects($this->any())
338 ->method(
'getCustomLayoutUpdateXml')
339 ->willReturn($customLayoutUpdateXml);
340 $this->pageMock->expects($this->any())
341 ->method(
'getLayoutUpdateXml')
342 ->willReturn($layoutUpdateXml);
343 $this->layoutProcessorMock->expects($this->any())
344 ->method(
'addUpdate')
345 ->with($layoutUpdate)
347 $this->layoutMock->expects($this->any())
349 ->with(
'page_content_heading')
350 ->willReturn($this->blockMock);
351 $this->pageMock->expects($this->any())
352 ->method(
'getContentHeading')
353 ->willReturn($contentHeading);
354 $this->escaperMock->expects($this->any())
355 ->method(
'escapeHtml')
356 ->with($contentHeading)
357 ->willReturn($escapedContentHeading);
358 $this->blockMock->expects($this->any())
359 ->method(
'setContentHeading')
360 ->with($escapedContentHeading)
363 if ($expectedResult) {
369 $this->object->prepareResultPage($this->actionMock, $pageId)
379 'ids NOT EQUAL BUT page->load() NOT SUCCESSFUL' => [
381 'internalPageId' => 234,
382 'pageLoadResultIndex' => 0,
383 'customPageLayout' =>
'DOES NOT MATTER',
384 'handle' =>
'DOES NOT MATTER',
385 'customLayoutUpdateXml' =>
'DOES NOT MATTER',
386 'layoutUpdate' =>
'DOES NOT MATTER',
387 'expectedResult' =>
false,
389 'page->load IS SUCCESSFUL BUT internalPageId IS EMPTY' => [
391 'internalPageId' =>
null,
392 'pageLoadResultIndex' => 1,
393 'customPageLayout' =>
'DOES NOT MATTER',
394 'handle' =>
'DOES NOT MATTER',
395 'customLayoutUpdateXml' =>
'DOES NOT MATTER',
396 'layoutUpdate' =>
'DOES NOT MATTER',
397 'expectedResult' =>
false,
399 'getPageLayout() AND getLayoutUpdateXml() ARE USED' => [
401 'internalPageId' => 234,
402 'pageLoadResultIndex' => 1,
403 'customPageLayout' =>
'empty',
404 'handle' =>
'pageLayout',
405 'customLayoutUpdateXml' =>
'',
406 'layoutUpdate' =>
'layoutUpdateXml',
407 'expectedResult' =>
true,
409 'getCustomPageLayout() AND getCustomLayoutUpdateXml() ARE USED' => [
411 'internalPageId' => 234,
412 'pageLoadResultIndex' => 1,
413 'customPageLayout' =>
'customPageLayout',
414 'handle' =>
'customPageLayout',
415 'customLayoutUpdateXml' =>
'customLayoutUpdateXml',
416 'layoutUpdate' =>
'customLayoutUpdateXml',
417 'expectedResult' =>
true,
434 $pageLoadResultIndex,
438 $pageIdentifier = 111;
440 $pageLoadResultCollection = [
445 $this->pageFactoryMock->expects($this->any())
447 ->willReturn($this->pageMock);
448 $this->pageMock->expects($this->any())
450 ->willReturn($internalPageId);
451 $this->storeManagerMock->expects($this->any())
453 ->willReturn($this->storeMock);
454 $this->storeMock->expects($this->any())
457 $this->pageMock->expects($this->any())
458 ->method(
'setStoreId')
461 $this->pageMock->expects($this->any())
464 ->willReturn($pageLoadResultCollection[$pageLoadResultIndex]);
465 $this->pageMock->expects($this->any())
466 ->method(
'getIdentifier')
467 ->willReturn($pageIdentifier);
468 $this->urlBuilderMock->expects($this->any())
470 ->with(
null, [
'_direct' => $pageIdentifier])
473 $this->assertEquals($expectedResult, $this->object->getPageUrl($pageId));
482 'ids NOT EQUAL BUT page->load() NOT SUCCESSFUL' => [
484 'internalPageId' =>
null,
485 'pageLoadResultIndex' => 0,
486 'expectedResult' =>
null,
488 'page->load() IS SUCCESSFUL BUT internalId IS EMPTY' => [
490 'internalPageId' =>
null,
491 'pageLoadResultIndex' => 1,
492 'expectedResult' =>
null,
496 'internalPageId' => 234,
497 'pageLoadResultIndex' => 1,
498 'expectedResult' =>
'/some/url',
renderPageExtendedDataProvider()
testPrepareResultPage( $pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult)
testGetPageUrl( $pageId, $internalPageId, $pageLoadResultIndex, $expectedResult)