Permalink
Browse files

Merge branch 'hotfix/3088' into develop

Close #3088
  • Loading branch information...
2 parents 8485e8e + 937e5c2 commit a9b073ef17bf03fc9ae8e9a54187c2f538f490eb @weierophinney weierophinney committed Dec 13, 2012
Showing with 21 additions and 13 deletions.
  1. +3 −7 library/Zend/Permissions/Rbac/AbstractRole.php
  2. +18 −6 tests/ZendTest/Permissions/Rbac/RbacTest.php
@@ -58,7 +58,7 @@ public function addPermission($name)
}
/**
- * Checks if a permission exists for this role or any child roles.
+ * Checks if a permission exists for this role or any parent roles.
*
* @param string $name
* @return bool
@@ -69,12 +69,8 @@ public function hasPermission($name)
return true;
}
- $it = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::CHILD_FIRST);
- foreach ($it as $leaf) {
- /** @var AbstractRole $leaf */
- if ($leaf->hasPermission($name)) {
- return true;
- }
+ if($this->parent && $this->parent->hasPermission($name)) {
+ return true;
}
return false;
@@ -68,7 +68,7 @@ public function testIsGrantedSingleRole()
$this->assertEquals(false, $this->rbac->isGranted('foo', 'can.baz'));
}
- public function testIsGrantedChildRoles()
+ public function testParentRolesNotGrantedChildPermissions()
{
$foo = new Rbac\Role('foo');
$bar = new Rbac\Role('bar');
@@ -79,12 +79,24 @@ public function testIsGrantedChildRoles()
$this->rbac->addRole($foo);
$this->rbac->addRole($bar, $foo);
- $this->assertEquals(true, $this->rbac->isGranted('foo', 'can.bar'));
- $this->assertEquals(true, $this->rbac->isGranted('foo', 'can.foo'));
- $this->assertEquals(true, $this->rbac->isGranted('bar', 'can.bar'));
+ $this->assertFalse($this->rbac->isGranted('foo', 'can.bar'));
+ }
- $this->assertEquals(false, $this->rbac->isGranted('foo', 'can.baz'));
- $this->assertEquals(false, $this->rbac->isGranted('bar', 'can.baz'));
+ /**
+ * @group xxx
+ */
+ public function testChildRolesInheritParentPermissions()
+ {
+ $foo = new Rbac\Role('foo');
+ $bar = new Rbac\Role('bar');
+
+ $foo->addPermission('can.foo');
+ $bar->addPermission('can.bar');
+
+ $this->rbac->addRole($foo);
+ $this->rbac->addRole($bar, $foo);
+
+ $this->assertTrue($this->rbac->isGranted('bar', 'can.foo'));
}
public function testHasRole()

0 comments on commit a9b073e

Please sign in to comment.