Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 /**
  * 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__);
 }