示例#1
0
 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);
 }
示例#2
0
 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();
 }