public function testPassesServerToNewPage() { $expectedDate = new DateTime('2011-01-25', $this->timezone); $expectedAction = 'TimeReport/TimeReport.aspx?DateInWeek=2011-01-25'; $this->server->expects($this->once())->method('get')->with($expectedAction)->will($this->returnValue($this->loadHTMLFile('intellitime-v9-timereport-three-open.txt'))); $factory = new TZIntellitimeWeekDataFactory($this->server); $weekData = $factory->createWeekData($expectedDate); $reports = array(createMockReport('mhbLP96iqH04xVvkWCFl884hbku5Eii3', '2011-01-26', '08:00', '17:00')); $reports[0]->intellitime_local_changes = 1; $this->server->expects($this->once())->method('post')->will($this->returnValue($this->loadHTMLFile('intellitime-v9-timereport-three-open.txt'))); $post = $weekData->buildPost($reports); $page = $post->post(); }
function testDuplicatesWithoutChangesKeepsFirst() { $weekData = $this->loadHTMLFile('intellitime-v9-timereport-single-open.txt'); $reports = array(createMockReport('mhbLP96iqH3iH05RYH%2fOlM4hbku5Eii3', '2011-01-25', '08:30', '17:30', 60, 0), createMockReport('mhbLP96iqH3iH05RYH%2fOlM4hbku5Eii3', '2011-01-25', '08:30', '17:30', 61, 0)); $account = (object) array('name' => 'Kalle', 'uid' => 63); $updatedReports = $weekData->updateReports($reports, $account); $this->assertEquals(2, count($reports)); $this->assertEquals(2, count($updatedReports)); $this->assertEquals(TZFlags::CREATED, $updatedReports[0]->flags); $this->assertTrue(FALSE !== strpos($updatedReports[0]->intellitime_id, 'mhbLP96iqH3iH05RYH%2fOlM4hbku5Eii3')); $this->assertEquals(60 * 60, $updatedReports[0]->breakduration); $this->assertEquals(TZFlags::DELETED, $updatedReports[1]->flags); $this->assertEquals(0, $updatedReports[1]->intellitime_local_changes); }
function testConstructorHandlesDELETED() { $tzreport = createMockReport('mhbLP96iqH2Zr7CDtWyWb84hbku5Eii3', "2010-10-10", "10:10", "22:10", 30, 1, TZFlags::DELETED); $itreport = new TZIntellitimeReport($tzreport); $this->assertEquals(TZIntellitimeReport::STATE_DELETED, $itreport->state); }
public function testSyncUpdatesUnfinishedWeeksInfo() { $expectedDate = new DateTime('2011-01-25', $this->timezone); $expectedMonday = new DateTime('2011-01-24T00:00:00.000', $this->timezone); $expectedSunday = new DateTime('2011-01-31T00:00:00.000', $this->timezone); $expectedReports = array(); $syncResult = new TZIntellitimeWeekSyncResult(); $syncResult->intellitime_assignments = array($this->createMockAssignment('Assignment Title', 'title')); $syncResult->tzreports = array(createMockReport('mhbLP96iqH3iH05RYH%2fOlM4hbku5Eii3', '2011-01-25', '08:30', '17:30', 60, 0)); $syncResult->tzreports[0]->intellitime_jobid = $syncResult->intellitime_assignments[0]->id; unset($syncResult->tzreports[0]->nid); unset($syncResult->tzreports[0]->vid); unset($syncResult->tzreports[0]->jobid); $syncResult->unfinishedWeeks = array(new DateTime('2011-02-22', $this->timezone)); $storedAssignments = array_map($this->clone_lambda, $syncResult->getTZJobs()); $storedAssignments[0]->nid = 2; $storedAssignments[0]->vid = 3; $storedAssignments[0]->parentid = 0; $mappedReports = array_map($this->clone_lambda, $syncResult->tzreports); $mappedReports[0]->jobid = 2; unset($mappedReports[0]->intellitime_jobid); $this->syncPolicy->expects($this->exactly(2))->method('getNextWeekToSync')->will($this->onConsecutiveCalls($expectedDate, NULL)); $this->syncPolicy->expects($this->once())->method('addWeeks')->with($syncResult->unfinishedWeeks); $this->reportStorage->expects($this->once())->method('getTZReports')->with($expectedMonday, $expectedSunday)->will($this->returnValue($expectedReports)); $expectedWeek = $this->getMockBuilder('TZIntellitimeWeek')->disableOriginalConstructor()->getMock(); $expectedWeek->expects($this->once())->method('sync')->will($this->returnValue($syncResult)); $this->weekFactory->expects($this->once())->method('createWeek')->with($expectedDate, $expectedReports)->will($this->returnValue($expectedWeek)); $this->reportStorage->expects($this->once())->method('storeTZJobs')->with($syncResult->getTZJobs())->will($this->returnValue($storedAssignments)); $this->reportStorage->expects($this->once())->method('storeTZReports')->with($mappedReports); $status = $this->syncController->synchronize(); $this->assertEquals(TZIntellitimeSyncStatus::SYNC_OK, $status); }
public function testV9RestoreStateOnNetworkException() { $weekData = array($this->loadHTMLFile('Week_v9ChangingReportedRowsRequiresTwoPosts_step_1.txt'), $this->loadHTMLFile('Week_v9ChangingReportedRowsRequiresTwoPosts_step_2.txt')); $expectedException = new TZNetworkFailureException('mock exception'); $dataFactory = $this->getMock('TZIntellitimeWeekDataFactory'); $dataFactory->expects($this->at(0))->method('createWeekData')->will($this->returnValue($weekData[0])); $dataFactory->expects($this->at(1))->method('createWeekDataFromPost')->with($this->isInstanceOf('IntellitimeWeekUnlockPost'))->will($this->returnValue($weekData[1])); $dataFactory->expects($this->at(2))->method('createWeekDataFromPost')->with($this->isInstanceOf('IntellitimeWeekUpdatePost'))->will($this->throwException($expectedException)); $reports = array(createMockReport('mhbLP96iqH2ZmvPmA4%2fZ0M4hbku5Eii3', '2011-01-24', '08:00', '17:00', 60), createMockReport('mhbLP96iqH3iH05RYH%2fOlM4hbku5Eii3', '2011-01-25', '08:30', '17:30', 60), createMockReport('mhbLP96iqH04xVvkWCFl884hbku5Eii3', '2011-01-26', '08:00', '17:00', 60)); $reports[0]->intellitime_local_changes = 0; $reports[2]->intellitime_local_changes = 0; $week = new TZIntellitimeWeek(new DateTime('2011-01-25'), $dataFactory, $reports, $this->account); $syncResult = $week->sync(); $this->assertNotNull($syncResult); $this->assertSame($expectedException, $syncResult->exception); foreach ($reports as $i => $report) { $updatedReport = $syncResult->tzreports[$i]; $this->assertEquals($report->vid, $updatedReport->vid); $this->assertEquals($report->begintime, $updatedReport->begintime); $this->assertEquals($report->endtime, $updatedReport->endtime); $this->assertEquals($report->breakduration, $updatedReport->breakduration); } $this->assertEquals(0, $syncResult->tzreports[0]->intellitime_local_changes); $this->assertEquals(1, $syncResult->tzreports[1]->intellitime_local_changes); $this->assertEquals(0, $syncResult->tzreports[2]->intellitime_local_changes); $this->assertEquals(TZIntellitimeReport::STATE_REPORTED, $syncResult->tzreports[0]->intellitime_last_state); $this->assertEquals(TZIntellitimeReport::STATE_OPEN, $syncResult->tzreports[1]->intellitime_last_state); $this->assertEquals(TZIntellitimeReport::STATE_OPEN, $syncResult->tzreports[2]->intellitime_last_state); }