protected function setUp() { $this->structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Data\\Structure')->disableOriginalConstructor()->getMock(); $this->processorFactoryMock = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorFactory', ['create'], [], '', false); $this->themeResolverMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\Theme\\ResolverInterface'); $this->processorMock = $this->getMock('Magento\\Framework\\View\\Model\\Layout\\Merge', [], [], '', false); $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface'); $this->generatorBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Block')->disableOriginalConstructor()->getMock(); $this->generatorContainerMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Container')->disableOriginalConstructor()->getMock(); $this->cacheMock = $this->getMockBuilder('Magento\\Framework\\Cache\\FrontendInterface')->disableOriginalConstructor()->getMock(); $this->readerPoolMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\ReaderPool')->disableOriginalConstructor()->getMock(); $this->messageManagerMock = $this->getMockBuilder('Magento\\Framework\\Message\\ManagerInterface')->disableOriginalConstructor()->getMock(); $this->generatorPoolMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\GeneratorPool')->disableOriginalConstructor()->getMock(); $this->generatorPoolMock->expects($this->any())->method('getGenerator')->will($this->returnValueMap([[\Magento\Framework\View\Layout\Generator\Block::TYPE, $this->generatorBlockMock], [\Magento\Framework\View\Layout\Generator\Container::TYPE, $this->generatorContainerMock]])); $this->readerContextFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\ContextFactory')->disableOriginalConstructor()->getMock(); $this->readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock(); $this->readerContextFactoryMock->expects($this->once())->method('create')->willReturn($this->readerContextMock); $this->generatorContextFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\ContextFactory')->disableOriginalConstructor()->getMock(); $this->model = new \Magento\Framework\View\Layout($this->processorFactoryMock, $this->eventManagerMock, $this->structureMock, $this->messageManagerMock, $this->themeResolverMock, $this->readerPoolMock, $this->generatorPoolMock, $this->cacheMock, $this->readerContextFactoryMock, $this->generatorContextFactoryMock, true); }
public function testGenerateElementsWithoutCache() { $this->readerContextFactoryMock->expects($this->once())->method('create')->willReturn($this->readerContextMock); $layoutCacheId = 'layout_cache_id'; $handles = ['default', 'another']; /** @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); $this->processorMock->expects($this->once())->method('getHandles')->willReturn($handles); $this->cacheMock->expects($this->once())->method('load')->with('structure_' . $layoutCacheId)->willReturn(false); $this->readerPoolMock->expects($this->once())->method('interpret')->with($this->readerContextMock, $xml)->willReturnSelf(); $this->cacheMock->expects($this->once())->method('save')->with(serialize($this->readerContextMock), 'structure_' . $layoutCacheId, $handles)->willReturn(true); $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($this->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(); }
/** * Getter and lazy loader for reader context * * @return Layout\Reader\Context */ public function getReaderContext() { if (!$this->readerContext) { $this->readerContext = $this->readerContextFactory->create(); } return $this->readerContext; }
/** * @param Layout\ProcessorFactory $processorFactory * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param Layout\Data\Structure $structure * @param \Magento\Framework\Message\ManagerInterface $messageManager * @param Design\Theme\ResolverInterface $themeResolver * @param Layout\ReaderPool $readerPool * @param Layout\GeneratorPool $generatorPool * @param FrontendInterface $cache * @param Layout\Reader\ContextFactory $readerContextFactory * @param Layout\Generator\ContextFactory $generatorContextFactory * @param bool $cacheable */ public function __construct(Layout\ProcessorFactory $processorFactory, ManagerInterface $eventManager, Layout\Data\Structure $structure, MessageManagerInterface $messageManager, Design\Theme\ResolverInterface $themeResolver, Layout\ReaderPool $readerPool, Layout\GeneratorPool $generatorPool, FrontendInterface $cache, Layout\Reader\ContextFactory $readerContextFactory, Layout\Generator\ContextFactory $generatorContextFactory, $cacheable = true) { $this->_elementClass = 'Magento\\Framework\\View\\Layout\\Element'; $this->setXml(simplexml_load_string('<layout/>', $this->_elementClass)); $this->_renderingOutput = new \Magento\Framework\Object(); $this->_processorFactory = $processorFactory; $this->_eventManager = $eventManager; $this->structure = $structure; $this->messageManager = $messageManager; $this->themeResolver = $themeResolver; $this->readerPool = $readerPool; $this->generatorPool = $generatorPool; $this->cacheable = $cacheable; $this->cache = $cache; $this->readerContextFactory = $readerContextFactory; $this->generatorContextFactory = $generatorContextFactory; $this->readerContext = $this->readerContextFactory->create(); }