public function testAddParameter() { $userContext = new UserContext(); $userContext->addParameter('authenticated', true); $this->assertTrue($userContext->hasParameter('authenticated')); $parameters = $userContext->getParameters(); $this->assertEquals(true, $parameters['authenticated']); }
public function testSetIdentity() { $user = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\User'); $userContext = new UserContext(); $this->repositoryMock->expects($this->once())->method('getCurrentUser')->will($this->returnValue($user)); $roleId1 = 123; $roleId2 = 456; $roleId3 = 789; $limitationForRole2 = $this->generateLimitationMock(array('limitationValues' => array('/1/2', '/1/2/43'))); $limitationForRole3 = $this->generateLimitationMock(array('limitationValues' => array('foo', 'bar'))); $returnedRoleAssignments = array($this->generateRoleAssignmentMock(array('role' => $this->generateRoleMock(array('id' => $roleId1)))), $this->generateRoleAssignmentMock(array('role' => $this->generateRoleMock(array('id' => $roleId2)), 'limitation' => $limitationForRole2)), $this->generateRoleAssignmentMock(array('role' => $this->generateRoleMock(array('id' => $roleId3)), 'limitation' => $limitationForRole3))); $this->roleServiceMock->expects($this->once())->method('getRoleAssignmentsForUser')->with($user, true)->will($this->returnValue($returnedRoleAssignments)); $this->assertSame(array(), $userContext->getParameters()); $contextProvider = new RoleContextProvider($this->repositoryMock); $contextProvider->updateUserContext($userContext); $userContextParams = $userContext->getParameters(); $this->assertArrayHasKey('roleIdList', $userContextParams); $this->assertSame(array($roleId1, $roleId2, $roleId3), $userContextParams['roleIdList']); $this->assertArrayHasKey('roleLimitationList', $userContextParams); $limitationIdentifierForRole2 = get_class($limitationForRole2); $limitationIdentifierForRole3 = get_class($limitationForRole3); $this->assertSame(array("{$roleId2}-{$limitationIdentifierForRole2}" => array('/1/2', '/1/2/43'), "{$roleId3}-{$limitationIdentifierForRole3}" => array('foo', 'bar')), $userContextParams['roleLimitationList']); }