/** * set up tests */ protected function setUp() { parent::setUp(); $this->_testCalendar = $this->_getTestContainer('Calendar'); $this->_uit = Tinebase_Controller_ScheduledImport::getInstance(); }
/** * 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']); }