Browse Source

Update unit test

Thomas Rabaix 13 years ago
parent
commit
661a7b47b5
3 changed files with 27 additions and 8 deletions
  1. 2 0
      Admin/AdminInterface.php
  2. 1 0
      Admin/Pool.php
  3. 24 8
      Tests/Admin/PoolTest.php

+ 2 - 0
Admin/AdminInterface.php

@@ -395,4 +395,6 @@ interface AdminInterface
     function preRemove($object);
 
     function postRemove($object);
+
+    function showIn($context);
 }

+ 1 - 0
Admin/Pool.php

@@ -66,6 +66,7 @@ class Pool
             if (isset($adminGroup['items'])) {
                 foreach ($adminGroup['items'] as $key => $id) {
                     $admin = $this->getInstance($id);
+
                     if ($admin->showIn(Admin::CONTEXT_DASHBOARD)) {
                         $groups[$name]['items'][$key] = $admin;
                     } else {

+ 24 - 8
Tests/Admin/PoolTest.php

@@ -42,20 +42,36 @@ class PoolTest extends \PHPUnit_Framework_TestCase
 
     public function testGetDashboardGroups()
     {
-        $this->pool->setAdminGroups(array(
+
+        $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()
+            'adminGroup2' => array(
+                'itmes' => array('itemKey' => 'sonata.user.admin.group1')
+            ),
+            'adminGroup3' => array(
+                'items' => array('itemKey' => 'sonata.user.admin.group2')
+            ),
         ));
 
-        $expectedOutput = array(
-            'adminGroup1' => array(
-                'items' => array('itemKey' => 'adminUserClass')
-            )
-        );
+        $groups = $pool->getDashboardGroups();
 
-        $this->assertEquals($expectedOutput, $this->pool->getDashboardGroups());
+        $this->assertCount(1, $groups);
     }
 
     public function testGetAdminForClassWhenAdminClassIsNotSet()