public function testExecutionOfDisabledBlock()
 {
     $simpleBlock = new SimpleBlock();
     $simpleBlock->setEnabled(false);
     $templatingMock = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface')->disableOriginalConstructor()->getMock();
     $templatingMock->expects($this->never())->method('renderResponse');
     $simpleBlockService = new SimpleBlockService('test-service', $templatingMock);
     $simpleBlockService->execute(new BlockContext($simpleBlock));
 }
 public function testExecutionOfEnabledBlock()
 {
     $template = 'CmfBlockBundle:Block:block_container.html.twig';
     $simpleBlock1 = new SimpleBlock();
     $simpleBlock1->setId(1);
     $simpleBlock2 = new SimpleBlock();
     $simpleBlock2->setId(2);
     $childrenCollectionMock = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\ChildrenCollection')->disableOriginalConstructor()->getMock();
     $containerBlock = new ContainerBlock('foo');
     $containerBlock->setEnabled(true);
     $containerBlock->setChildren($childrenCollectionMock);
     $settings = array('divisible_by' => 0, 'divisible_class' => '', 'child_class' => '', 'template' => $template);
     $blockContext = new BlockContext($containerBlock, $settings);
     $responseContent1 = 'Rendered Simple Block 1.';
     $responseContent2 = 'Rendered Simple Block 2.';
     $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($responseContent1 . $responseContent2)));
     $containerBlockService = new ContainerBlockService('test-service', $templatingMock, $blockRendererMock);
     $response = $containerBlockService->execute($blockContext);
     $this->assertInstanceof('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals($responseContent1 . $responseContent2, $response->getContent());
 }
Example #3
0
 private function blockCreator($parent, $name, $parentname, ObjectManager $manager)
 {
     $block = $manager->find(null, '/cms/content/blocks/' . $parentname . '/' . $name);
     if (null == $block) {
         $block = new SimpleBlock(array('add_locale_pattern' => true));
         $block->setParentObject($parent);
         $block->setName($name);
         $block->setTitle($this->translator->trans($parentname . '.' . $name . '.title', array(), 'messages', 'da'));
         $block->setBody($this->translator->trans($parentname . '.' . $name . '.body', array(), 'messages', 'da'));
         $manager->persist($block);
         $manager->bindTranslation($block, 'da');
         foreach (array('en', 'de', 'fr', 'es', 'it', 'po') as $locale) {
             $block->setTitle($this->translator->trans($parentname . '.' . $name . '.title', array(), 'messages', $locale));
             $block->setBody($this->translator->trans($parentname . '.' . $name . '.body', array(), 'messages', $locale));
             $manager->bindTranslation($block, $locale);
         }
     }
 }
 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();
 }