Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/AbstractIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public function rewind()
*/
public function hasChildren()
{
return count($this->children) > 0;
if ($this->valid() && ($this->current() instanceof RecursiveIterator)) {
return true;
}

return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Rbac.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getCreateMissingRoles()
*
* @param string|RoleInterface $child
* @param array|RoleInterface|null $parents
* @return RoleInterface
* @return self
* @throws Exception\InvalidArgumentException
*/
public function addRole($child, $parents = null)
Expand Down
20 changes: 20 additions & 0 deletions test/RbacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,24 @@ public function testAddRoleWithAutomaticParentsUsingRbac()
$this->assertEquals($bar->getParent(), $foo);
$this->assertEquals(1, count($foo->getChildren()));
}

/**
* @tesdox Test adding custom child roles works
*/
public function testAddCustomChildRole()
{
$role = $this->getMockForAbstractClass('Zend\Permissions\Rbac\RoleInterface');
$this->rbac->setCreateMissingRoles(true)->addRole($role, array('parent'));

$role->expects($this->any())
->method('getName')
->will($this->returnValue('customchild'));

$role->expects($this->once())
->method('hasPermission')
->with('test')
->will($this->returnValue(true));

$this->assertTrue($this->rbac->isGranted('parent', 'test'));
}
}

0 comments on commit 6027334

Please sign in to comment.