function test_executeTasksTablesAlter()
 {
     $this->assertTrue($this->initDatabase(325, array('campaigns')) . 'failed to created version 325 of campaigns table');
     $tblCampaigns = $this->oDbh->quoteIdentifier($this->prefix . 'campaigns', true);
     // Insert some data to test the upgrade from... we know the schema being used so we can directly insert
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (1,'campaign one',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'h', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (2,'campaign two',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'm', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (3,'campaign three', 1, -1, -1, -1, '2000-01-01', '2000-01-01', 't', 'l', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (4,'campaign four',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'h', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (5,'campaign five',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'm', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (6,'campaign six',   1, -1, -1, -1, '2000-01-01', '2000-01-01', 't', 'l', 1, 1, 'f', 'f')");
     Mock::generatePartial('OA_DB_UpgradeAuditor', $mockAuditor = 'OA_DB_UpgradeAuditor' . rand(), array('logAuditAction', 'setKeyParams'));
     $oLogger = new OA_UpgradeLogger();
     $oLogger->setLogFile('DB_Upgrade.test.log');
     $oDB_Upgrade = new OA_DB_Upgrade($oLogger);
     $oDB_Upgrade->oAuditor = new $mockAuditor($this);
     $oDB_Upgrade->oAuditor->setReturnValue('logAuditAction', true);
     $oDB_Upgrade->oAuditor->setReturnValue('setKeyParams', true);
     $oDB_Upgrade->init('constructive', 'tables_core', 326);
     $aDef325 = $this->oaTable->aDefinition;
     $oDB_Upgrade->aDBTables = $oDB_Upgrade->_listTables();
     $this->assertTrue($oDB_Upgrade->_verifyTasksTablesAlter(), 'failed _verifyTasksTablesAlter: change field');
     $this->assertTrue($oDB_Upgrade->_executeTasksTablesAlter(), 'failed _executeTasksTablesAlter: change field');
     $aDefDB = $oDB_Upgrade->oSchema->getDefinitionFromDatabase(array($this->prefix . 'campaigns'));
     $aDiff = $oDB_Upgrade->oSchema->compareDefinitions($this->aDefNew, $aDefDb);
     $this->assertEqual(count($aDiff), 0, 'comparison failed');
     $aResults = $this->oDbh->queryAll("SELECT * FROM " . $tblCampaigns);
     $this->assertIsa($aResults, 'array');
     $expected = array(1 => '5', 2 => '3', 3 => '0', 4 => '5', 5 => '3', 6 => '0');
     foreach ($aResults as $idx => $aRow) {
         $this->assertEqual($aRow['priority'], $expected[$aRow['campaignid']], ' unexpected campaign priority value detected after upgrade');
     }
 }
コード例 #2
0
 function upgradeToVersion($version)
 {
     Mock::generatePartial('OA_UpgradeLogger', $mockLogger = 'OA_UpgradeLogger' . rand(), array('logOnly', 'logError', 'log'));
     $oLogger = new $mockLogger($this);
     $oLogger->setReturnValue('logOnly', true);
     $oLogger->setReturnValue('logError', true);
     $oLogger->setReturnValue('log', true);
     $this->oDBUpgrader = new OA_DB_Upgrade($oLogger);
     $this->oDBUpgrader->logFile = MAX_PATH . '/var/DB_Upgrade.test.log';
     $this->oDBUpgrader->initMDB2Schema();
     $auditor = new OA_DB_UpgradeAuditor();
     $this->oDBUpgrader->oAuditor =& $auditor;
     $this->assertTrue($auditor->init($this->oDBUpgrader->oSchema->db), 'error initialising upgrade auditor, probable error creating database action table');
     // execute all database upgrade actions for a given schema version
     // constructive first
     $this->oDBUpgrader->init('constructive', 'tables_core', $version);
     $this->oDBUpgrader->doBackups = false;
     $this->assertTrue($this->oDBUpgrader->upgrade(), 'constructive');
     // use same changeset, switch timing only to execute destructive
     $this->oDBUpgrader->init('destructive', 'tables_core', $version, true);
     $this->assertTrue($this->oDBUpgrader->upgrade(), 'destructive');
 }