Browse Source

Added tests for GetAdminByAdminCode method from Pool class.

Leszek 13 years ago
parent
commit
9332825f68
1 changed files with 27 additions and 1 deletions
  1. 27 1
      Tests/Admin/PoolTest.php

+ 27 - 1
Tests/Admin/PoolTest.php

@@ -71,7 +71,28 @@ class PoolTest extends \PHPUnit_Framework_TestCase
 
 
     public function testGetAdminByAdminCode()
     public function testGetAdminByAdminCode()
     {
     {
-        $this->assertEquals('adminUserClass', $this->pool->getAdminByAdminCode('sonata.user.admin.group1'));
+        $this->assertEquals('adminUserClass', $this->pool->getAdminByAdminCode('sonata.news.admin.post'));
+    }
+
+    public function testGetAdminByAdminCodeForChildClass()
+    {
+        $adminMock = $this->getMock('Sonata\AdminBundle\Admin', array('hasChild', 'getChild'));
+        $adminMock->expects($this->any())
+            ->method('hasChild')
+            ->will($this->returnValue(true));
+        $adminMock->expects($this->once())
+            ->method('getChild')
+            ->with($this->equalTo('sonata.news.admin.comment'))
+            ->will($this->returnValue('commentAdminClass'));
+
+        $containerMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $containerMock->expects($this->any())
+            ->method('get')
+            ->will($this->returnValue($adminMock));
+
+        $this->pool = new Pool($containerMock);
+
+        $this->assertEquals('commentAdminClass', $this->pool->getAdminByAdminCode('sonata.news.admin.post|sonata.news.admin.comment'));
     }
     }
 
 
     public function testGetAdminClasses()
     public function testGetAdminClasses()
@@ -92,6 +113,11 @@ class PoolTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(array('sonata.user.admin.group1', 'sonata.user.admin.group2'), $this->pool->getAdminServiceIds());
         $this->assertEquals(array('sonata.user.admin.group1', 'sonata.user.admin.group2'), $this->pool->getAdminServiceIds());
     }
     }
 
 
+    public function testGetContainer()
+    {
+        $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerInterface', $this->pool->getContainer());
+    }
+
     /**
     /**
      * @return Symfony\Component\DependencyInjection\ContainerInterface - the mock of container interface
      * @return Symfony\Component\DependencyInjection\ContainerInterface - the mock of container interface
      */
      */