Exemplo n.º 1
0
 public function testSearchLeaveSummary()
 {
     $clues['cmbEmpId'] = 1;
     $clues['userType'] = 'ESS';
     $clues['cmbLeaveType'] = '';
     $clues['cmbSubDivision'] = '';
     $clues['cmbJobTitle'] = '';
     $clues['cmbLocation'] = '';
     $clues['subordinates'] = '';
     $clues['cmbWithTerminated'] = '';
     $intendedResults[0] = array('emp_fullname' => 'Ashley Abel', 'leave_type_id' => 'LTY001', 'available_flag' => 1, 'leave_period_id' => null, 'employee_id' => null, 'emp_number' => 2, 'termination_id' => null, 'leave_type_name' => 'Casual', 'no_of_days_allotted' => '0.00', 'leave_brought_forward' => null, 'leave_carried_forward' => null, 'leave_info' => '0.00_0.00_0.00', 'having_taken' => false, 'leave_taken' => '0.00', 'having_scheduled' => false, 'leave_scheduled' => '0.00', 'logged_user_id' => 1, 'leave_type_status' => true);
     $intendedResults[1] = array('emp_fullname' => 'Ashley Abel', 'leave_type_id' => 'LTY002', 'available_flag' => 1, 'leave_period_id' => null, 'employee_id' => null, 'emp_number' => 2, 'termination_id' => null, 'leave_type_name' => 'Medical', 'no_of_days_allotted' => '0.00', 'leave_brought_forward' => null, 'leave_carried_forward' => null, 'leave_info' => '0.00_0.00_0.00', 'having_taken' => false, 'leave_taken' => '0.00', 'having_scheduled' => false, 'leave_scheduled' => '0.00', 'logged_user_id' => 1, 'leave_type_status' => true);
     $leaveSummaryDao = $this->getMock('LeaveSummaryDao', array('searchLeaveSummary'));
     $leaveSummaryDao->expects($this->once())->method('searchLeaveSummary')->with($clues, 0, 20)->will($this->returnValue($intendedResults));
     // TODO: 'BasicUserRoleManager' is used directly. Should be accessed via UserRoleManagerFactory::getUserRoleManager()
     $userRoleManagerMock = $this->getMock('BasicUserRoleManager', array('getAccessibleEntityIds', 'getUser', 'getDataGroupPermissions'));
     $userRoleManagerMock->expects($this->once())->method('getAccessibleEntityIds')->with('Employee')->will($this->returnValue(array(1, 2, 3, 4, 5)));
     $user = new SystemUser();
     $user->setEmpNumber(2);
     $userRoleManagerMock->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $dataGroupPermission = new ResourcePermission(true, true, true, true);
     $userRoleManagerMock->expects($this->exactly(2))->method('getDataGroupPermissions')->with(array('leave_summary'), array(), array(), true)->will($this->returnValue($dataGroupPermission));
     $this->leaveSummaryService->setLeaveSummaryDao($leaveSummaryDao);
     $this->leaveSummaryService->setUserRoleManager($userRoleManagerMock);
     $result = $this->leaveSummaryService->searchLeaveSummary($clues, 0, 20, 1);
     $this->compareArrays($intendedResults, $result);
 }
Exemplo n.º 2
0
 /**
  * @expectedException DaoException
  */
 public function testSaveSystemUserWithExistingUserName()
 {
     $systemUser = new SystemUser();
     $systemUser->setUserRoleId(1);
     $systemUser->setEmpNumber(2);
     $systemUser->setUserName('samantha');
     $systemUser->setUserPassword('orangehrm');
     $this->systemUserDao->saveSystemUser($systemUser);
 }
 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);
 }