function testPutAdmin() { $oUpgrade = new OA_Upgrade(); // Prepare test data $aAdmin = array('email' => '*****@*****.**', 'name' => 'testadmin', 'pword' => 'testpass', 'language' => 'es'); $aPrefs = array('timezone' => 'Europe/Madrid'); // there shouldn't be admin account $adminAccountId = OA_Dal_ApplicationVariables::get('admin_account_id'); $this->assertNull($adminAccountId); // create admin $result = $oUpgrade->putAdmin($aAdmin, $aPrefs); $this->assertTrue($result); // admin account is set $adminAccountId = OA_Dal_ApplicationVariables::get('admin_account_id'); $this->assertNotNull($adminAccountId); $doAccount = OA_Dal::factoryDO('accounts'); $doAccount->get($adminAccountId); $this->assertEqual($doAccount->account_type, OA_ACCOUNT_ADMIN); $this->assertEqual($doAccount->account_name, 'Administrator account'); // user exists $doUser = OA_Dal::factoryDO('users'); $doUserAssoc = OA_Dal::factoryDO('account_user_assoc'); $doUserAssoc->account_id = $adminAccountId; $doUser->joinAdd($doUserAssoc); $doUser->find(); $this->assertTrue($doUser->fetch()); $this->assertEqual($doUser->contact_name, 'Administrator'); $this->assertEqual($doUser->email_address, $aAdmin['email']); $this->assertEqual($doUser->username, $aAdmin['name']); $this->assertEqual($doUser->password, md5($aAdmin['pword'])); $this->assertEqual($doUser->language, $aAdmin['language']); // agency was created $doAgency = OA_Dal::factoryDO('agency'); $doAccount = OA_Dal::factoryDO('accounts'); $doAccount->account_id = $doUser->default_account_id; $doAgency->joinAdd($doAccount); $doAgency->find(); $this->assertTrue($doAgency->fetch()); $this->assertEqual($doAgency->name, 'Default manager'); $this->assertEqual($doAgency->email, $aAdmin['email']); $this->assertEqual($doAgency->active, 1); // Default preferences + custom timezone are set $oPreferences = new OA_Preferences(); $aDefPrefs = $oPreferences->getPreferenceDefaults(); $aExpected = array(); foreach ($aDefPrefs as $name => $values) { $aExpected[$name] = $values['default']; } $aExpected['timezone'] = $aPrefs['timezone']; $aExpected['language'] = 'en'; //added by get admin account preferences $aAdminPreferences = OA_Preferences::loadAdminAccountPreferences(true); $this->assertEqual($aExpected, $aAdminPreferences); // trunkate tables DataGenerator::cleanUp(array('account_preference_assoc', 'preferences', 'account_user_assoc', 'users', 'agency', 'accounts')); // remove admin_account_id from application variables OA_Dal_ApplicationVariables::delete('admin_account_id'); }
$aUrls = array(); if (!OA_Upgrade_Login::checkLogin()) { $message = $strUsernameOrPasswordWrong; $action = OA_UPGRADE_LOGIN; } else { // deal with data from previous page if ($_COOKIE['oat'] == OA_UPGRADE_INSTALL) { OA_Permission::switchToSystemProcessUser('Installer'); $aAdminInfo = $_POST['aAdmin']; // we set the default from: in OpenX emails to the administrator's email if (empty($GLOBALS['_MAX']['CONF']['email']['fromAddress'])) { $oUpgrader->oConfiguration->setValue('email', 'fromAddress', $aAdminInfo['email']); $oUpgrader->oConfiguration->writeConfig(true); } // Save admin credentials $oUpgrader->putAdmin($aAdminInfo); // Save admim account preference for timezone $oUpgrader->putTimezoneAccountPreference($_POST['aPrefs']); } $importErrors = false; // Import any plugins present from the previous install if (isset($_POST['previousPath']) && $_POST['previousPath'] != MAX_PATH) { // Prevent directory traversal and other nasty tricks: $path = rtrim(str_replace("", '', $_POST['previousPath']), '\\/'); if (!stristr($path, '../') && !stristr($path, '..\\')) { $oPluginImporter = new OX_UpgradePluginImport(); $oPluginImporter->basePath = $path; if ($oPluginImporter->verifyAll($GLOBALS['_MAX']['CONF']['plugins'], false)) { // For each plugin that's claimed to be installed... (ex|im)port it into the new codebase foreach ($GLOBALS['_MAX']['CONF']['plugins'] as $plugin => $enabled) { $oPluginImporter->import($plugin);