Set an assertion
public function testAssertionMap() { $rbac = $this->getMock('Rbac\\Rbac', [], [], '', false); $roleService = $this->getMock('ZfcRbac\\Service\\RoleService', [], [], '', false); $assertionPluginManager = $this->getMock('ZfcRbac\\Assertion\\AssertionPluginManager', [], [], '', false); $authorizationService = new AuthorizationService($rbac, $roleService, $assertionPluginManager); $authorizationService->setAssertions(['foo' => 'bar', 'bar' => 'foo']); $this->assertTrue($authorizationService->hasAssertion('foo')); $this->assertTrue($authorizationService->hasAssertion('bar')); $authorizationService->setAssertion('bar', null); $this->assertFalse($authorizationService->hasAssertion('bar')); }
public function testThrowExceptionForInvalidAssertionCondition() { $role = $this->getMock('Rbac\\Role\\RoleInterface'); $rbac = $this->getMock('Rbac\\Rbac', [], [], '', false); $rbac->expects($this->once())->method('isGranted')->will($this->returnValue(true)); $roleService = $this->getMock('ZfcRbac\\Service\\RoleService', [], [], '', false); $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue([$role])); $assertionPluginManager = $this->getMock('ZfcRbac\\Assertion\\AssertionPluginManager', [], [], '', false); $authorizationService = new AuthorizationService($rbac, $roleService, $assertionPluginManager); $this->setExpectedException('ZfcRbac\\Exception\\InvalidArgumentException'); $authorizationService->setAssertion('foo', ['assertions' => 'bar', 'condition' => new \stdClass()]); $authorizationService->isGranted('foo'); }