Exemplo n.º 1
0
 public function testGetDashboardGroups()
 {
     $admin_group1 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
     $admin_group1->expects($this->once())->method('showIn')->will($this->returnValue(true));
     $admin_group2 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
     $admin_group2->expects($this->once())->method('showIn')->will($this->returnValue(false));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->any())->method('get')->will($this->onConsecutiveCalls($admin_group1, $admin_group2));
     $pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png');
     $pool->setAdminGroups(array('adminGroup1' => array('items' => array('itemKey' => 'sonata.user.admin.group1')), 'adminGroup2' => array('itmes' => array('itemKey' => 'sonata.user.admin.group1')), 'adminGroup3' => array('items' => array('itemKey' => 'sonata.user.admin.group2'))));
     $groups = $pool->getDashboardGroups();
     $this->assertCount(1, $groups);
 }
 public function testGetKnpMenuWithNotGrantedList()
 {
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $adminGroups = array('bar' => array('label' => 'foo', 'icon' => '<i class="fa fa-edit"></i>', 'label_catalogue' => 'SonataAdminBundle', 'items' => array(array('admin' => 'sonata_admin_foo_service', 'label' => 'fooLabel')), 'item_adds' => array(), 'roles' => array()));
     $this->pool->setAdminGroups($adminGroups);
     $this->admin->expects($this->once())->method('hasRoute')->with($this->equalTo('list'))->will($this->returnValue(true));
     $this->admin->expects($this->any())->method('isGranted')->with($this->equalTo('LIST'))->will($this->returnValue(false));
     $menu = $this->twigExtension->getKnpMenu($request);
     $this->assertInstanceOf('Knp\\Menu\\ItemInterface', $menu);
     $this->assertArrayHasKey('bar', $menu->getChildren());
     foreach ($menu->getChildren() as $key => $child) {
         $this->assertInstanceOf('Knp\\Menu\\MenuItem', $child);
         $this->assertEquals('bar', $child->getName());
         $this->assertEquals($adminGroups['bar']['label'], $child->getLabel());
         // menu items
         $children = $child->getChildren();
         $this->assertCount(0, $children);
     }
 }
 public function testGetKnpMenuWithProvider()
 {
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $adminGroups = array("bar" => array("provider" => 'my_menu', "label_catalogue" => '', "icon" => '<i class="fa fa-edit"></i>', "roles" => array()));
     $this->pool->setAdminGroups($adminGroups);
     $menu = $this->twigExtension->getKnpMenu($request);
     $this->assertInstanceOf('Knp\\Menu\\ItemInterface', $menu);
     $this->assertArrayHasKey('bar', $menu->getChildren());
     foreach ($menu->getChildren() as $key => $child) {
         $this->assertInstanceOf('Knp\\Menu\\MenuItem', $child);
         $this->assertEquals("bar", $child->getName());
         $this->assertEquals("bar", $child->getLabel());
         // menu items
         $children = $child->getChildren();
         $this->assertCount(1, $children);
         $this->assertArrayHasKey('foo', $children);
         $this->assertInstanceOf('Knp\\Menu\\MenuItem', $child['foo']);
         $this->assertEquals('foo', $child['foo']->getLabel());
     }
 }
Exemplo n.º 4
0
 public function testGetAdminGroups()
 {
     $this->pool->setAdminGroups(array('adminGroup1' => 'sonata.user.admin.group1'));
     $this->assertEquals(array('adminGroup1' => 'sonata.user.admin.group1'), $this->pool->getAdminGroups());
 }