public function testGetUrlsafeIdentifier()
 {
     $entity = new \stdClass();
     // set admin to pool
     $this->pool->setAdminClasses(array('stdClass' => array('sonata_admin_foo_service')));
     $this->admin->expects($this->once())->method('getUrlsafeIdentifier')->with($this->equalTo($entity))->will($this->returnValue(1234567));
     $this->assertEquals(1234567, $this->twigExtension->getUrlsafeIdentifier($entity));
 }
 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());
     }
 }