/** * Retrieve the layout update instance * * @return \Magento\Framework\View\Layout\ProcessorInterface */ protected function getPageLayoutMerge() { if ($this->pageLayoutMerge) { return $this->pageLayoutMerge; } $this->pageLayoutMerge = $this->processorFactory->create(['theme' => $this->themeResolver->get(), 'fileSource' => $this->pageLayoutFileSource, 'cacheSuffix' => self::MERGE_CACHE_SUFFIX]); return $this->pageLayoutMerge; }
public function testGetUpdate() { $themeMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $this->themeResolverMock->expects($this->once())->method('get')->will($this->returnValue($themeMock)); $this->processorFactoryMock->expects($this->once())->method('create')->with(array('theme' => $themeMock))->will($this->returnValue($this->processorMock)); $this->assertEquals($this->processorMock, $this->_model->getUpdate()); $this->assertEquals($this->processorMock, $this->_model->getUpdate()); }
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(); }
public function testGenerateXml() { $themeMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $this->themeResolverMock->expects($this->once())->method('get')->will($this->returnValue($themeMock)); $this->processorFactoryMock->expects($this->once())->method('create')->with(['theme' => $themeMock])->will($this->returnValue($this->processorMock)); $xmlString = '<?xml version="1.0"?><layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . '<some_update>123</some_update></layout>'; $xml = simplexml_load_string($xmlString, 'Magento\\Framework\\View\\Layout\\Element'); $this->processorMock->expects($this->once())->method('asSimplexml')->will($this->returnValue($xml)); $this->structureMock->expects($this->once())->method('importElements')->with($this->equalTo([]))->will($this->returnSelf()); $this->assertSame($this->model, $this->model->generateXml()); $this->assertSame('<some_update>123</some_update>', $this->model->getNode('some_update')->asXml()); }
/** * Retrieve the layout update instance * * @return \Magento\Framework\View\Layout\ProcessorInterface */ public function getUpdate() { if (!$this->_update) { $theme = $this->themeResolver->get(); $this->_update = $this->_processorFactory->create(['theme' => $theme]); } return $this->_update; }