コード例 #1
0
 /**
  * Creates and truncates the tables in the list $aTables.
  *
  * @param array $aTables Names of the tables to be created.
  */
 function initTables($aTables)
 {
     foreach ($aTables as $table) {
         $result = $this->oaTable->createTable($table);
         if (PEAR::isError($result)) {
             return false;
         }
         $result = $this->oaTable->truncateTable($table);
         if (PEAR::isError($result)) {
             return false;
         }
     }
     return true;
 }
 function test_runScript()
 {
     $GLOBALS['_MAX']['CONF']['table']['prefix'] = $this->prefix;
     $oUpgrade = new OA_Upgrade();
     $oUpgrade->initDatabaseConnection();
     $oDbh =& $oUpgrade->oDbh;
     $oTable = new OA_DB_Table();
     $testfile = MAX_PATH . "/etc/changes/tests/data/schema_tables_core_dashboard.xml";
     $oTable->init($testfile);
     $table = 'preference';
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     if (in_array($this->prefix . $table, $aExistingTables)) {
         $this->assertTrue($oTable->dropTable($this->prefix . $table), 'error dropping ' . $this->prefix . $table);
     }
     $this->assertTrue($oTable->createTable($table), 'error creating ' . $this->prefix . $table);
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($this->prefix . $table, $aExistingTables), $this->prefix . $table . ' table not found');
     $this->assertTrue($oUpgrade->runScript('postscript_openads_upgrade_2.3.36-beta-rc1.php'));
     $aExistingColumns = $oDbh->manager->listTableFields($this->prefix . $table);
     $aColumns = array('ad_clicks_sum', 'ad_views_sum', 'ad_clicks_per_second', 'ad_views_per_second', 'ad_cs_data_last_sent', 'ad_cs_data_last_sent', 'ad_cs_data_last_received');
     foreach ($aColumns as $column) {
         $this->assertFalse(in_array($column, $aExistingColumns, $column . ' found in column list'));
     }
     TestEnv::restoreConfig();
     TestEnv::restoreEnv();
 }
 function test_runScript()
 {
     $oUpgrade = new OA_Upgrade();
     $this->oConfiguration = $oUpgrade->oConfiguration;
     $oUpgrade->initDatabaseConnection();
     $oDbh =& $oUpgrade->oDbh;
     $oTable = new OA_DB_Table();
     $table = 'database_action';
     $testfile = MAX_PATH . "/lib/OA/Upgrade/tests/data/{$table}.xml";
     $oTable->init($testfile);
     $this->assertTrue($oTable->dropTable($this->prefix . $table), 'error dropping ' . $this->prefix . $table);
     $this->assertTrue($oTable->createTable($table), 'error creating ' . $this->prefix . $table);
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($this->prefix . $table, $aExistingTables), 'old database_action table not found');
     $this->assertTrue($oUpgrade->runScript('prescript_openads_upgrade_2.3.33-beta-rc4.php'));
     TestEnv::restoreConfig();
 }
コード例 #4
0
 function _createTestTableConfig($oDbh, $name)
 {
     $oTable = new OA_DB_Table();
     $testpath = MAX_PATH . '/lib/OA/Upgrade/tests/data/';
     $oTable->init($testpath . 'schema_test_config.xml');
     $this->assertTrue($oTable->createTable($name), 'error creating ' . $this->prefix . $name);
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($this->prefix . $name, $aExistingTables), '_createTestTableConfig');
 }
コード例 #5
0
 function test_listBackups()
 {
     $oAuditor = $this->_getAuditObject('OA_DB_UpgradeAuditor');
     $oTable = new OA_DB_Table();
     $oTable->init($this->path . 'schema_test_backups.xml');
     $this->assertTrue($oTable->createTable('z_test1'), 'error creating test backup z_test1');
     $this->assertTrue($oTable->createTable('z_test2'), 'error creating test backup z_test2');
     $this->assertTrue($oTable->createTable('z_test3'), 'error creating test backup z_test3');
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($oAuditor->prefix . 'z_test1', $aExistingTables), '_listBackups');
     $this->assertTrue(in_array($oAuditor->prefix . 'z_test2', $aExistingTables), '_listBackups');
     $this->assertTrue(in_array($oAuditor->prefix . 'z_test3', $aExistingTables), '_listBackups');
     $aBackupTables = $oAuditor->_listBackups();
     $this->assertIsA($aBackupTables, 'array', 'backup array not an array');
     $this->assertEqual(count($aBackupTables), 3, 'wrong number of backups found in database: expected 3 got ' . count($aBackupTables));
     $this->_dropAuditTable($oAuditor->prefix . $oAuditor->logTable);
     $this->_dropAuditTable($oAuditor->prefix . 'z_test1');
     $this->_dropAuditTable($oAuditor->prefix . 'z_test2');
     $this->_dropAuditTable($oAuditor->prefix . 'z_test3');
 }
