/** * {@inheritdoc} * * @param Layout\Reader\Context $readerContext * @param Layout\Element $bodyElement * @return $this */ public function interpret(Layout\Reader\Context $readerContext, Layout\Element $bodyElement) { /** @var \Magento\Framework\View\Layout\Element $element */ foreach ($bodyElement as $element) { if ($element->getName() === self::BODY_ATTRIBUTE) { $this->setBodyAttributeToStructure($readerContext, $element); } } $this->readerPool->interpret($readerContext, $bodyElement); return $this; }
/** * @param \Magento\Framework\View\Layout\Element $elementCurrent * @param string $containerName * @param array $structureElement * @param array $expectedData * * @dataProvider processDataProvider */ public function testProcess($elementCurrent, $containerName, $structureElement, $expectedData) { /** @var ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructureMock */ $scheduledStructureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\ScheduledStructure')->disableOriginalConstructor()->getMock(); $scheduledStructureMock->expects($this->once())->method('getStructureElementData')->with($containerName)->willReturn($structureElement); $scheduledStructureMock->expects($this->once())->method('setStructureElementData')->with($containerName, $expectedData)->willReturnSelf(); /** @var Context|\PHPUnit_Framework_MockObject_MockObject $contextMock */ $contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock(); $contextMock->expects($this->any())->method('getScheduledStructure')->willReturn($scheduledStructureMock); $this->helperMock->method('scheduleStructure')->with($scheduledStructureMock, $elementCurrent); $this->readerPoolMock->expects($this->once())->method('interpret')->with($contextMock, $elementCurrent)->willReturnSelf(); $this->container->interpret($contextMock, $elementCurrent); }
public function testInterpret() { /** @var Reader\Context $contextMock */ $contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock(); $currentElement = new \Magento\Framework\View\Layout\Element('<element><move name="block"/><remove name="container"/><ignored name="user"/></element>'); /** * @var \Magento\Framework\View\Layout\Reader\Move|\PHPUnit_Framework_MockObject_MockObject $moveReaderMock */ $moveReaderMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Move')->disableOriginalConstructor()->getMock(); $moveReaderMock->expects($this->exactly(2))->method('interpret')->willReturn($this->returnSelf()); $moveReaderMock->method('getSupportedNodes')->willReturn(['move']); $this->readerFactoryMock->expects($this->once())->method('create')->willReturnMap([['Magento\\Framework\\View\\Layout\\Reader\\Move', [], $moveReaderMock]]); $this->pool->interpret($contextMock, $currentElement); $this->pool->interpret($contextMock, $currentElement); }
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); }
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} * * @param Context $readerContext * @param Layout\Element $currentElement * @param Layout\Element $parentElement * @return $this */ public function interpret(Context $readerContext, Layout\Element $currentElement) { switch ($currentElement->getName()) { case self::TYPE_CONTAINER: $this->helper->scheduleStructure($readerContext->getScheduledStructure(), $currentElement, $currentElement->getParent()); $this->mergeContainerAttributes($readerContext->getScheduledStructure(), $currentElement); break; case self::TYPE_REFERENCE_CONTAINER: $this->containerReference($readerContext->getScheduledStructure(), $currentElement); break; default: break; } $this->readerPool->interpret($readerContext, $currentElement); return $this; }
/** * {@inheritdoc} * * @param Context $readerContext * @param Layout\Element $currentElement * @param Layout\Element $parentElement * @return $this */ public function interpret(Context $readerContext, Layout\Element $currentElement) { $scheduledStructure = $readerContext->getScheduledStructure(); switch ($currentElement->getName()) { case self::TYPE_BLOCK: $this->scheduleBlock($scheduledStructure, $currentElement); break; case self::TYPE_REFERENCE_BLOCK: $this->scheduleReference($scheduledStructure, $currentElement); break; default: break; } $this->readerPool->interpret($readerContext, $currentElement); return $this; }
/** * Create structure of elements from the loaded XML configuration * * @return void */ public function generateElements() { \Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__); $cacheId = 'structure_' . $this->getUpdate()->getCacheId(); $result = $this->cache->load($cacheId); if ($result) { $this->readerContext = unserialize($result); } else { \Magento\Framework\Profiler::start('build_structure'); $this->readerPool->interpret($this->getReaderContext(), $this->getNode()); \Magento\Framework\Profiler::stop('build_structure'); $this->cache->save(serialize($this->getReaderContext()), $cacheId, $this->getUpdate()->getHandles()); } $generatorContext = $this->generatorContextFactory->create(['structure' => $this->structure, 'layout' => $this]); \Magento\Framework\Profiler::start('generate_elements'); $this->generatorPool->process($this->getReaderContext(), $generatorContext); \Magento\Framework\Profiler::stop('generate_elements'); $this->addToOutputRootContainers(); \Magento\Framework\Profiler::stop(__CLASS__ . '::' . __METHOD__); }
/** * Prepare reader pool * * @param string $xml * @param string $elementType */ protected function prepareReaderPool($xml, $elementType) { $this->currentElement = $this->getElement($xml, $elementType); $this->readerPool->expects($this->once())->method('interpret')->with($this->context, $this->currentElement); }
/** * Read page layout structure and fill reader context * * @param Layout\Reader\Context $readerContext * @param string $pageLayout * @return void */ public function read(Layout\Reader\Context $readerContext, $pageLayout) { $this->getPageLayoutMerge()->load($pageLayout); $xml = $this->getPageLayoutMerge()->asSimplexml(); $this->reader->interpret($readerContext, $xml); }