public function testGetUserRoleManagerExistingClass() { $configDao = $this->getMock('ConfigDao', array('getValue')); $configDao->expects($this->once())->method('getValue')->with(UserRoleManagerService::KEY_USER_ROLE_MANAGER_CLASS)->will($this->returnValue('UnitTestUserRoleManager')); $authenticationService = $this->getMock('AuthenticationService', array('getLoggedInUserId')); $authenticationService->expects($this->once())->method('getLoggedInUserId')->will($this->returnValue(211)); $systemUser = new SystemUser(); $systemUser->setId(211); $systemUserService = $this->getMock('SystemUserService', array('getSystemUser')); $systemUserService->expects($this->once())->method('getSystemUser')->will($this->returnValue($systemUser)); $this->service->setConfigDao($configDao); $this->service->setAuthenticationService($authenticationService); $this->service->setSystemUserService($systemUserService); $manager = $this->service->getUserRoleManager(); $this->assertNotNull($manager); $this->assertTrue($manager instanceof AbstractUserRoleManager); $this->assertTrue($manager instanceof UnitTestUserRoleManager); $user = $manager->getUser(); $this->assertEquals($systemUser, $user); }
public function testGetCredentialsInvalidPassword() { $userId = 3838; $userName = '******'; $password = '******'; $hashedPassword = '******'; $user = new SystemUser(); $user->setId($userId); $user->setUserRoleId(1); $user->setUserName($userName); $user->setUserPassword($hashedPassword); $mockDao = $this->getMock('SystemUserDao', array('isExistingSystemUser')); $mockDao->expects($this->once())->method('isExistingSystemUser')->with($userName)->will($this->returnValue($user)); $this->systemUserService->setSystemUserDao($mockDao); $result = $this->systemUserService->getCredentials($userName, $password); $this->assertFalse($result); }
public function testFilterRolesSupervisorForEmployee() { $testManager = new TestBasicUserRoleManager(); $userRoles = $this->__convertRoleNamesToObjects(array('Supervisor', 'Admin', 'RegionalAdmin')); $roles = $testManager->filterUserRolesPublic($userRoles, $rolesToExclude, $rolesToInclude); $this->assertEquals($userRoles, $roles); $rolesToExclude = array(); $rolesToInclude = array(); $user = new SystemUser(); $user->setId(11); $user->setEmpNumber(9); $systemUserService = $this->getMock('SystemUserService', array('getSystemUser')); $systemUserService->expects($this->once())->method('getSystemUser')->will($this->returnValue($user)); $testManager->setSystemUserService($systemUserService); $testManager->setUser($user); $employeeIds = array(1, 2, 3); $employeeService = $this->getMock('EmployeeService', array('getSubordinateIdListBySupervisorId')); $employeeService->expects($this->once())->method('getSubordinateIdListBySupervisorId')->with($user->getEmpNumber())->will($this->returnValue($employeeIds)); $testManager->setEmployeeService($employeeService); // Test that supervisor role is returned for Employee who is a subordinate $roles = $testManager->filterUserRolesPublic($userRoles, $rolesToExclude, $rolesToInclude, array('Employee' => 3)); $this->assertEquals($userRoles, $roles); // Test that supervisor role is not returned for Employee who is not a subordinate $roles = $testManager->filterUserRolesPublic($userRoles, $rolesToExclude, $rolesToInclude, array('Employee' => 13)); $this->assertEquals(array($userRoles[1], $userRoles[2]), $roles); }
public function testGetScreenPermissions() { $userRole = new UserRole(); $userRole->setId(1); $userRole->setName('Admin'); $user = new SystemUser(); $user->setId(1); $user->setEmpNumber(NULL); $user->setUserRole($userRole); $systemUserService = $this->getMock('SystemUserService', array('getSystemUser')); $systemUserService->expects($this->once())->method('getSystemUser')->with($user->getId())->will($this->returnValue($user)); $this->manager->setSystemUserService($systemUserService); $this->manager->setUser($user); $mockScreenPermissionService = $this->getMock('ScreenPermissionService', array('getScreenPermissions')); $permission = new ResourcePermission(true, false, true, false); $module = 'admin'; $action = 'testAction'; $roles = array($userRole); $mockScreenPermissionService->expects($this->once())->method('getScreenPermissions')->with($module, $action, $roles)->will($this->returnValue($permission)); $this->manager->setScreenPermissionService($mockScreenPermissionService); $result = $this->manager->getScreenPermissions($module, $action); $this->assertEquals($permission, $result); }