/**
  * @dataProvider grantedProvider
  */
 public function testGranted($role, $permission, $context, $isGranted, $assertions = [])
 {
     $roleConfig = ['admin' => ['children' => ['member'], 'permissions' => ['delete']], 'member' => ['children' => ['guest'], 'permissions' => ['write']], 'guest' => ['permissions' => ['read']]];
     $assertionPluginConfig = ['invokables' => ['ZfcRbacTest\\Asset\\SimpleAssertion' => 'ZfcRbacTest\\Asset\\SimpleAssertion']];
     $identity = $this->getMock('ZfcRbac\\Identity\\IdentityInterface');
     $identity->expects($this->once())->method('getRoles')->will($this->returnValue((array) $role));
     $identityProvider = $this->getMock('ZfcRbac\\Identity\\IdentityProviderInterface');
     $identityProvider->expects($this->any())->method('getIdentity')->will($this->returnValue($identity));
     $rbac = new Rbac(new RecursiveRoleIteratorStrategy());
     $roleService = new RoleService($identityProvider, new InMemoryRoleProvider($roleConfig), $rbac->getTraversalStrategy());
     $assertionPluginManager = new AssertionPluginManager(new ServiceManager(), $assertionPluginConfig);
     $authorizationService = new AuthorizationService($rbac, $roleService, $assertionPluginManager);
     $authorizationService->setAssertions($assertions);
     $this->assertEquals($isGranted, $authorizationService->isGranted($permission, $context));
 }
Exemple #2
0
 public function testGetTraversalStrategy()
 {
     $customStrategy = $this->getMock('Rbac\\Traversal\\Strategy\\TraversalStrategyInterface');
     $rbac = new Rbac($customStrategy);
     $this->assertSame($customStrategy, $rbac->getTraversalStrategy());
 }