protected function setUp() { $this->context = new LayoutContext(); $this->registry = new LayoutRegistry(); $this->registry->addExtension(new CoreExtension()); $this->registry->addExtension(new PreloadedExtension(['root' => new Type\RootType(), 'header' => new Type\HeaderType(), 'logo' => new Type\LogoType(), 'test_self_building_container' => new Type\TestSelfBuildingContainerType()])); $this->rawLayoutBuilder = new RawLayoutBuilder(); $this->layoutManipulator = new DeferredLayoutManipulator($this->registry, $this->rawLayoutBuilder); $this->blockFactory = new BlockFactory($this->registry, $this->layoutManipulator); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExtensions() { $testBlockType = $this->getMock('Oro\\Component\\Layout\\Block\\Type\\AbstractType'); $testBlockType->expects($this->any())->method('getName')->will($this->returnValue('test')); $testBlockType->expects($this->any())->method('getParent')->will($this->returnValue(BaseType::NAME)); $headerLayoutUpdate = $this->getMock('Oro\\Component\\Layout\\LayoutUpdateInterface'); $headerLayoutUpdate->expects($this->once())->method('updateLayout')->will($this->returnCallback(function (LayoutManipulatorInterface $layoutManipulator, LayoutItemInterface $item) { $layoutManipulator->add('test', 'header', 'test'); })); $headerBlockTypeExtension = $this->getMock('Oro\\Component\\Layout\\BlockTypeExtensionInterface'); $headerBlockTypeExtension->expects($this->any())->method('getExtendedType')->will($this->returnValue('header')); $headerBlockTypeExtension->expects($this->once())->method('setDefaultOptions')->will($this->returnCallback(function (OptionsResolverInterface $resolver) { $resolver->setDefaults(['test_option' => '']); })); $headerBlockTypeExtension->expects($this->once())->method('buildBlock')->will($this->returnCallback(function (BlockBuilderInterface $builder, array $options) { if ($options['test_option'] === 'move_logo_to_root') { $builder->getLayoutManipulator()->move('logo', 'root'); } })); $headerBlockTypeExtension->expects($this->once())->method('buildView')->will($this->returnCallback(function (BlockView $view, BlockInterface $block, array $options) { $view->vars['attr']['block_id'] = $block->getId(); if ($options['test_option'] === 'move_logo_to_root') { $view->vars['attr']['logo_moved'] = true; } })); $headerBlockTypeExtension->expects($this->once())->method('finishView')->will($this->returnCallback(function (BlockView $view, BlockInterface $block, array $options) { if (isset($view['test'])) { $view['test']->vars['processed_by_header_extension'] = true; } })); $this->registry->addExtension(new AbstractExtensionStub([$testBlockType], [$headerBlockTypeExtension], ['header' => [$headerLayoutUpdate]], [], [])); $this->layoutManipulator->add('root', null, 'root')->add('header', 'root', 'header', ['test_option' => 'move_logo_to_root'])->add('logo', 'header', 'logo', ['title' => 'test']); $view = $this->getLayoutView(); $this->assertBlockView(['vars' => ['id' => 'root'], 'children' => [['vars' => ['id' => 'header', 'attr' => ['block_id' => 'header', 'logo_moved' => true]], 'children' => [['vars' => ['id' => 'test', 'processed_by_header_extension' => true]]]], ['vars' => ['id' => 'logo', 'title' => 'test']]]], $view); }
public function testConfigureContext() { $context = $this->getMock('Oro\\Component\\Layout\\ContextInterface'); $contextConfigurator = $this->getMock('Oro\\Component\\Layout\\ContextConfiguratorInterface'); $this->extension->expects($this->once())->method('hasContextConfigurators')->will($this->returnValue(true)); $this->extension->expects($this->once())->method('getContextConfigurators')->will($this->returnValue([$contextConfigurator])); $contextConfigurator->expects($this->once())->method('configureContext')->with($this->identicalTo($context)); $this->registry->configureContext($context); }
/** * {@inheritdoc} */ public function getLayoutFactory() { // initialize extension manager $registry = new LayoutRegistry(); foreach ($this->extensions as $extension) { $registry->addExtension($extension); } if (!empty($this->types) || !empty($this->typeExtensions) || !empty($this->layoutUpdates)) { $registry->addExtension(new PreloadedExtension($this->types, $this->typeExtensions, $this->layoutUpdates)); } // initialize renderer registry $rendererRegistry = new LayoutRendererRegistry(); $defaultRenderer = $this->defaultRenderer; foreach ($this->renderers as $name => $renderer) { $rendererRegistry->addRenderer($name, $renderer); if (!$defaultRenderer) { $defaultRenderer = $name; } } if ($defaultRenderer) { $rendererRegistry->setDefaultRenderer($defaultRenderer); } return new LayoutFactory($registry, $rendererRegistry); }