3 * Tine 2.0 - http://www.tine20.org
6 * @license http://www.gnu.org/licenses/agpl.html
7 * @copyright Copyright (c) 2008-2013 Metaways Infosystems GmbH (http://www.metaways.de)
8 * @author Philipp Schüle <p.schuele@metaways.de>
15 require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
18 * Test class for Tinebase_Group
20 class Setup_ControllerTest extends PHPUnit_Framework_TestCase
23 * @var Setup_Controller
25 protected $_uit = null;
28 * Sets up the fixture.
29 * This method is called before a test is executed.
33 protected function setUp()
35 $this->_uit = Setup_Controller::getInstance();
39 * Tears down the fixture
40 * This method is called after a test is executed.
44 protected function tearDown()
46 $testCredentials = Setup_TestServer::getInstance()->getTestCredentials();
47 $this->_installAllApplications(array(
48 'defaultAdminGroupName' => 'Administrators',
49 'defaultUserGroupName' => 'Users',
50 'adminLoginName' => $testCredentials['username'],
51 'adminPassword' => $testCredentials['password'],
56 * testLoginWithWrongUsernameAndPassword
58 public function testLoginWithWrongUsernameAndPassword()
60 $result = $this->_uit->login('unknown_user_xxyz', 'wrong_password');
61 $this->assertFalse($result);
65 * test uninstall application and cache clearing
68 public function testUninstallApplications()
70 $cache = Tinebase_Core::getCache();
71 $cacheId = 'unittestcache';
72 $cache->save('something', $cacheId);
75 $result = $this->_uit->uninstallApplications(array('ActiveSync'));
76 } catch (Tinebase_Exception_NotFound $e) {
77 $this->_uit->installApplications(array('ActiveSync'));
78 $result = $this->_uit->uninstallApplications(array('ActiveSync'));
81 $this->assertFalse($cache->test($cacheId), 'cache is not cleared');
83 $apps = $this->_uit->searchApplications();
86 foreach ($apps['results'] as $app) {
87 if ($app['name'] == 'ActiveSync') {
88 $activeSyncApp = $app;
94 $this->assertTrue(isset($activeSyncApp));
95 $this->assertEquals('uninstalled', $activeSyncApp['install_status']);
98 $this->_uit->installApplications(array('ActiveSync'));
102 * testInstallAdminAccountOptions
104 public function testInstallAdminAccountOptions()
106 $this->_uninstallAllApplications();
107 $this->_uit->installApplications(array('Tinebase'), array('adminLoginName' => 'phpunit-admin', 'adminPassword' => 'phpunit-password'));
108 $adminUser = Tinebase_User::getInstance()->getFullUserByLoginName('phpunit-admin');
109 $this->assertTrue($adminUser instanceof Tinebase_Model_User);
111 $this->assertNull(Tinebase_Auth::getBackendConfiguration('adminLoginName'));
112 $this->assertNull(Tinebase_Auth::getBackendConfiguration('adminPassword'));
113 $this->assertNull(Tinebase_Auth::getBackendConfiguration('adminConfirmation'));
116 $this->_uninstallAllApplications();
120 * testSaveAuthenticationRedirectSettings
122 public function testSaveAuthenticationRedirectSettings()
124 $originalRedirectSettings = array(
125 Tinebase_Config::REDIRECTURL => Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTURL, ''),
126 Tinebase_Config::REDIRECTTOREFERRER => Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTTOREFERRER, FALSE)
129 $newRedirectSettings = array(
130 Tinebase_Config::REDIRECTURL => 'http://tine20.org',
131 Tinebase_Config::REDIRECTTOREFERRER => TRUE
134 $this->_uit->saveAuthentication(array('redirectSettings' => $newRedirectSettings));
136 $storedRedirectSettings = array(
137 Tinebase_Config::REDIRECTURL => Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTURL),
138 Tinebase_Config::REDIRECTTOREFERRER => Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTTOREFERRER)
141 $configNames = array(Tinebase_Config::REDIRECTURL, Tinebase_Config::REDIRECTTOREFERRER);
142 foreach ($configNames as $configName) {
143 $this->assertEquals($storedRedirectSettings[$configName], $newRedirectSettings[$configName],
144 'new setting should match stored settings: ' . print_r($newRedirectSettings, TRUE));
147 // test empty redirectUrl
148 $newRedirectSettings = array(
149 Tinebase_Config::REDIRECTURL => '',
150 Tinebase_Config::REDIRECTTOREFERRER => FALSE
153 $this->_uit->saveAuthentication(array('redirectSettings' => $newRedirectSettings));
155 $storedRedirectSettings = array(
156 Tinebase_Config::REDIRECTURL => Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTURL),
157 Tinebase_Config::REDIRECTTOREFERRER => Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTTOREFERRER)
160 foreach ($configNames as $configName) {
161 $this->assertEquals($storedRedirectSettings[$configName], $newRedirectSettings[$configName],
162 'new setting should match stored settings (with empty redirect URL): ' . print_r($newRedirectSettings, TRUE));
165 $this->_uit->saveAuthentication($originalRedirectSettings);
169 * testInstallGroupNameOptions
171 public function testInstallGroupNameOptions()
173 $this->_uninstallAllApplications();
174 $testCredentials = Setup_TestServer::getInstance()->getTestCredentials();
175 $this->_installAllApplications(array(
176 'defaultAdminGroupName' => 'phpunit-admins',
177 'defaultUserGroupName' => 'phpunit-users',
178 'adminLoginName' => $testCredentials['username'],
179 'adminPassword' => $testCredentials['password'],
181 $adminUser = Tinebase_Core::get('currentAccount');
182 $this->assertEquals('phpunit-admins', Tinebase_User::getBackendConfiguration(Tinebase_User::DEFAULT_ADMIN_GROUP_NAME_KEY));
183 $this->assertEquals('phpunit-users', Tinebase_User::getBackendConfiguration(Tinebase_User::DEFAULT_USER_GROUP_NAME_KEY));
185 // setupuser and replication user should be disabled
186 foreach (array('setupuser', 'replicationuser') as $username) {
187 $systemUser = Tinebase_User::getInstance()->getFullUserByLoginName($username);
188 self::assertEquals(Tinebase_Model_User::ACCOUNT_STATUS_DISABLED, $systemUser->accountStatus,
189 $username . ' should be disabled');
194 * test uninstall application
197 public function testUninstallTinebaseShouldThrowDependencyException()
199 $result = $this->_uit->uninstallApplications(array('Tinebase'));
200 $this->assertTrue($this->_uit->setupRequired());
204 * test search applications
207 public function testSearchApplications()
209 $apps = $this->_uit->searchApplications();
211 $this->assertGreaterThan(0, $apps['totalcount']);
214 foreach ($apps['results'] as $app) {
215 if ($app['name'] == 'ActiveSync') {
216 $activeSyncApp = $app;
222 $this->assertTrue(isset($activeSyncApp));
223 $this->assertTrue(isset($activeSyncApp['id']), 'ActiveSync ID missing ' . print_r($apps['results'], true));
224 $this->assertEquals('uptodate', $activeSyncApp['install_status']);
228 * test install application
230 public function testInstallApplications()
233 $result = $this->_uit->installApplications(array('ActiveSync'));
234 } catch (Exception $e) {
235 $this->_uit->uninstallApplications(array('ActiveSync'));
236 $result = $this->_uit->installApplications(array('ActiveSync'));
239 $apps = $this->_uit->searchApplications();
242 foreach ($apps['results'] as $app) {
243 if ($app['name'] == 'ActiveSync') {
244 $activeSyncApp = $app;
250 $applicationId = $activeSyncApp['id'];
252 $this->assertTrue(isset($activeSyncApp));
253 $this->assertTrue(isset($applicationId));
254 $this->assertEquals('enabled', $activeSyncApp['status']);
255 $this->assertEquals('uptodate', $activeSyncApp['install_status']);
257 //check if user role has the right to run the recently installed app
258 $roles = Tinebase_Acl_Roles::getInstance();
259 $userRole = $roles->getRoleByName('user role');
260 $rights = $roles->getRoleRights($userRole->getId());
262 foreach ($rights as $right) {
263 if ($right['application_id'] === $applicationId &&
264 $right['right'] === 'run') {
268 $this->assertTrue($hasRight, 'User role has run right for recently installed app?');
272 * test install applications from dump
274 * @see 0012728: install from (backup) dump
276 public function testInstallFromDump()
278 if ($this->_uit->isInstalled('Tinebase')) {
279 $this->_uninstallAllApplications();
282 $oldTinebaseId = '99a88a21e657b8365bf80ae867e9d06d1c355a39';
284 'backupDir' => dirname(__DIR__) . '/files/2017-02-27-11-42-25',
287 $result = $this->_uit->getInstance()->installFromDump($options);
288 $this->assertTrue($result);
289 $this->assertTrue($this->_uit->isInstalled('Addressbook'), 'Addressbook is not installed');
290 $tinebaseId = Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId();
291 $this->assertNotEquals($oldTinebaseId, $tinebaseId);
292 $this->assertGreaterThan(40, Tinebase_Application::getInstance()->getApplicationTables($tinebaseId));
294 $this->_uninstallAllApplications();
298 * test update application
300 * @todo test real update process; currently this test case only tests updating an already uptodate application
302 public function testUpdateApplications()
304 $applications = new Tinebase_Record_RecordSet('Tinebase_Model_Application');
305 $applications->addRecord(Tinebase_Application::getInstance()->getApplicationByName('ActiveSync'));
306 $result = $this->_uit->updateApplications($applications);
307 $this->assertTrue(is_array($result));
314 public function testEnvCheck()
316 $result = $this->_uit->checkRequirements();
318 $this->assertTrue(isset($result['success']));
319 $this->assertGreaterThan(16, count($result['results']));
323 * uninstallAllApplications
325 protected function _uninstallAllApplications()
327 $installedApplications = Tinebase_Application::getInstance()->getApplications(NULL, 'id');
328 $this->_uit->uninstallApplications($installedApplications->name);
329 Tinebase_Core::unsetTinebaseId();
330 Tinebase_Group::unsetInstance();
331 Tinebase_Acl_Roles::unsetInstance();
332 Tinebase_Core::unsetUser();
333 Tinebase_Cache_PerRequest::getInstance()->reset();
337 * installAllApplications
339 * @param array $_options
340 * @throws Setup_Exception
342 protected function _installAllApplications($_options = null)
345 throw new Setup_Exception('could not run test, Setup_Controller init failed');
348 Tinebase_Core::unsetTinebaseId();
349 Tinebase_Group::unsetInstance();
350 Tinebase_Cache_PerRequest::getInstance()->reset();
351 $installableApplications = $this->_uit->getInstallableApplications();
352 $installableApplications = array_keys($installableApplications);
353 $this->_uit->installApplications($installableApplications, $_options);
357 * @see 11574: backup should only dump structure of some tables
359 public function testGetBackupStructureOnlyTables()
361 require_once __DIR__ . '/Controller_Mock.php';
363 $setupControllerMock = new Setup_Controller_Mock();
365 $tables = $setupControllerMock->getBackupStructureOnlyTables();
367 $this->assertTrue(in_array(SQL_TABLE_PREFIX . 'felamimail_cache_message', $tables), 'felamimail tables need to be in _getBackupStructureOnlyTables');