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;
     $serverTimezoneOffset = (int) date('Z');
     sfContext::getInstance()->getUser()->setAttribute('system.timeZoneOffset', $serverTimezoneOffset / 3600);
     $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");
 }
 protected function validateResultRecords($originalQuery, $expectedQuery, $service, $method)
 {
     $resultQuery = self::$baseService->decorateQuery($service, $method, $originalQuery);
     $expectedRecords = TestDataService::getRecords($expectedQuery);
     $resultRecords = TestDataService::getRecords($resultQuery);
     $this->assertEquals($expectedRecords, $resultRecords);
     $this->resultRecords = $resultRecords;
 }
 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';
     $dates = $this->monthlyTimesheetPeriod->calculateDaysInTheTimesheetPeriod($currentDate, $xmlString);
     $this->assertEquals("2011-04-13", $dates[0]);
     $this->assertEquals("2011-05-12", end($dates));
     $this->assertEquals("2011-04-18", $dates[5]);
     $dates = $this->monthlyTimesheetPeriod->calculateDaysInTheTimesheetPeriod("2011-02-18", $xmlString);
     $this->assertEquals("2011-02-13", $dates[0]);
     $this->assertEquals("2011-03-12", end($dates));
     $this->assertEquals("2011-02-23", $dates[10]);
     $dates = $this->monthlyTimesheetPeriod->calculateDaysInTheTimesheetPeriod("2012-02-18", $xmlString);
     $this->assertEquals("2012-02-13", $dates[0]);
     $this->assertEquals("2012-03-12", end($dates));
     $this->assertEquals("2012-02-28", $dates[15]);
     $dates = $this->monthlyTimesheetPeriod->calculateDaysInTheTimesheetPeriod("2012-12-31", $xmlString);
     $this->assertEquals("2012-12-13", $dates[0]);
     $this->assertEquals("2013-01-12", end($dates));
     $this->assertEquals("2013-01-02", $dates[20]);
 }
 public function testGetTimesheetHeading()
 {
     $key = 'timesheet_period_and_start_date';
     // Note: fetchObject fails due to primary key 'key' being a reserved word.
     //$xmlString = TestDataService::fetchObject('Config', $key);
     $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);
     $timesheetHeading = $this->timesheetPeriodService->getTimesheetHeading();
     $this->assertEquals("Week", (string) $timesheetHeading);
 }