コード例 #6
0
 /**
  * the action_table_name table must exist for all upgrade events
  * currently the schema is stored in a separate xml file which is not part of an upgrade pkg
  * eventually this table schema should be merged into the core tables schema
  *
  * @return boolean
  */
 function _createAuditTable()
 {
     $xmlfile = MAX_PATH . $this->action_table_xml_filename;
     $oTable = new OA_DB_Table();
     $oTable->init($xmlfile);
     return $oTable->createTable($this->logTable);
 }
コード例 #7
0
 /**
  * internal function to set up some a test table with an autoincrement field
  *
  * @param mdb2 connection $oDbh
  */
 function _createTestTableAutoInc($oDbh)
 {
     $this->_dropTestTables($oDbh);
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['table']['split'] = false;
     $oTable = new OA_DB_Table();
     $oTable->init($this->path . 'schema_test_autoinc.xml');
     $this->assertTrue($oTable->createTable('table1_autoinc'), 'error creating test table1_autoinc');
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue($this->_tableExists('table1_autoinc', $aExistingTables), '_createTestTableAutoInc');
 }
コード例 #8
0
 function test_resetSequence()
 {
     $oDbh =& OA_DB::singleton();
     if ($oDbh->dbsyntax == 'pgsql') {
         $sequence = 'test_table1_test_id1_seq';
     } else {
         if ($oDbh->dbsyntax == 'mysql') {
             $sequence = 'test_table1';
         }
     }
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['table']['prefix'] = '';
     $oTable = new OA_DB_Table();
     $this->_writeSequenceTestDatabaseSchema();
     $oTable->init(MAX_PATH . '/var/test.xml');
     $oTable->createTable('test_table1');
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertEqual($aExistingTables[0], 'test_table1');
     if ($oDbh->dbsyntax == 'pgsql') {
         OA_DB::setCaseSensitive();
         $aSequences = $oDbh->manager->listSequences();
         OA_DB::disableCaseSensitive();
         $this->assertEqual($aSequences[0], 'test_table1_test_id1');
     }
     for ($i = 1; $i < 11; $i++) {
         $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table1', true) . " (test_desc1) VALUES ('{$i}')";
         $oDbh->query($query);
     }
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table1');
     reset($aRows);
     foreach ($aRows as $k => $v) {
         $this->assertTrue($v['test_id1'] == $v['test_desc1'], 'sequence problem with new table');
     }
     $query = "DELETE FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $oDbh->query($query);
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 0, 'failed to delete rows from test_table1');
     $this->assertTrue($oTable->resetSequence($sequence), 'failed to reset sequence on test_table1');
     for ($i = 1; $i < 11; $i++) {
         $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table1', true) . " (test_desc1) VALUES ('{$i}')";
         $oDbh->query($query);
     }
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table1');
     reset($aRows);
     foreach ($aRows as $k => $v) {
         $this->assertTrue($v['test_id1'] == $v['test_desc1'], 'sequence problem after reset: ' . $v['test_id1'] . '=>' . $v['test_desc1']);
     }
     $query = "DELETE FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $oDbh->query($query);
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table1', true);
     $aRows = $oDbh->queryAll($query);
     $this->assertEqual(count($aRows), 0, 'failed to delete rows from test_table1');
     // Test second parameter
     $this->assertTrue($oTable->resetSequence($sequence, 1000), 'failed to reset sequence on test_table1');
     $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table1', true) . " (test_desc1) VALUES ('1')";
     $oDbh->exec($query);
     $nextId = $oDbh->queryOne("SELECT test_id1 FROM " . $oDbh->quoteIdentifier('test_table1', true));
     if ($oDbh->dbsyntax == 'pgsql') {
         $this->assertEqual($nextId, 1000);
     } else {
         $this->assertEqual($nextId, 1);
     }
     $oTable->dropTable('test_table1');
     @unlink(MAX_PATH . '/var/test.xml');
 }
コード例 #9
0
 /**
  * internal function to set up some test tables
  *
  * @param mdb2 connection $oDbh
  */
 function _createTestTables($oDbh)
 {
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     if (!$this->_tableExists('z_test1', $aExistingTables)) {
         $conf =& $GLOBALS['_MAX']['CONF'];
         //$conf['table']['prefix'] = '';
         $oTable = new OA_DB_Table();
         $oTable->init($this->path . 'schema_test_backups.xml');
         $this->assertTrue($oTable->createTable('z_test1'), 'error creating test table1');
         $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
         $this->assertTrue($this->_tableExists('z_test1', $aExistingTables), '_createTestTables');
         return $oTable->aDefinition;
     }
     return false;
 }