/** * Test finding an non-existing container in a page does create a new block */ public function testFindNonExistingContainerCreatesNewBlock() { $page = new Page(); $container = $this->manager->findContainer('newcontainer', $page); $this->assertInstanceOf('Sonata\\PageBundle\\Model\\PageBlockInterface', $container, 'should be a block'); $this->assertEquals('newcontainer', $container->getSetting('code')); }
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')); }