/** * tests an openads upgrade where a series of upgrade packages may be required * the upgrade method will detectOpenXand cycle through the list of upgrade packages * executing the upgrade packages in the right order * until it runs out of upgrade packages * when no more upgrade packages are found * the application is stamped with the latest version * */ function test_upgradeIncremental() { $oUpgrade = new OA_Upgrade(); Mock::generatePartial('OA_Upgrade_Config', $mockConfig = 'OA_Upgrade_Config' . rand(), array('backupConfig', 'mergeConfig', 'setupConfigDatabase', 'setupConfigTable', 'setValue', 'writeConfig', 'getConfigBackupName', 'clearConfigBackupName', 'setBulkValue')); $oUpgrade->oConfiguration = new $mockConfig($this); $oUpgrade->oConfiguration->setReturnValue('setupConfigDatabase', true); $oUpgrade->oConfiguration->setReturnValue('setupConfigTable', true); $oUpgrade->oConfiguration->setReturnValue('setValue', true); $oUpgrade->oConfiguration->setReturnValue('writeConfig', true); $oUpgrade->oConfiguration->expectCallCount('backupConfig', 1); $oUpgrade->oConfiguration->setReturnValue('backupConfig', true); $oUpgrade->oConfiguration->expectCallCount('mergeConfig', 1); $oUpgrade->oConfiguration->setReturnValue('mergeConfig', true); $oUpgrade->oConfiguration->expectCallCount('getConfigBackupName', 13); for ($i = 0; $i < 13; $i++) { $oUpgrade->oConfiguration->setReturnValueAt($i, 'getConfigBackupName', $i . '_old.www.mysite.net.conf.php'); // drop a fake conf backup @copy(MAX_PATH . '/var/test.conf.php', MAX_PATH . '/var/' . $i . '_old.www.mysite.net.conf.php'); } // divert objects to test data $oUpgrade->upgradePath = MAX_PATH . '/lib/OA/Upgrade/tests/data/changes/'; $GLOBALS['_MAX']['CONF']['openads']['installed'] = true; $this->_dropTestTable($oUpgrade->oDbh, 'database_action'); $this->_dropTestTable($oUpgrade->oDbh, 'upgrade_action'); // just in case of error, lose this so we can continue afresh $oUpgrade->_pickupRecoveryFile(); // fake the versions we are starting with $this->_createTestAppVarRecord('oa_version', '2.3.32-beta-rc1'); // mock the integrity checker Mock::generatePartial('OA_DB_Integrity', $mockInteg = 'OA_DB_Integrity' . rand(), array('checkIntegrityQuick')); $oUpgrade->oIntegrity = new $mockInteg($this); $oUpgrade->oIntegrity->setReturnValue('checkIntegrityQuick', true); // do the initial detection $this->assertTrue($oUpgrade->detectOpenads()); // this should identify 12 upgrade packages to be executed // (from /lib/OA/Upgrade/tests/data/changes) $this->assertEqual(count($oUpgrade->aPackageList), 12, 'wrong number of packages in upgrader package list'); $this->assertIsA($oUpgrade->oAuditor, 'OA_UpgradeAuditor', 'class mismatch: OA_UpgradeAuditor'); // perform the upgrade $this->assertTrue($oUpgrade->upgrade(), 'upgrade'); $aAudit = $oUpgrade->oAuditor->queryAuditAllDescending(); // we should have 13 records in the upgrade_action audit table // we should have 13 logfiles in the var folder // one for each package plus a version stamp $this->assertEqual(count($aAudit), 13, 'wrong number of audit records'); $aPackageList = $oUpgrade->aPackageList; krsort($aPackageList, SORT_NUMERIC); foreach ($aAudit as $k => $aRec) { $idx = 12 - $k; $this->assertEqual($aRec['upgrade_action_id'], $idx + 1, ''); $this->assertEqual($aRec['confbackup'], $idx . '_old.www.mysite.net.conf.php'); $this->assertTrue(file_exists(MAX_PATH . '/var/' . $aRec['logfile'])); @unlink(MAX_PATH . '/var/' . $aRec['logfile']); if ($k > 0) { $this->assertEqual($aRec['upgrade_name'], $aPackageList[$idx], 'package mismatch: ' . $aRec['upgrade_name'] . ' and ' . $aPackageList[$idx]); } else { $this->assertEqual($aRec['upgrade_name'], 'openads_version_stamp_' . VERSION, 'wrong package name for version stamp'); } } // the application variable should match the code version stamp $this->assertEqual($oUpgrade->versionInitialApplication, VERSION, 'wrong initial application version: ' . $oUpgrade->versionInitialApplication); // $this->_deleteTestAppVarRecordAllNames('oa_version'); $oUpgrade->oConfiguration->tally(); $oUpgrade->oIntegrity->tally(); TestEnv::restoreConfig(); }
$message = $strUsernameOrPasswordWrong; $action = OA_UPGRADE_LOGIN; } elseif ($oUpgrader->canUpgrade()) { $installStatus = $oUpgrader->existing_installation_status; define('DISABLE_ALL_EMAILS', 1); OA_Permission::switchToSystemProcessUser('Installer'); if ($installStatus == OA_STATUS_NOT_INSTALLED) { if ($oUpgrader->install($_POST['aConfig'])) { $message = $strDBCreatedSuccesful . ' ' . OA_VERSION; $action = OA_UPGRADE_INSTALL; } } else { if (empty($_COOKIE['oat']) || $_COOKIE['oat'] != OA_UPGRADE_UPGRADE) { // Hey, what's going on, we shouldn't be here, go back to login! $action = OA_UPGRADE_LOGIN; } elseif ($oUpgrader->upgrade($oUpgrader->package_file)) { $message = $strUpgradeComplete; $action = OA_UPGRADE_UPGRADE; // Timezone support - hack if ($oUpgrader->versionInitialSchema['tables_core'] < 538 && empty($_POST['noTzAlert'])) { OA_Dal_ApplicationVariables::set('utc_update', OA::getNowUTC()); } // Clear the menu cache to built a new one with the new settings OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADMIN); OA_Admin_Menu::_clearCache(OA_ACCOUNT_MANAGER); OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADVERTISER); OA_Admin_Menu::_clearCache(OA_ACCOUNT_TRAFFICKER); OA_Admin_Menu::singleton(); } } }