public function testCalculateDaysInTheTimesheetPeriod() { $key = 'timesheet_period_and_start_date'; $xmlString = TestDataService::getRecords("SELECT value from hs_hr_config WHERE `key` = '" . $key . "'"); $xmlString = $xmlString[0]['value']; $xmlString = simplexml_load_String($xmlString); $currentDate = '2011-04-24'; // This is necessary to make timeStampDiff 0 in MonthlyTimesheetPeriod::getDatesOfTheTimesheetPeriod // $timeStampDiff = $clientTimeZoneOffset * 3600 - $serverTimezoneOffset; $userObj = new User(); $serverTimezoneOffset = (int) date('Z'); $userObj->setUserTimeZoneOffset($serverTimezoneOffset / 3600); sfContext::getInstance()->getUser()->setAttribute('user', $userObj); $datesArray = $this->weeklyTimesheetPeriod->calculateDaysInTheTimesheetPeriod($currentDate, $xmlString); $this->assertEquals($datesArray[0], "2011-04-18 00:00"); $this->assertEquals($datesArray[3], "2011-04-21 00:00"); $this->assertEquals(end($datesArray), "2011-04-24 00:00"); $currentDate = '2012-02-28'; $datesArray = $this->weeklyTimesheetPeriod->calculateDaysInTheTimesheetPeriod($currentDate, $xmlString); $this->assertEquals($datesArray[0], "2012-02-27 00:00"); $this->assertEquals($datesArray[3], "2012-03-01 00:00"); $this->assertEquals(end($datesArray), "2012-03-04 00:00"); $currentDate = '2011-12-29'; $datesArray = $this->weeklyTimesheetPeriod->calculateDaysInTheTimesheetPeriod($currentDate, $xmlString); $this->assertEquals($datesArray[0], "2011-12-26 00:00"); $this->assertEquals($datesArray[3], "2011-12-29 00:00"); $this->assertEquals(end($datesArray), "2012-01-01 00:00"); }
public function execute($filterChain) { if (isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == "Yes") { $userRoleArray['isAdmin'] = true; } else { $userRoleArray['isAdmin'] = false; } if (isset($_SESSION['isSupervisor'])) { $userRoleArray['isSupervisor'] = $_SESSION['isSupervisor']; } if (isset($_SESSION['isHiringManager'])) { $userRoleArray['isHiringManager'] = $_SESSION['isHiringManager']; } if (isset($_SESSION['isInterviewer'])) { $userRoleArray['isInterviewer'] = $_SESSION['isInterviewer']; } if (isset($_SESSION['empNumber']) && $_SESSION['empNumber'] == null) { $userRoleArray['isEssUser'] = false; } else { $userRoleArray['isEssUser'] = true; } if (isset($_SESSION['isProjectAdmin']) && $_SESSION['isProjectAdmin']) { $userRoleArray['isProjectAdmin'] = true; } else { $userRoleArray['isProjectAdmin'] = false; } $userObj = new User(); if (isset($_SESSION['empNumber'])) { $userObj->setEmployeeNumber($_SESSION['empNumber']); } if (isset($_SESSION['user'])) { $userObj->setUserId($_SESSION['user']); } if (isset($_SESSION['userTimeZoneOffset'])) { $userObj->setUserTimeZoneOffset($_SESSION['userTimeZoneOffset']); } else { $userObj->setUserTimeZoneOffset(0); } $simpleUserRoleFactory = new SimpleUserRoleFactory(); $decoratedUser = $simpleUserRoleFactory->decorateUserRole($userObj, $userRoleArray); $this->getContext()->getUser()->setAttribute("user", $decoratedUser); $filterChain->execute(); }
public function testGetDatesOfTheTimesheetPeriod() { $userObj = new User(); // This is necessary to make timeStampDiff 0 in MonthlyTimesheetPeriod::getDatesOfTheTimesheetPeriod // $timeStampDiff = $clientTimeZoneOffset * 3600 - $serverTimezoneOffset; $serverTimezoneOffset = (int) date('Z'); $userObj->setUserTimeZoneOffset($serverTimezoneOffset / 3600); sfContext::getInstance()->getUser()->setAttribute('user', $userObj); $startDate = "2011-12-12"; $endDate = "2011-12-31"; $returnedDatesArray = $this->monthlyTimesheetPeriod->getDatesOfTheTimesheetPeriod($startDate, $endDate); $this->assertEquals($returnedDatesArray[0], "2011-12-12"); $startDate = "2012-02-20"; $endDate = "2012-03-15"; $returnedDatesArray = $this->monthlyTimesheetPeriod->getDatesOfTheTimesheetPeriod($startDate, $endDate); $this->assertEquals($returnedDatesArray[0], "2012-02-20"); $this->assertEquals(end($returnedDatesArray), "2012-03-15"); $this->assertEquals($returnedDatesArray[9], "2012-02-29"); }
public function testGetDefinedTimesheetPeriod() { // This is necessary to make timeStampDiff 0 in MonthlyTimesheetPeriod::getDatesOfTheTimesheetPeriod // $timeStampDiff = $clientTimeZoneOffset * 3600 - $serverTimezoneOffset; $userObj = new User(); $serverTimezoneOffset = (int) date('Z'); $userObj->setUserTimeZoneOffset($serverTimezoneOffset / 3600); sfContext::getInstance()->getUser()->setAttribute('user', $userObj); $currentDate = '2011-06-30'; $key = 'timesheet_period_and_start_date'; $xmlString = TestDataService::getRecords("SELECT value from hs_hr_config WHERE `key` = '" . $key . "'"); $value = $xmlString[0]['value']; $timesheetPeriodDaoMock = $this->getMock('TimesheetPeriodDao', array('getDefinedTimesheetPeriod')); $timesheetPeriodDaoMock->expects($this->once())->method('getDefinedTimesheetPeriod')->will($this->returnValue($value)); $this->timesheetPeriodService->setTimesheetPeriodDao($timesheetPeriodDaoMock); $array = $this->timesheetPeriodService->getDefinedTimesheetPeriod($currentDate); $this->assertEquals($array[0], '2011-06-27 00:00'); $this->assertEquals($array[4], '2011-07-01 00:00'); }