/** * rollback the upgrade executed during the previous test * copy the *fake* RECOVER file to the var folder * check the audit trail * delete the RECOVER file after * */ function test_recoverUpgrade() { $host = OX_getHostName(); $confFile = $host . '.conf.php'; if (file_exists(MAX_PATH . '/var/test_' . $confFile)) { if (!@unlink(MAX_PATH . '/var/test_' . $confFile)) { $this->oLogger->logError('failed to remove the backup configuration file'); return false; } } if (file_exists(MAX_PATH . '/var/' . $confFile)) { if (!copy(MAX_PATH . '/var/' . $confFile, MAX_PATH . '/var/test_' . $confFile)) { $this->assertTrue(false, 'test failed to backup conf file before upgrade recovery'); return false; } } $oUpgrade = new OA_Upgrade(); $oUpgrade->_pickupRecoveryFile(); $this->_writeTestRecoveryFile(); $oUpgrade->recoverUpgrade(); if (file_exists(MAX_PATH . '/var/' . $confFile)) { if (!@unlink(MAX_PATH . '/var/' . $confFile)) { $this->oLogger->logError('failed to remove the backup configuration file'); return false; } } if (file_exists(MAX_PATH . '/var/test_' . $confFile)) { if (!copy(MAX_PATH . '/var/test_' . $confFile, MAX_PATH . '/var/' . $confFile)) { $this->assertTrue(false, 'test failed to restore the test conf file after upgrade recovery'); return false; } @unlink(MAX_PATH . '/var/test_' . $confFile); } $aAudit = $oUpgrade->oAuditor->queryAuditAllDescending(); // we should have another 13 records in the upgrade_action audit table // we should have another 13 logfiles in the var folder // we should have 13 backup conf files in the var folder // one for each of the 12 packages plus a version stamp *package* $this->assertEqual(count($aAudit), 26, 'wrong number of audit records'); foreach ($aAudit as $k => $aRec) { $idx = 25 - $k; if ($idx > 12) { $this->assertEqual($aRec['upgrade_action_id'], $idx + 1, ''); $this->assertEqual($aRec['action'], UPGRADE_ACTION_ROLLBACK_SUCCEEDED, 'wrong action definition'); $result = $oUpgrade->oAuditor->queryAuditByUpgradeId($k + 1); $this->assertIsA($result, 'array', 'failed to retrieve the original audit record array'); $this->assertTrue(isset($result[0]), 'failed to retrieve the original audit record'); $aOriginalAuditRec = $result[0]; $this->assertEqual($aOriginalAuditRec['confbackup'], 'dropped during recovery', 'failure to audit that conf was dropped'); //$aOriginalAuditRec['confbackup']); // recovery should restore then drop the backup tables if (file_exists(MAX_PATH . '/var/' . ($k + 11) . '_old.www.mysite.net.conf.php')) { $this->assertFalse(true, 'conf backup was not deleted'); @unlink(MAX_PATH . '/var/' . ($k + 11) . '_old.www.mysite.net.conf.php'); } $this->assertTrue(file_exists(MAX_PATH . '/var/' . $aRec['logfile']), 'logfile does not exist'); $this->assertEqual($aRec['logfile'], $aOriginalAuditRec['logfile'] . '.rollback', 'wrong log file'); @unlink(MAX_PATH . '/var/' . $aRec['logfile']); $this->assertEqual($aRec['upgrade_name'], $aOriginalAuditRec['upgrade_name'], 'package mismatch: ' . $aRec['upgrade_name'] . ' and ' . $aOriginalAuditRec['upgrade_name']); } } // the application variable should match the initial version given in the previous test $this->assertEqual($oUpgrade->oVersioner->getApplicationVersion(), '2.3.32-beta-rc1', 'wrong initial application version: ' . $oUpgrade->versionInitialApplication); $this->assertFalse(file_exists($oUpgrade->recoveryFile), 'recovery file was not deleted after recovery'); // just in case of error, lose the recovery file so we can continue afresh // and not screw up someone's installation next time they run $oUpgrade->_pickupRecoveryFile(); // delete the *restored* dummy conf file @unlink(MAX_PATH . '/var/www.mysite.net.conf.php'); }
function test_getOriginalApplicationVersion() { $oUpgrade = new OA_Upgrade(); Mock::generatePartial('OA_UpgradeAuditor', $mockAuditor = 'OA_UpgradeAuditor' . rand(), array('queryAuditByUpgradeId', "getUpgradeActionId")); $oUpgrade->oAuditor = new $mockAuditor($this); $oUpgrade->oAuditor->setReturnValueAt(0, 'getUpgradeActionId', 1); $this->assertTrue($oUpgrade->_writeRecoveryFile(), 'failed to write recovery file'); $oUpgrade->oAuditor->setReturnValueAt(1, 'getUpgradeActionId', 2); $this->assertTrue($oUpgrade->_writeRecoveryFile(), 'failed to write recovery file'); $oUpgrade->oAuditor->setReturnValueAt(2, 'getUpgradeActionId', 3); $this->assertTrue($oUpgrade->_writeRecoveryFile(), 'failed to write recovery file'); $aAudit = array(0 => array('upgrade_action_id' => 1, 'upgrade_name' => 'openads_upgrade_2.0.11_to_2.3.0', 'version_to' => '2.3.0', 'version_from' => '2.0.11')); $oUpgrade->oAuditor->setReturnValue('queryAuditByUpgradeId', $aAudit); $this->assertEqual($oUpgrade->getOriginalApplicationVersion(), '2.0.11'); $oUpgrade->_pickupRecoveryFile(); }