Sfoglia il codice sorgente

ZF-5700: apply patch to fix warning in Zend_Acl when allowing all roles access to resource

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18284 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 anni fa
parent
commit
ef4b23994c
2 ha cambiato i file con 27 aggiunte e 4 eliminazioni
  1. 5 3
      library/Zend/Acl.php
  2. 22 1
      tests/Zend/Acl/AclTest.php

+ 5 - 3
library/Zend/Acl.php

@@ -218,9 +218,11 @@ class Zend_Acl
             }
         }
         foreach ($this->_rules['byResourceId'] as $resourceIdCurrent => $visitor) {
-            foreach ($visitor['byRoleId'] as $roleIdCurrent => $rules) {
-                if ($roleId === $roleIdCurrent) {
-                    unset($this->_rules['byResourceId'][$resourceIdCurrent]['byRoleId'][$roleIdCurrent]);
+            if (array_key_exists('byRoleId', $visitor)) {
+                foreach ($visitor['byRoleId'] as $roleIdCurrent => $rules) {
+                    if ($roleId === $roleIdCurrent) {
+                        unset($this->_rules['byResourceId'][$resourceIdCurrent]['byRoleId'][$roleIdCurrent]);
+                    }
                 }
             }
         }

+ 22 - 1
tests/Zend/Acl/AclTest.php

@@ -1210,6 +1210,27 @@ class Zend_Acl_AclTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(is_array($roles));
         $this->assertFalse(empty($roles));
     }
-}
 
+    /**
+     * Confirm that deleting a role after allowing access to all roles
+     * raise undefined index error
+     *
+     * @group ZF-5700
+     */
+    public function testRemovingRoleAfterItWasAllowedAccessToAllResourcesGivesError()
+    {
+        $acl = new Zend_Acl();
+        $acl->addRole(new Zend_Acl_Role('test0'));
+        $acl->addRole(new Zend_Acl_Role('test1'));
+        $acl->addRole(new Zend_Acl_Role('test2'));
+        $acl->addResource(new Zend_Acl_Resource('Test'));
 
+        $acl->allow(null,'Test','xxx');
+
+        // error test
+        $acl->removeRole('test0');
+
+        // Check after fix
+        $this->assertFalse($acl->hasRole('test0'));
+    }
+}