public function testCreateBlockSuccess() { $blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass(); $this->_blockFactoryMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock)); $this->_model->createBlock('type', 'blockname', array()); $this->assertInstanceOf('Magento\\Framework\\View\\Element\\AbstractBlock', $this->_model->getBlock('blockname')); }
public function testCreateBlockSuccess() { $blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass(); $this->structureMock->expects($this->once())->method('createStructuralElement')->with('blockname', \Magento\Framework\View\Layout\Element::TYPE_BLOCK, 'type')->willReturn('blockname'); $this->generatorBlockMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock)); $this->model->createBlock('type', 'blockname', []); $this->assertInstanceOf('Magento\\Framework\\View\\Element\\AbstractBlock', $this->model->getBlock('blockname')); $this->assertFalse($this->model->getBlock('not_exist')); }
public function testGetBlock() { $this->assertFalse($this->_layout->getBlock('test')); $block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\Layout')->createBlock('Magento\\Framework\\View\\Element\\Text'); $this->_layout->setBlock('test', $block); $this->assertSame($block, $this->_layout->getBlock('test')); }
public function getBlockExtras($name, $data) { if (isset($data['type'])) { $extras[] = $data['type']; } $block = $this->_layout->getBlock($name); if ($block) { if ($block instanceof \Magento\Cms\Block\Block) { $extras[] = $block->getBlockId(); } if ($block instanceof \Magento\Cms\Block\Page) { $extras[] = $block->getPage()->getIdentifier(); } if ($block instanceof \Magento\Framework\View\Element\Template) { $extras[] = $block->getTemplate(); } $extras[] = $block->getType(); } return $extras; }
protected function buildEntries(MagentoLayout $layout, &$structure, $name = 'root', $alias = '', $level = 0) { if (!isset($structure[$name])) { return []; } $instance = $layout->getBlock($name); $block = $structure[$name]; $entries = []; $entries[] = ['level' => $level, 'name' => $name, 'alias' => $alias, 'type' => $block['type'], 'label' => isset($block['label']) ? $block['label'] : '', 'extra' => array_filter(['htmlTag' => isset($block['htmlTag']) ? $block['htmlTag'] : '', 'htmlId' => isset($block['htmlId']) ? $block['htmlId'] : '', 'htmlClass' => isset($block['htmlClass']) ? $block['htmlClass'] : '', 'template' => $instance ? $instance->getTemplate() : ''])]; if (isset($block['children'])) { foreach ($block['children'] as $child => $alias) { $entries = array_merge($entries, $this->buildEntries($layout, $structure, $child, $alias, $level + 1)); } } return $entries; }
/** * {@inheritdoc} */ public function getBlock($name) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getBlock'); if (!$pluginInfo) { return parent::getBlock($name); } else { return $this->___callPlugins('getBlock', func_get_args(), $pluginInfo); } }