/** * testNextScheduledImport */ public function testNextScheduledImport() { $cc = Calendar_Controller_Event::getInstance(); $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()))); $all = $cc->search($filter); $this->assertEquals(0, $all->count()); $now = Tinebase_DateTime::now()->subHour(1); $record = $this->createScheduledImport(); // assert setting timestamp to start value $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi')); $record = $this->_uit->runNextScheduledImport(); // assert updating timestamp after successful run $now->addHour(1); $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi')); $all = $cc->search($filter); $seq = $all->getFirstRecord()->seq; // assert all events have been imported $this->assertEquals(7, $all->count()); // this must not be run, the interval is not exceed $ret = $this->_uit->runNextScheduledImport(); $all = $cc->search($filter); $this->assertEquals($seq, $all->getFirstRecord()->seq); // setting manual timestamp to force run again $record->timestamp = $record->timestamp->subHour(1)->subSecond(1); $this->_uit->update($record); $ret = $this->_uit->runNextScheduledImport(); $all = $cc->search($filter); $this->assertEquals(7, $all->count()); }
/** * @see 0011342: ics-scheduled import only imports 1 remote calendar */ public function testMultipleScheduledImports() { // add two imports and check if they are both executed $import1 = $this->createScheduledImport(); sleep(1); // make sure first one is found first $import2 = $this->createScheduledImport(); $importRun1 = $this->_uit->runNextScheduledImport(); $this->assertEquals($import1->getId(), $importRun1['id'], print_r($importRun1, true)); $this->assertGreaterThanOrEqual($importRun1['timestamp'], Tinebase_DateTime::now()->toString()); $importRun2 = $this->_uit->runNextScheduledImport(); $this->assertEquals($import2->getId(), $importRun2['id'], 'second import not run: ' . print_r($importRun1, true)); $this->assertGreaterThanOrEqual($importRun2['timestamp'], Tinebase_DateTime::now()->toString()); }
/** * @see 0012082: deactivate failing scheduled imports */ public function testDeactivatingImport() { // create invalid import $import1 = $this->createScheduledImport(); // run 5 (maxfailcount) times for ($i = 1; $i <= Tinebase_Controller_ScheduledImport::MAXFAILCOUNT; $i++) { $importRun = $this->_uit->runNextScheduledImport(); $this->assertTrue(isset($importRun['failcount']), 'failcount should exist (import run ' . $i . ')'); $this->assertEquals($i, $importRun['failcount'], 'failcount should increase: ' . print_r($importRun, true)); $this->_runAgain($importRun); } // check if import is deactivated $importRun = $this->_uit->runNextScheduledImport(); $this->assertTrue($importRun === null, 'import should not run: ' . print_r($importRun, true)); }