public static function suite() { $suite = new PHPUnit_Framework_TestSuite('Tine 2.0 Tinebase All Group Tests'); $suite->addTestSuite('Tinebase_Group_SqlTest'); if (TestServer::getInstance()->isPhpunitVersionGreaterOrEquals("3.5.0")) { // getMockBuilder() is only supported in phpunit 3.5 and higher $suite->addTestSuite('Tinebase_Group_ActiveDirectoryTest'); } return $suite; }
/** * lazy init of uit * * @return Calendar_Import_CalDAV_ClientMock */ protected function _getUit() { $testCredentials = TestServer::getInstance()->getTestCredentials(); if ($this->_uit === null) { $caldavClientOptions = array('baseUri' => 'localhost', 'userName' => Tinebase_Core::getUser()->accountLoginName, 'password' => $testCredentials['password']); $this->_uit = new Calendar_Import_CalDAV_ClientMock($caldavClientOptions, 'MacOSX'); $this->_uit->setVerifyPeer(false); } return $this->_uit; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_backend = Tinebase_User::getInstance(); if (!array_key_exists('Tinebase_EmailUser_Smtp_Postfix', $this->_backend->getPlugins())) { $this->markTestSkipped('Postfix SQL plugin not enabled'); } $this->objects['users'] = array(); $config = TestServer::getInstance()->getConfig(); if ($config->maildomain) { $this->_mailDomain = $config->maildomain; } }
/** * test get smtp config */ public function testGetSmtpConfig() { $smtpConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::SMTP); $account = new Felamimail_Model_Account(array('type' => Felamimail_Model_Account::TYPE_SYSTEM)); $accountSmtpConfig = $account->getSmtpConfig(); if (array_key_exists('primarydomain', $smtpConfig)) { $this->assertContains($smtpConfig['primarydomain'], $accountSmtpConfig['username']); } if (TestServer::getInstance()->getConfig()->mailserver) { $this->assertEquals(TestServer::getInstance()->getConfig()->mailserver, $accountSmtpConfig['hostname']); } }
/** * test get smtp config */ public function testGetSmtpConfig() { $this->markTestSkipped('this test has to be refactored'); $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray(); $account = new Felamimail_Model_Account(array('type' => Felamimail_Model_Account::TYPE_SYSTEM)); $accountSmtpConfig = $account->getSmtpConfig(); if (isset($smtpConfig['primarydomain']) || array_key_exists('primarydomain', $smtpConfig)) { $this->assertContains($smtpConfig['primarydomain'], $accountSmtpConfig['username']); } if (TestServer::getInstance()->getConfig()->mailserver) { $this->assertEquals(TestServer::getInstance()->getConfig()->mailserver, $accountSmtpConfig['hostname']); } }
/** * testMaintenanceModeLoginFail */ public function testMaintenanceModeLoginFail() { if (Tinebase_User::getConfiguredBackend() === Tinebase_User::LDAP || Tinebase_User::getConfiguredBackend() === Tinebase_User::ACTIVEDIRECTORY) { $this->markTestSkipped('FIXME: Does not work with LDAP/AD backend (full test suite run)'); } Tinebase_Config::getInstance()->maintenanceMode = 1; try { $this->_instance->login('sclever', Tinebase_Helper::array_value('password', TestServer::getInstance()->getTestCredentials()), new \Zend\Http\PhpEnvironment\Request()); $this->fail('expecting exception: Tinebase_Exception_MaintenanceMode'); } catch (Tinebase_Exception_MaintenanceMode $temm) { $this->assertEquals('Installation is in maintenance mode. Please try again later', $temm->getMessage()); } }
public static function suite() { $suite = new PHPUnit_Framework_TestSuite('Tine 2.0 Tinebase All User Tests'); $suite->addTestSuite('Tinebase_User_SqlTest'); $suite->addTestSuite('Tinebase_User_LdapTest'); if (TestServer::getInstance()->isPhpunitVersionGreaterOrEquals("3.5.0")) { // getMockBuilder() is only supported in phpunit 3.5 and higher $suite->addTestSuite('Tinebase_User_ActiveDirectoryTest'); } $suite->addTestSuite('Tinebase_User_Plugin_SambaTest'); $suite->addTestSuite('Tinebase_User_ModelTest'); $suite->addTestSuite('Tinebase_User_AbstractTest'); $suite->addTestSuite('Tinebase_User_EmailUser_AllTests'); // disabled user registration tests -> this is not used atm and not functional //$suite->addTestSuite('Tinebase_User_RegistrationTest'); return $suite; }
/** * test change / delete of account */ public function testChangeDeleteAccount() { $system = $this->_getSystemAccount(); unset($system['id']); $system['type'] = Felamimail_Model_Account::TYPE_USER; $account = $this->_json->saveAccount($system); $accountRecord = new Felamimail_Model_Account($account, TRUE); $accountRecord->resolveCredentials(FALSE); if (TestServer::getInstance()->getConfig()->mailserver) { $this->assertEquals(TestServer::getInstance()->getConfig()->mailserver, $account['host']); } $this->_json->changeCredentials($account['id'], $accountRecord->user, 'neuespasswort'); $account = $this->_json->getAccount($account['id']); $accountRecord = new Felamimail_Model_Account($account, TRUE); $accountRecord->resolveCredentials(FALSE); $this->assertEquals('neuespasswort', $accountRecord->password); $this->_json->deleteAccounts($account['id']); }
define('PATH_TO_TEST_DIR', dirname(__FILE__)); $path = array(PATH_TO_REAL_DIR, get_include_path(), PATH_TO_TEST_DIR, PATH_TO_TINE_LIBRARY); set_include_path(implode(PATH_SEPARATOR, $path)); /* * Set parameters for logging (call via browser) * * @todo put that in config.inc as well or remove that? */ define('CONFIGURATION', PATH_TO_TEST_DIR . "/conf.xml"); /* * Set up basic tine 2.0 environment */ require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->setFallbackAutoloader(true); // get config if (file_exists(dirname(__FILE__) . '/phpunitconfig.inc.php')) { $config = new Zend_Config(require dirname(__FILE__) . '/phpunitconfig.inc.php'); } else { throw new Exception("Couldn't find phpunitconfig.inc.php! \n"); } $_SERVER['DOCUMENT_ROOT'] = $config->docroot; TestServer::getInstance()->initFramework(); Tinebase_Core::set('locale', new Zend_Locale($config->locale)); Tinebase_Core::set('testconfig', $config); /* $tinebaseController = Tinebase_Controller::getInstance(); if (!$tinebaseController->login($config->username, $config->password, $config->ip)){ throw new Exception("Couldn't login, user session required for tests! \n"); } */
/** * testImportUsersWithEmailUser */ public function testImportUsersWithEmailUser() { $userBackend = Tinebase_User::getInstance(); $config = TestServer::getInstance()->getConfig(); $maildomain = $config->maildomain ? $config->maildomain : 'tine20.org'; $readFile = fopen(dirname(__FILE__) . '/files/tine_user5.csv', 'r'); $writeFile = fopen('test.csv', 'w'); $delimiter = ','; $enclosure = '"'; while (($row = fgetcsv($readFile)) !== false) { foreach ($row as $colIndex => &$field) { $field = str_replace('DOMAIN', $maildomain, $field); } fputcsv($writeFile, $row, $delimiter, $enclosure); } fclose($readFile); fclose($writeFile); if (!array_key_exists('Tinebase_EmailUser_Smtp_Postfix', $userBackend->getPlugins())) { $this->markTestSkipped('Postfix SQL plugin not enabled'); } $this->_importUsers($this->objects['configEmailuser'], 'test.csv', 'admin_user_import_csv_test_emailuser'); $newUser = $userBackend->getFullUserByLoginName('testuser'); $this->assertEquals(array('contact@' . $maildomain, 'kontakt@' . $maildomain), $newUser->smtpUser->emailAliases); $this->assertEquals(array('test@' . $maildomain), $newUser->smtpUser->emailForwards); $this->assertTrue($newUser->smtpUser->emailForwardOnly); unlink("test.csv"); }
/** * testMaintenanceModeLoginFail */ public function testMaintenanceModeLoginFail() { Tinebase_Config::getInstance()->maintenanceMode = 1; $this->setExpectedException('Tinebase_Exception_MaintenanceMode'); $this->_instance->login('sclever', Tinebase_Helper::array_value('password', TestServer::getInstance()->getTestCredentials()), new \Zend\Http\PhpEnvironment\Request()); }
/** * test change pw + credential cache */ public function testChangePasswordAndUpdateCredentialCache() { $this->markTestSkipped('FIXME 0009250: fix test testChangePasswordAndUpdateCredentialCache'); $testCredentials = TestServer::getInstance()->getTestCredentials(); $account = clone $this->_account; unset($account->id); $account->type = Felamimail_Model_Account::TYPE_USER; $account->user = $testCredentials['username']; $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray(); if (isset($imapConfig['domain']) && !empty($imapConfig['domain'])) { $account->user .= '@' . $imapConfig['domain']; } $account->password = $testCredentials['password']; $account = $this->_controller->create($account); $testPw = 'testpwd'; // change pw & update credential cache $this->_setCredentials($testCredentials['username'], $testPw); $account = $this->_controller->get($account->getId()); // try to connect to imap $loginSuccessful = TRUE; try { $imap = Felamimail_Backend_ImapFactory::factory($account); } catch (Felamimail_Exception_IMAPInvalidCredentials $e) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' config: ' . print_r($imapAccountConfig, true) . ' / exception:' . $e); } $loginSuccessful = FALSE; } $this->assertTrue($loginSuccessful, 'wrong credentials'); }
/** * replace maildomain in input file * * @param string $filename * @return string filename */ public static function replaceEmailDomainInFile($filename) { $config = TestServer::getInstance()->getConfig(); $maildomain = $config->maildomain ? $config->maildomain : 'tine20.org'; $tempPath = Tinebase_TempFile::getTempPath(); $contents = file_get_contents($filename); $contents = preg_replace('/tine20.org/', $maildomain, $contents); file_put_contents($tempPath, $contents); return $tempPath; }
/** * test change pw + credential cache */ public function testChangePasswordAndUpdateCredentialCache() { $testCredentials = TestServer::getInstance()->getTestCredentials(); $account = clone $this->_account; unset($account->id); $account->type = Expressomail_Model_Account::TYPE_USER; $account->user = $testCredentials['username']; $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray(); if (isset($imapConfig['domain']) && !empty($imapConfig['domain'])) { $account->user .= '@' . $imapConfig['domain']; } $account->password = $testCredentials['password']; $account = $this->_controller->create($account); $testPw = 'testpwd'; // change pw & update credential cache $this->_setCredentials($testCredentials['password'], $testPw); $account = $this->_controller->get($account->getId()); // try to connect to imap $loginSuccessful = TRUE; try { $imap = Expressomail_Backend_ImapFactory::factory($account); $imapAccountConfig = $account->getImapConfig(); $imap->connectAndLogin((object) $imapAccountConfig); } catch (Expressomail_Exception_IMAPInvalidCredentials $e) { $loginSuccessful = FALSE; } $this->assertTrue($loginSuccessful, 'wrong credentials'); }
/** * test line end encoding of Zend_Mime_Part / Smtp Protocol */ public function testSendWithWrongLineEnd() { $config = TestServer::getInstance()->getConfig(); $mailDomain = $config->maildomain ? $config->maildomain : 'tine20.org'; // build message with wrong line end rfc822 part $mail = new Tinebase_Mail('utf-8'); $mail->setBodyText('testmail' . "\r\n" . "\r\n"); $mail->setFrom('unittest@' . $mailDomain, 'unittest'); $mail->setSubject('line end test'); $mail->addTo('unittest@' . $mailDomain); $mail->addHeader('X-Tine20TestMessage', 'lineend'); // replace EOLs $content = file_get_contents(dirname(dirname(__FILE__)) . '/files/text_plain.eml'); $content = preg_replace("/\\x0a/", "\r\n", $content); $stream = fopen("php://temp", 'r+'); fputs($stream, $content); rewind($stream); $attachment = new Zend_Mime_Part($stream); $attachment->type = Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822; $attachment->encoding = null; $attachment->charset = 'ISO-8859-1'; $attachment->filename = 'attach.eml'; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $mail->addAttachment($attachment); $smtpConfig = $this->_account->getSmtpConfig(); $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig); $mail->send($transport); $smtpLog = $transport->getConnection()->getLog(); $badLineEndCount = preg_match_all("/\\x0d\\x0d\\x0a/", $smtpLog, $matches); $this->assertEquals(0, $badLineEndCount); $badLineEndCount = preg_match_all("/\\x0d/", $smtpLog, $matches); $this->assertTrue(preg_match_all("/\\x0d/", $smtpLog, $matches) > 70, 'unix line ends are missing'); }
/** * 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']); }
/** * returns configured primary mail domain * * phpunit.config.inc > smtp config primary domain > current user mail domain > tine20.org * * @return mixed|string */ public static function getPrimaryMailDomain() { $config = TestServer::getInstance()->getConfig(); if ($config->maildomain) { return $config->maildomain; } else { $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray(); if (isset($smtpConfig['primarydomain'])) { return $smtpConfig['primarydomain']; } if (!empty(Tinebase_Core::getUser()->accountEmailAddress)) { list($user, $domain) = explode('@', Tinebase_Core::getUser()->accountEmailAddress, 2); return $domain; } } return 'tine20.org'; }
<?php /** * Tine 2.0 * * @package tests * @subpackage test root * @license http://www.gnu.org/licenses/agpl.html AGPL3 * @copyright Copyright (c) 2008 Metaways Infosystems GmbH (http://www.metaways.de) * @author Matthias Greiling <*****@*****.**> */ Tinebase_Session_Abstract::setSessionEnabled('TINE20SESSID'); TestServer::getInstance()->initFramework(); TestServer::getInstance()->login(); // do this after login because we need the current user TestServer::getInstance()->initTestUsers(); TestServer::getInstance()->setTestUserEmail(); // speed up tests by disabling calendar notifications Calendar_Controller_Event::getInstance()->sendNotifications(false);
/** * test imap authentication */ public function testImapAuth() { // use imap config for the auth config $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray(); if (empty($imapConfig)) { $this->markTestSkipped('No IMAP config found.'); } $authConfig = array('host' => $imapConfig['host'], 'port' => $imapConfig['port'], 'ssl' => $imapConfig['ssl'], 'domain' => $imapConfig['domain']); Tinebase_Auth::setBackendType(Tinebase_Auth::IMAP); Tinebase_Auth::setBackendConfiguration($authConfig); Tinebase_Auth::saveBackendConfiguration(); Tinebase_Auth::getInstance()->setBackend(); $this->assertEquals(Tinebase_Auth::IMAP, Tinebase_Auth::getConfiguredBackend()); $testCredentials = TestServer::getInstance()->getTestCredentials(); // valid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], $testCredentials['password']); $this->assertTrue($authResult->isValid()); // invalid authentication $authResult = Tinebase_Auth::getInstance()->authenticate($testCredentials['username'], 'some pw'); $this->assertFalse($authResult->isValid()); $this->assertEquals(Tinebase_Auth::FAILURE_CREDENTIAL_INVALID, $authResult->getCode()); $this->assertEquals(array('Invalid credentials for user ' . $this->_getEmailAddress(), ''), $authResult->getMessages()); }
/** * get email address * * @return string */ public function getEmailAddress() { $config = TestServer::getInstance()->getConfig(); $email = $config->email ? $config->email : Tinebase_Core::getUser()->accountEmailAddress; return $email; }