Esempio n. 1
0
 /**
  * A method to inser initialise the preferences table and insert the default prefs
  *
  * @param int $adminAccountId
  * @return bool
  */
 function putDefaultPreferences($adminAccountId)
 {
     // Preferences handling
     $oPreferences = new OA_Preferences();
     $aPrefs = $oPreferences->getPreferenceDefaults();
     // Insert default prefs
     foreach ($aPrefs as $prefName => &$aPref) {
         $doPreferences = OA_Dal::factoryDO('preferences');
         $doPreferences->preference_name = $prefName;
         $doPreferences->account_type = empty($aPref['account_type']) ? '' : $aPref['account_type'];
         $preferenceId = $doPreferences->insert();
         if (!$preferenceId) {
             $this->oLogger->logError("error adding preference entry: {$prefName}");
             return false;
         }
         $doAPA = OA_Dal::factoryDO('account_preference_assoc');
         $doAPA->account_id = $adminAccountId;
         $doAPA->preference_id = $preferenceId;
         $doAPA->value = $aPref['default'];
         $result = $doAPA->insert();
         if (!$result) {
             $this->oLogger->logError("error adding preference default for {$prefName}: '" . $aPref['default'] . "'");
             return false;
         }
     }
     return true;
 }
 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');
 }