/** * test for getActualHandles function */ public function testGetActualHandles() { $this->prepareMocks(); $layoutHandles = ['handle1', 'config_layout_handle1', 'handle2']; $this->updateLayoutMock->expects($this->once())->method('getHandles')->will($this->returnValue($layoutHandles)); $this->assertEquals($layoutHandles, $this->helper->getActualHandles()); }
/** * @covers \Magento\PageCache\Block\Javascript::getScriptOptions * @param bool $isSecure * @param string $url * @param string $expectedResult * @dataProvider getScriptOptionsDataProvider */ public function testGetScriptOptions($isSecure, $url, $expectedResult) { $handles = ['some', 'handles', 'here']; $this->requestMock->expects($this->once())->method('isSecure')->willReturn($isSecure); $this->urlBuilderMock->expects($this->once())->method('getUrl')->willReturn($url); $this->layoutUpdateMock->expects($this->once())->method('getHandles')->willReturn($handles); $this->assertRegExp($expectedResult, $this->blockJavascript->getScriptOptions()); }
public function testRead() { $data = 'test_string'; $xml = '<body> <attribute name="body_attribute_name" value="body_attribute_value" /> </body>'; $this->processorInterface->expects($this->any())->method('load')->with($data)->will($this->returnValue($this->processorInterface)); $this->themeResolver->expects($this->atLeastOnce())->method('get')->will($this->returnValue($this->themeInterface)); $createData = ['theme' => $this->themeInterface, 'fileSource' => $this->pageLayoutFileSource, 'cacheSuffix' => 'page_layout']; $this->processorFactory->expects($this->once())->method('create')->with($createData)->will($this->returnValue($this->processorInterface)); $element = new \Magento\Framework\View\Layout\Element($xml); $this->processorInterface->expects($this->once())->method('asSimplexml')->will($this->returnValue($element)); $this->readerPool->expects($this->once())->method('interpret')->with($this->readerContext, $element); $this->model->read($this->readerContext, $data); }
/** * Cleanup circular references between layout & blocks * * Destructor should be called explicitly in order to work around the PHP bug * https://bugs.php.net/bug.php?id=62468 */ public function __destruct() { if (isset($this->_update) && is_object($this->_update)) { $this->_update->__destruct(); $this->_update = null; } $this->_blocks = []; parent::__destruct(); }
/** * Cleanup circular references between layout & blocks * * Destructor should be called explicitly in order to work around the PHP bug * https://bugs.php.net/bug.php?id=62468 */ public function __destruct() { if (isset($this->_update) && is_object($this->_update)) { $this->_update->__destruct(); $this->_update = null; } $this->_blocks = array(); $this->_xml = null; }
/** * @covers \Magento\PageCache\Block\Javascript::getScriptOptions * @param string $url * @param string $route * @param string $controller * @param string $action * @param string $expectedResult * @dataProvider getScriptOptionsPrivateContentDataProvider */ public function testGetScriptOptionsPrivateContent($url, $route, $controller, $action, $expectedResult) { $handles = ['some', 'handles', 'here']; $this->requestMock->expects($this->once())->method('isSecure')->willReturn(false); $this->requestMock->expects($this->once())->method('getRouteName')->will($this->returnValue($route)); $this->requestMock->expects($this->once())->method('getControllerName')->will($this->returnValue($controller)); $this->requestMock->expects($this->once())->method('getActionName')->will($this->returnValue($action)); $this->urlBuilderMock->expects($this->once())->method('getUrl')->willReturn($url); $this->layoutUpdateMock->expects($this->once())->method('getHandles')->willReturn($handles); $this->assertRegExp($expectedResult, $this->blockJavascript->getScriptOptions()); }
/** * @covers \Magento\Cms\Helper\Page::renderPageExtended * @param integer|null $pageId * @param integer|null $internalPageId * @param integer $pageLoadResultIndex * @param string $customPageLayout * @param string $handle * @param string $customLayoutUpdateXml * @param string $layoutUpdate * @param boolean $expectedResult * * @dataProvider renderPageExtendedDataProvider * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testRenderPageExtended($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult) { $storeId = 321; $customThemeFrom = 'customThemeFrom'; $customThemeTo = 'customThemeTo'; $isScopeDateInInterval = true; $customTheme = 'customTheme'; $pageLayout = 'pageLayout'; $pageIdentifier = 111; $layoutUpdateXml = 'layoutUpdateXml'; $contentHeading = 'contentHeading'; $escapedContentHeading = 'escapedContentHeading'; $defaultGroup = 'defaultGroup'; $pageLoadResultCollection = [null, $this->pageMock]; $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf(); $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]); $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom); $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo); $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval); $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme); $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf(); $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout); $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock); $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier); $this->viewMock->expects($this->any())->method('addPageLayoutHandles')->with(['id' => $pageIdentifier])->willReturn(true); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->viewMock->expects($this->any())->method('loadLayoutUpdates')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml); $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml); $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf(); $this->viewMock->expects($this->any())->method('generateLayoutXml')->willReturnSelf(); $this->viewMock->expects($this->any())->method('generateLayoutBlocks')->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock); $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading); $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getMessagesBlock')->willReturn($this->messagesBlockMock); $this->messageManagerMock->expects($this->any())->method('getDefaultGroup')->willReturn($defaultGroup); $this->messagesBlockMock->expects($this->any())->method('addStorageType')->with($defaultGroup); $this->messageManagerMock->expects($this->any())->method('getMessages')->with(true)->willReturn($this->messageCollectionMock); $this->messagesBlockMock->expects($this->any())->method('addMessages')->with($this->messageCollectionMock)->willReturnSelf(); $this->viewMock->expects($this->any())->method('renderLayout')->willReturnSelf(); $this->assertEquals($expectedResult, $this->object->renderPageExtended($this->actionMock, $pageId)); }
/** * @covers \Magento\Cms\Helper\Page::prepareResultPage * @param integer|null $pageId * @param integer|null $internalPageId * @param integer $pageLoadResultIndex * @param string $customPageLayout * @param string $handle * @param string $customLayoutUpdateXml * @param string $layoutUpdate * @param boolean $expectedResult * * @dataProvider renderPageExtendedDataProvider * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testPrepareResultPage($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult) { $storeId = 321; $customThemeFrom = 'customThemeFrom'; $customThemeTo = 'customThemeTo'; $isScopeDateInInterval = true; $customTheme = 'customTheme'; $pageLayout = 'pageLayout'; $pageIdentifier = 111; $layoutUpdateXml = 'layoutUpdateXml'; $contentHeading = 'contentHeading'; $escapedContentHeading = 'escapedContentHeading'; $pageLoadResultCollection = [null, $this->pageMock]; $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf(); $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]); $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom); $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo); $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval); $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme); $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf(); $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout); $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout); $this->resultPageFactory->expects($this->any())->method('create')->will($this->returnValue($this->resultPageMock)); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock); $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml); $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml); $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock); $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading); $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf(); if ($expectedResult) { $expectedResult = $this->resultPageMock; } $this->assertSame($expectedResult, $this->object->prepareResultPage($this->actionMock, $pageId)); }