public function testExecutionOfBlockWithNoChildren()
 {
     $template = 'CmfBlockBundle:Block:block_container.html.twig';
     $childrenCollectionMock = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\ChildrenCollection')->disableOriginalConstructor()->getMock();
     $containerBlock = new ContainerBlock('foo');
     $containerBlock->setEnabled(true);
     $containerBlock->setChildren($childrenCollectionMock);
     $settings = array('divisibleBy' => 0, 'divisibleClass' => '', 'childClass' => '', 'template' => $template);
     $blockContext = new BlockContext($containerBlock, $settings);
     $blockRendererMock = $this->getMockBuilder('Sonata\\BlockBundle\\Block\\BlockRendererInterface')->disableOriginalConstructor()->getMock();
     $templatingMock = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface')->disableOriginalConstructor()->getMock();
     $templatingMock->expects($this->once())->method('renderResponse')->with($this->equalTo($template), $this->equalTo(array('block' => $containerBlock, 'settings' => $settings)), $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response'))->will($this->returnValue(new Response('')));
     $containerBlockService = new ContainerBlockService('test-service', $templatingMock, $blockRendererMock);
     $response = $containerBlockService->execute($blockContext);
     $this->assertInstanceof('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals('', $response->getContent());
 }
Exemplo n.º 2
0
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     $root = $manager->find(null, '/test');
     $parent = new Generic();
     $parent->setParentDocument($root);
     $parent->setNodename('blocks');
     $manager->persist($parent);
     //Simple
     $block = new SimpleBlock();
     $block->setParentDocument($parent);
     $block->setName('block-1');
     $block->setTitle('block-1-title');
     $block->setBody('block-1-body');
     $manager->persist($block);
     $block = new SimpleBlock();
     $block->setParentDocument($parent);
     $block->setName('block-2');
     $block->setTitle('block-2-title');
     $block->setBody('block-2-body');
     $block->setPublishable(false);
     $manager->persist($block);
     //Action
     $actionBlockOne = new ActionBlock();
     $actionBlockOne->setParentDocument($parent);
     $actionBlockOne->setName('action-block-1');
     $actionBlockOne->setActionName('cmf_block_test.test_controller:dummyAction');
     $actionBlockOne->setPublishable(true);
     $manager->persist($actionBlockOne);
     $actionBlockTwo = new ActionBlock();
     $actionBlockTwo->setParentDocument($parent);
     $actionBlockTwo->setName('action-block-2');
     $actionBlockTwo->setActionName('FooBundle:Bar:actionTwo');
     $actionBlockTwo->setPublishable(false);
     $manager->persist($actionBlockTwo);
     //Container
     $childBlockOne = new SimpleBlock();
     $childBlockOne->setName('block-child-1');
     $childBlockOne->setTitle('block-child-1-title');
     $childBlockOne->setBody('block-child-1-body');
     $containerBlock = new ContainerBlock();
     $containerBlock->setParentDocument($parent);
     $containerBlock->setName('container-block-1');
     $containerBlock->addChild($childBlockOne);
     $manager->persist($containerBlock);
     $block = new ContainerBlock();
     $block->setParentDocument($parent);
     $block->setName('container-block-2');
     $block->setPublishable(false);
     $manager->persist($block);
     //Reference
     $block = new ReferenceBlock();
     $block->setParentDocument($parent);
     $block->setName('reference-block-1');
     $block->setReferencedBlock($actionBlockOne);
     $manager->persist($block);
     $block = new ReferenceBlock();
     $block->setParentDocument($parent);
     $block->setName('reference-block-2');
     $block->setReferencedBlock($actionBlockTwo);
     $block->setPublishable(false);
     $manager->persist($block);
     // Menu Nodes
     NodeHelper::createPath($manager->getPhpcrSession(), '/test/menus');
     $menuRoot = $manager->find(null, '/test/menus');
     $menu = new Menu();
     $menu->setName('test-menu');
     $menu->setLabel('Test Menu');
     $menu->setParentDocument($menuRoot);
     $manager->persist($menu);
     $menuNodeOne = new MenuNode();
     $menuNodeOne->setName('menu-node-1');
     $menuNodeOne->setLabel('menu-node-1');
     $menuNodeOne->setParentDocument($menu);
     $manager->persist($menuNodeOne);
     $menuNodeTwo = new MenuNode();
     $menuNodeTwo->setName('menu-node-2');
     $menuNodeTwo->setLabel('menu-node-2');
     $menuNodeTwo->setParentDocument($menu);
     $manager->persist($menuNodeTwo);
     //Menu
     $block = new MenuBlock();
     $block->setParentDocument($parent);
     $block->setName('menu-block-1');
     $block->setMenuNode($menuNodeOne);
     $manager->persist($block);
     $block = new MenuBlock();
     $block->setParentDocument($parent);
     $block->setName('menu-block-2');
     $block->setMenuNode($menuNodeTwo);
     $block->setPublishable(false);
     $manager->persist($block);
     //String
     $block = new StringBlock();
     $block->setParentDocument($parent);
     $block->setName('string-block-1');
     $block->setBody('string-block-1-body');
     $manager->persist($block);
     $block = new StringBlock();
     $block->setParentDocument($parent);
     $block->setName('string-block-2');
     $block->setBody('string-block-2-body');
     $block->setPublishable(false);
     $manager->persist($block);
     $manager->flush();
 }
 /**
  * Sets default settings for the block.
  *
  * @param string $name
  */
 public function __construct($name = null)
 {
     parent::__construct($name);
     $this->settings = array_merge($this->settings, ['no_padding' => false, "full_width" => false, "per_row" => 1]);
 }
 /**
  * @todo Get missing container blocks
  * @return type
  */
 public function getContainerBlocks()
 {
     // Prepare new container blocks
     if ($this->containerBlocks->count() === 0) {
         foreach ($this->getAllowedContainerBlocks() as $allowedContainerBlock) {
             $containerBlock = new ContainerBlock();
             $containerBlock->setParentDocument($this);
             $containerBlock->setName($allowedContainerBlock['label']);
             $this->containerBlocks->add($containerBlock);
         }
     }
     return $this->containerBlocks;
 }