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

Commit

Permalink
Merge pull request #171 from danizord/hotfix/fix-tests
Browse files Browse the repository at this point in the history
Fix failing tests
  • Loading branch information
bakura10 committed Jan 13, 2014
2 parents 136380a + 3934e41 commit 962cd3a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/ZfcRbac/Collector/RbacCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Rbac\Role\HierarchicalRoleInterface;
use Rbac\Role\RoleInterface;
use Rbac\Traversal\RecursiveRoleIterator;
use RecursiveIteratorIterator;
use ReflectionProperty;
use Serializable;
Expand Down Expand Up @@ -157,7 +158,10 @@ private function collectIdentityRolesAndPermissions(RoleService $roleService)
if (!$role instanceof HierarchicalRoleInterface) {
$this->collectedRoles[] = $roleName;
} else {
$iteratorIterator = new RecursiveIteratorIterator($role, RecursiveIteratorIterator::SELF_FIRST);
$iteratorIterator = new RecursiveIteratorIterator(
new RecursiveRoleIterator($role->getChildren()),
RecursiveIteratorIterator::SELF_FIRST
);

foreach ($iteratorIterator as $childRole) {
$this->collectedRoles[$roleName][] = $childRole->getName();
Expand Down
3 changes: 2 additions & 1 deletion tests/ZfcRbacTest/Collector/RbacCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use ZfcRbac\Options\ModuleOptions;
use ZfcRbac\Role\InMemoryRoleProvider;
use ZfcRbac\Service\RoleService;
use Rbac\Traversal\Strategy\RecursiveRoleIteratorStrategy;

/**
* @covers \ZfcRbac\Collector\RbacCollector
Expand Down Expand Up @@ -130,7 +131,7 @@ public function testCanCollect()
->method('getIdentity')
->will($this->returnValue($identity));

$roleService = new RoleService($identityProvider, new InMemoryRoleProvider($dataToCollect['role_config']));
$roleService = new RoleService($identityProvider, new InMemoryRoleProvider($dataToCollect['role_config']), new RecursiveRoleIteratorStrategy());

$serviceManager->expects($this->at(0))
->method('get')
Expand Down
7 changes: 4 additions & 3 deletions tests/ZfcRbacTest/Guard/ControllerGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ZfcRbac\Guard\GuardInterface;
use ZfcRbac\Role\InMemoryRoleProvider;
use ZfcRbac\Service\RoleService;
use Rbac\Traversal\Strategy\RecursiveRoleIteratorStrategy;

/**
* @covers \ZfcRbac\Guard\AbstractGuard
Expand Down Expand Up @@ -424,7 +425,7 @@ public function testControllerGranted(
->will($this->returnValue($identity));

$roleProvider = new InMemoryRoleProvider($rolesConfig);
$roleService = new RoleService($identityProvider, $roleProvider);
$roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());

$controllerGuard = new ControllerGuard($roleService, $rules);
$controllerGuard->setProtectionPolicy($protectionPolicy);
Expand Down Expand Up @@ -461,7 +462,7 @@ public function testProperlyFillEventOnAuthorization()
'member'
]);

$roleService = new RoleService($identityProvider, $roleProvider);
$roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());

$routeGuard = new ControllerGuard($roleService, [[
'controller' => 'MyController',
Expand Down Expand Up @@ -506,7 +507,7 @@ public function testProperlySetUnauthorizedAndTriggerEventOnUnauthorization()
'member'
]);

$roleService = new RoleService($identityProvider, $roleProvider);
$roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());

$routeGuard = new ControllerGuard($roleService, [[
'controller' => 'MyController',
Expand Down
7 changes: 4 additions & 3 deletions tests/ZfcRbacTest/Guard/RouteGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use ZfcRbac\Guard\RouteGuard;
use ZfcRbac\Role\InMemoryRoleProvider;
use ZfcRbac\Service\RoleService;
use Rbac\Traversal\Strategy\RecursiveRoleIteratorStrategy;

/**
* @covers \ZfcRbac\Guard\AbstractGuard
Expand Down Expand Up @@ -378,7 +379,7 @@ public function testRouteGranted(
->will($this->returnValue($identity));

$roleProvider = new InMemoryRoleProvider($rolesConfig);
$roleService = new RoleService($identityProvider, $roleProvider);
$roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());

$routeGuard = new RouteGuard($roleService, $rules);
$routeGuard->setProtectionPolicy($protectionPolicy);
Expand Down Expand Up @@ -411,7 +412,7 @@ public function testProperlyFillEventOnAuthorization()
->will($this->returnValue($identity));

$roleProvider = new InMemoryRoleProvider(['member']);
$roleService = new RoleService($identityProvider, $roleProvider);
$roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());

$routeGuard = new RouteGuard($roleService, [
'adminRoute' => 'member'
Expand Down Expand Up @@ -449,7 +450,7 @@ public function testProperlySetUnauthorizedAndTriggerEventOnUnauthorization()
->will($this->returnValue('member'));

$roleProvider = new InMemoryRoleProvider(['member', 'guest']);
$roleService = new RoleService($identityProvider, $roleProvider);
$roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy());

$routeGuard = new RouteGuard($roleService, [
'adminRoute' => 'guest'
Expand Down
7 changes: 6 additions & 1 deletion tests/ZfcRbacTest/Role/ObjectRepositoryRoleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace ZfcRbacTest\Role;

use Doctrine\ORM\Tools\SchemaTool;
use Rbac\Traversal\RecursiveRoleIterator;
use Zend\ServiceManager\ServiceManager;
use ZfcRbac\Role\ObjectRepositoryRoleProvider;
use ZfcRbacTest\Asset\FlatRole;
Expand Down Expand Up @@ -95,7 +96,11 @@ public function testObjectRepositoryProviderForHierarchicalRole()
$this->assertInstanceOf('Rbac\Role\HierarchicalRoleInterface', $roles[0]);
$this->assertEquals('admin', $roles[0]->getName());

$iteratorIterator = new \RecursiveIteratorIterator($roles[0], \RecursiveIteratorIterator::SELF_FIRST);
$iteratorIterator = new \RecursiveIteratorIterator(
new RecursiveRoleIterator($roles[0]->getChildren()),
\RecursiveIteratorIterator::SELF_FIRST
);

$childRolesString = '';

foreach ($iteratorIterator as $childRole) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ZfcRbacTest/Service/AuthorizationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function testGranted($role, $permission, $context = null, $isGranted, $as
->will($this->returnValue($identity));

$rbac = new Rbac(new RecursiveRoleIteratorStrategy());
$roleService = new RoleService($identityProvider, new InMemoryRoleProvider($roleConfig));
$roleService = new RoleService($identityProvider, new InMemoryRoleProvider($roleConfig), $rbac->getTraversalStrategy());
$assertionPluginManager = new AssertionPluginManager(new Config($assertionPluginConfig));
$authorizationService = new AuthorizationService($rbac, $roleService, $assertionPluginManager);

Expand Down

0 comments on commit 962cd3a

Please sign in to comment.