/**
  * Test finding an existing container in a page
  */
 public function testFindExistingContainer()
 {
     $block = new SnapshotBlock();
     $block->setSettings(array('code' => 'findme'));
     $page = new Page();
     $page->addBlocks($block);
     $container = $this->manager->findContainer('findme', $page);
     $this->assertEquals(spl_object_hash($block), spl_object_hash($container), 'should retrieve the block of the page');
 }
Example #2
0
 public function testGetBlockByType()
 {
     $page = new Page();
     $block1 = $this->getMockBuilder('Sonata\\PageBundle\\Model\\Block')->getMock();
     $block1->expects($this->once())->method('getType')->will($this->returnValue('sonata.page.block.action'));
     $block2 = $this->getMockBuilder('Sonata\\PageBundle\\Model\\Block')->getMock();
     $block2->expects($this->once())->method('getType')->will($this->returnValue('sonata.page.block.container'));
     $block3 = $this->getMockBuilder('Sonata\\PageBundle\\Model\\Block')->getMock();
     $block3->expects($this->once())->method('getType')->will($this->returnValue('sonata.page.block.action'));
     $page->addBlocks($block1);
     $page->addBlocks($block2);
     $page->addBlocks($block3);
     $types = $page->getBlocksByType('sonata.page.block.action');
     $this->assertEquals(2, count($types));
 }
 public function testfindContainer()
 {
     $blockManager = $this->getMock('Sonata\\PageBundle\\Model\\BlockManagerInterface');
     $blockManager = $this->getManager()->getBlockManager();
     $blockManager->expects($this->once())->method('createNewContainer')->will($this->returnCallback(function ($options) {
         $block = new Block();
         $block->setSettings($options);
         return $block;
     }));
     $blockManager->expects($this->once())->method('save')->will($this->returnValue(true));
     $pageManager = $this->getMock('Sonata\\PageBundle\\Model\\PageManagerInterface');
     $templating = $this->getMock('Symfony\\Component\\Templating\\EngineInterface');
     $cacheInvalidation = $this->getMock('Sonata\\PageBundle\\Cache\\Invalidation\\InvalidationInterface');
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $manager = new CmsPageManager($templating, $cacheInvalidation, $router, array('not_found' => array('404'), 'fatal' => array('500')), $pageManager, $blockManager);
     $block = new Block();
     $block->setSettings(array('name' => 'findme'));
     $page = new Page();
     $page->addBlocks($block);
     $container = $manager->findContainer('findme', $page);
     $this->assertEquals(spl_object_hash($block), spl_object_hash($container));
     $container = $manager->findContainer('newcontainer', $page);
     $this->assertEquals('newcontainer', $container->getSetting('name'));
 }