/** * @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); }
/** * @param string|null $rootId * * @return BlockView */ protected function getLayoutView($rootId = null) { $this->layoutManipulator->applyChanges($this->context, true); $rawLayout = $this->rawLayoutBuilder->getRawLayout(); return $this->blockFactory->createBlockView($rawLayout, $this->context, $rootId); }