/** * 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()); }
/** * the singleton pattern * * @return Tinebase_Controller_ScheduledImport */ public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; }
/** * @see 0011342: ics-scheduled import only imports 1 remote calendar */ public function testNextScheduledImportFilter() { $record = $this->createScheduledImport(); $record->timestamp = $record->timestamp->addHour(2); $this->_uit->update($record); $filter = $this->_uit->getScheduledImportFilter(); $result = $this->_uit->search($filter); $this->assertEquals(0, count($result), 'no imports should be found: ' . print_r($result->toArray(), true)); }
/** * @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)); }
/** * creates a scheduled import * * @param string $remoteUrl * @param string $interval * @param string $importOptions * @return array */ public function importRemoteEvents($remoteUrl, $interval, $importOptions) { // Determine which plugin should be used to import switch ($importOptions['sourceType']) { case 'remote_caldav': $plugin = 'Calendar_Import_CalDAV'; break; default: $plugin = 'Calendar_Import_Ical'; } $credentialCache = Tinebase_Auth_CredentialCache::getInstance(); $credentials = $credentialCache->cacheCredentials($importOptions['username'], $importOptions['password'], null, true, Tinebase_DateTime::now()->addYear(100)); $record = Tinebase_Controller_ScheduledImport::getInstance()->createRemoteImportEvent(array('source' => $remoteUrl, 'interval' => $interval, 'options' => array_replace($importOptions, array('plugin' => $plugin, 'importFileByScheduler' => $importOptions['sourceType'] != 'remote_caldav', 'cid' => $credentials->getId(), 'ckey' => $credentials->key)), 'model' => 'Calendar_Model_Event', 'user_id' => Tinebase_Core::getUser()->getId(), 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId())); $result = $this->_recordToJson($record); Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'container_id:' . print_r($result['container_id'], true)); return $result; }
/** * trigger caldav import by json frontend * * @todo use mock as fallback (if server can not be reached by curl) * @todo get servername from unittest config / skip or mock if no servername found */ public function testCalDAVImport() { // Skip if tine20.com.local could not be resolved if (gethostbyname('tine20.com.local') == 'tine20.com.local') { $this->markTestSkipped('Can\'t perform test, because instance is not reachable.'); } $this->_testNeedsTransaction(); $event = $this->testCreateEvent(true); $fe = new Calendar_Frontend_Json(); $testUserCredentials = TestServer::getInstance()->getTestCredentials(); $fe->importRemoteEvents('http://tine20.com.local/calendars/' . Tinebase_Core::getUser()->contact_id . '/' . $event['container_id']['id'], Tinebase_Model_Import::INTERVAL_DAILY, array('container_id' => 'remote_caldav_calendar', 'sourceType' => 'remote_caldav', 'importFileByScheduler' => false, 'allowDuplicateEvents' => true, 'username' => $testUserCredentials['username'], 'password' => $testUserCredentials['password'])); $importScheduler = Tinebase_Controller_ScheduledImport::getInstance(); $record = $importScheduler->runNextScheduledImport(); $container = Tinebase_Container::getInstance()->getContainerByName('Calendar', 'remote_caldav_calendar', Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser()->getId()); $this->_testCalendars[] = $container; $this->assertTrue($container instanceof Tinebase_Model_Container, 'Container was not created'); $this->assertNotEquals($record, null, 'The import could not start!'); $filter = $this->_getEventFilterArray($container->getId()); $result = $this->_uit->searchEvents($filter, array()); $this->assertEquals(1, $result['totalcount']); }