/** * 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'); }
/** * Returns Sonata route page generator service * * @return RoutePageGenerator */ protected function getRoutePageGenerator() { $router = $this->getRouterMock(); $pageManager = $this->getMockBuilder('Sonata\\PageBundle\\Entity\\PageManager')->disableOriginalConstructor()->getMock(); $pageManager->expects($this->any())->method('create')->will($this->returnValue(new Page())); $hybridPage = new Page(); $hybridPage->setRouteName('test_hybrid_page_not_exists'); $pageManager->expects($this->any())->method('getHybridPages')->will($this->returnValue(array($hybridPage))); $decoratorStrategy = new DecoratorStrategy(array(), array(), array()); $exceptionListener = $this->getMockBuilder('Sonata\\PageBundle\\Listener\\ExceptionListener')->disableOriginalConstructor()->getMock(); $exceptionListener->expects($this->any())->method('getHttpErrorCodes')->will($this->returnValue(array(404, 500))); return new RoutePageGenerator($router, $pageManager, $decoratorStrategy, $exceptionListener); }
public function testWithSlashAtTheEnd() { $entityManager = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry', array(), array(), '', false); $manager = new PageManager('Foo\\Bar', $entityManager, array()); $homepage = new Page(); $homepage->setUrl('/'); $homepage->setName('homepage'); $bundle = new Page(); $bundle->setUrl('/bundles/'); $bundle->setName('Bundles'); $child = new Page(); $child->setName('foobar'); $bundle->addChildren($child); $homepage->addChildren($bundle); $manager->fixUrl($child); $this->assertEquals('/bundles/foobar', $child->getUrl()); }
public function loadPages() { $pages = array(); $i = 1; $pageAll = new Page(); $pageAll->setId($i); $pageAll->setRequestMethod(''); $pageAll->setRouteName('all'); $pageAll->setUrl('/all'); $pages[$i++] = $pageAll; $pagePost = new Page(); $pagePost->setId($i); $pagePost->setRequestMethod('POST'); $pagePost->setRouteName('post'); $pagePost->setUrl('/post'); $pagePost->setParent($pageAll); $pages[$i++] = $pagePost; $pageGet = new Page(); $pageGet->setId($i); $pageGet->setRequestMethod('GET'); $pageGet->setRouteName('get'); $pageGet->setUrl('/get'); $pageGet->setParent($pageAll); $pages[$i++] = $pageGet; $page = new Page(); $page->setId($i); $page->setRequestMethod('GET|POST'); $page->setRouteName('get-post'); $page->setUrl('/get-post'); $page->setParent($pageAll); $pages[$i++] = $page; return $pages; }
public function testFixUrl() { $manager = new PageManager($this->getMock('Doctrine\\ORM\\EntityManager', array(), array(), '', false)); $page1 = new Page(); $page1->setName('Salut comment ca va ?'); $page2 = new Page(); $page2->setName('Super! et toi ?'); $page1->addChildren($page2); $manager->fixUrl($page1); $this->assertEquals($page1->getSlug(), 'salut-comment-ca-va'); $this->assertEquals($page1->getUrl(), '/salut-comment-ca-va'); $parent = new Page(); $parent->setRouteName('homepage'); $parent->addChildren($page1); $manager->fixUrl($parent); $this->assertEquals($parent->getSlug(), null); // homepage is a specific route name $this->assertEquals($parent->getUrl(), '/'); $this->assertEquals($page1->getSlug(), 'salut-comment-ca-va'); $this->assertEquals($page1->getUrl(), '/salut-comment-ca-va'); $this->assertEquals($page2->getSlug(), 'super-et-toi'); $this->assertEquals($page2->getUrl(), '/salut-comment-ca-va/super-et-toi'); }
public function setUp() { $pages = array(); $i = 1; $this->site = new Site(); $pageAll = new Page(); $pageAll->setId($i); $pageAll->setRequestMethod(''); $pageAll->setRouteName('all'); $pageAll->setUrl('/all'); $pageAll->setSite($this->site); $pages[$i++] = $pageAll; $pagePost = new Page(); $pagePost->setId($i); $pagePost->setRequestMethod('POST'); $pagePost->setRouteName('post'); $pagePost->setUrl('/post'); $pagePost->setParent($pageAll); $pagePost->setSite($this->site); $pages[$i++] = $pagePost; $pageGet = new Page(); $pageGet->setId($i); $pageGet->setRequestMethod('GET'); $pageGet->setRouteName('get'); $pageGet->setUrl('/get'); $pageGet->setParent($pageAll); $pageGet->setSite($this->site); $pages[$i++] = $pageGet; $page = new Page(); $page->setId($i); $page->setRequestMethod('GET|POST'); $page->setRouteName('get-post'); $page->setUrl('/get-post'); $page->setParent($pageAll); $page->setSite($this->site); $pages[$i++] = $page; $this->pages = $pages; }
/** * Returns Sonata route page generator service * * @return RoutePageGenerator */ protected function getRoutePageGenerator() { $router = $this->getRouterMock(); $pageManager = $this->getMockBuilder('Sonata\\PageBundle\\Entity\\PageManager')->disableOriginalConstructor()->getMock(); $pageManager->expects($this->any())->method('create')->will($this->returnValue(new Page())); $hybridPageNotExists = new Page(); $hybridPageNotExists->setRouteName('test_hybrid_page_not_exists'); $hybridPageWithGoodHost = new Page(); $hybridPageWithGoodHost->setRouteName('test_hybrid_page_with_good_host'); $hybridPageWithBadHost = new Page(); $hybridPageWithBadHost->setRouteName('test_hybrid_page_with_bad_host'); $pageManager->expects($this->at(12))->method('findOneBy')->with($this->equalTo(array('routeName' => 'test_hybrid_page_with_bad_host', 'site' => 1)))->will($this->returnValue($hybridPageWithBadHost)); $pageManager->expects($this->any())->method('getHybridPages')->will($this->returnValue(array($hybridPageNotExists, $hybridPageWithGoodHost, $hybridPageWithBadHost))); $decoratorStrategy = new DecoratorStrategy(array(), array(), array()); $exceptionListener = $this->getMockBuilder('Sonata\\PageBundle\\Listener\\ExceptionListener')->disableOriginalConstructor()->getMock(); $exceptionListener->expects($this->any())->method('getHttpErrorCodes')->will($this->returnValue(array(404, 500))); return new RoutePageGenerator($router, $pageManager, $decoratorStrategy, $exceptionListener); }
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')); }