コード例 #1
0
ファイル: AdminTest.php プロジェクト: drmjo/SonataAdminBundle
 /**
  * @covers Sonata\AdminBundle\Admin\Admin::hasChild
  * @covers Sonata\AdminBundle\Admin\Admin::addChild
  * @covers Sonata\AdminBundle\Admin\Admin::getChild
  * @covers Sonata\AdminBundle\Admin\Admin::isChild
  * @covers Sonata\AdminBundle\Admin\Admin::hasChildren
  * @covers Sonata\AdminBundle\Admin\Admin::getChildren
  */
 public function testChildren()
 {
     $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\\Sonata\\NewsBundle\\Entity\\Post', 'SonataNewsBundle:PostAdmin');
     $this->assertFalse($postAdmin->hasChildren());
     $this->assertFalse($postAdmin->hasChild('comment'));
     $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\\Sonata\\NewsBundle\\Entity\\Comment', 'SonataNewsBundle:CommentAdmin');
     $postAdmin->addChild($commentAdmin);
     $this->assertTrue($postAdmin->hasChildren());
     $this->assertTrue($postAdmin->hasChild('sonata.post.admin.comment'));
     $this->assertSame('sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getCode());
     $this->assertSame('sonata.post.admin.post|sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getBaseCodeRoute());
     $this->assertSame($postAdmin, $postAdmin->getChild('sonata.post.admin.comment')->getParent());
     $this->assertFalse($postAdmin->isChild());
     $this->assertTrue($commentAdmin->isChild());
     $this->assertSame(array('sonata.post.admin.comment' => $commentAdmin), $postAdmin->getChildren());
 }
コード例 #2
0
 /**
  * @dataProvider provideGetBaseRouteName
  */
 public function testGetBaseRouteNameWithChildAdmin($objFqn, $expected)
 {
     $routeGenerator = new DefaultRouteGenerator($this->getMock('Symfony\\Component\\Routing\\RouterInterface'), new RoutesCache($this->cacheTempFolder, true));
     $pathInfo = new \Sonata\AdminBundle\Route\PathInfoBuilder($this->getMock('Sonata\\AdminBundle\\Model\\AuditManagerInterface'));
     $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
     $postAdmin->setRouteBuilder($pathInfo);
     $postAdmin->setRouteGenerator($routeGenerator);
     $postAdmin->initialize();
     $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\\Sonata\\NewsBundle\\Entity\\Comment', 'SonataNewsBundle:CommentAdmin');
     $commentAdmin->setRouteBuilder($pathInfo);
     $commentAdmin->setRouteGenerator($routeGenerator);
     $commentAdmin->initialize();
     $postAdmin->addChild($commentAdmin);
     $this->assertSame($expected . '_comment', $commentAdmin->getBaseRouteName());
     $this->assertTrue($postAdmin->hasRoute('show'));
     $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post.show'));
     $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.show'));
     $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment.list'));
     $this->assertFalse($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.edit'));
     $this->assertFalse($commentAdmin->hasRoute('edit'));
 }