public function testGenerateElementsWithCache() { $layoutCacheId = 'layout_cache_id'; /** @var \Magento\Framework\View\Layout\Element $xml */ $xml = simplexml_load_string('<layout/>', 'Magento\Framework\View\Layout\Element'); $this->model->setXml($xml); $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); $this->themeResolverMock->expects($this->once()) ->method('get') ->willReturn($themeMock); $this->processorFactoryMock->expects($this->once()) ->method('create') ->with(['theme' => $themeMock]) ->willReturn($this->processorMock); $this->processorMock->expects($this->once()) ->method('getCacheId') ->willReturn($layoutCacheId); $readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context') ->disableOriginalConstructor() ->getMock(); $this->cacheMock->expects($this->once()) ->method('load') ->with('structure_' . $layoutCacheId) ->willReturn(serialize($readerContextMock)); $this->readerPoolMock->expects($this->never()) ->method('interpret'); $this->cacheMock->expects($this->never()) ->method('save'); $generatorContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Context') ->disableOriginalConstructor() ->getMock(); $this->generatorContextFactoryMock->expects($this->once()) ->method('create') ->with(['structure' => $this->structureMock, 'layout' => $this->model]) ->willReturn($generatorContextMock); $this->generatorPoolMock->expects($this->once()) ->method('process') ->with($readerContextMock, $generatorContextMock) ->willReturn(true); $elements = [ 'name_1' => ['type' => '', 'parent' => null], 'name_2' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => null], 'name_3' => ['type' => '', 'parent' => 'parent'], 'name_4' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => 'parent'], ]; $this->structureMock->expects($this->once()) ->method('exportElements') ->willReturn($elements); $this->model->generateElements(); }
/** * {@inheritdoc} */ public function getDbUpdateString($handle) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getDbUpdateString'); if (!$pluginInfo) { return parent::getDbUpdateString($handle); } else { return $this->___callPlugins('getDbUpdateString', func_get_args(), $pluginInfo); } }
public function testAddPageLayoutHandlesWithDefaultHandle() { $defaultHandle = 'default_handle'; $parameters = ['key_one' => 'val_one', 'key_two' => 'val_two']; $expected = ['default_handle', 'default_handle_key_one_val_one', 'default_handle_key_two_val_two']; $this->request->expects($this->never())->method('getFullActionName'); $this->layoutMerge->expects($this->any())->method('addHandle')->with($expected)->willReturnSelf(); $this->page->addPageLayoutHandles($parameters, $defaultHandle); }
public function testLoadDbApp() { $this->assertEmpty($this->model->getHandles()); $this->assertEmpty($this->model->asString()); $handles = ['fixture_handle_one', 'fixture_handle_two']; $this->model->load($handles); $expectedResult = ' <root> <body> <block class="Magento\\Framework\\View\\Element\\Template" template="fixture_template_one.phtml"/> </body> <body> <block class="Magento\\Framework\\View\\Element\\Template" template="fixture_template_two.phtml"/> </body> </root> '; $actualResult = '<root>' . $this->model->asString() . '</root>'; $this->assertXmlStringEqualsXmlString($expectedResult, $actualResult); }
/** * Test loading invalid layout */ public function testLoadWithInvalidLayout() { $this->_model->addPageHandles(['default']); $this->_appState->expects($this->any())->method('getMode')->will($this->returnValue('developer')); $this->_layoutValidator->expects($this->any())->method('getMessages')->will($this->returnValue(['testMessage1', 'testMessage2'])); $this->_layoutValidator->expects($this->any())->method('isValid')->will($this->returnValue(false)); $suffix = md5(implode('|', $this->_model->getHandles())); $cacheId = "LAYOUT_{$this->_theme->getArea()}_STORE{$this->scope->getId()}_{$this->_theme->getId()}{$suffix}"; $messages = $this->_layoutValidator->getMessages(); // Testing error message is logged with logger $this->_logger->expects($this->once())->method('info')->with('Cache file with merged layout: ' . $cacheId . ' and handles default' . ': ' . array_shift($messages)); $this->_model->load(); }
/** * Around getDbUpdateString * * @param \Magento\Framework\View\Model\Layout\Merge $subject * @param callable $proceed * @param string $handle * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundGetDbUpdateString(\Magento\Framework\View\Model\Layout\Merge $subject, \Closure $proceed, $handle) { return $this->update->fetchUpdatesByHandle($handle, $subject->getTheme(), $subject->getScope()); }
/** * {@inheritdoc} */ public function getCacheId() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCacheId'); if (!$pluginInfo) { return parent::getCacheId(); } else { return $this->___callPlugins('getCacheId', func_get_args(), $pluginInfo); } }