public function setUp() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $layoutFactory = $objectManager->get('Magento\\Framework\\View\\LayoutFactory'); $this->layout = $layoutFactory->create(); $layoutElement = new \Magento\Framework\View\Layout\Element(__DIR__ . '/_files/layout_with_exceptions/layout.xml', 0, true); $this->layout->setXml($layoutElement); $objectManager->get('Magento\\Framework\\App\\Cache\\Type\\Layout')->clean(); }
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 testIsNonCacheable() { $this->_layout->setXml(simplexml_load_file(__DIR__ . '/_files/layout/non_cacheable.xml', 'Magento\\Framework\\View\\Layout\\Element')); $this->_layout->generateElements(); $this->assertFalse($this->_layout->isCacheable()); }
/** * @param string $xmlString * @param bool $result * @dataProvider isCacheableDataProvider */ public function testIsCacheable($xmlString, $result) { $xml = simplexml_load_string($xmlString, 'Magento\\Framework\\View\\Layout\\Element'); $this->assertSame($this->model, $this->model->setXml($xml)); $this->assertSame($result, $this->model->isCacheable()); }
/** * {@inheritdoc} */ public function setXml(\Magento\Framework\Simplexml\Element $node) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'setXml'); if (!$pluginInfo) { return parent::setXml($node); } else { return $this->___callPlugins('setXml', func_get_args(), $pluginInfo); } }