function test_checkSchemaIntegrity() { $this->path = MAX_PATH . '/lib/OA/Upgrade/tests/data/'; $oDB_Upgrade = $this->_newDBUpgradeObject(); $oTable = new OA_DB_Table(); $oTable->init(MAX_PATH . '/etc/tables_core.xml'); $oTable->dropAllTables(); $prefixOld = $this->prefix; $GLOBALS['_MAX']['CONF']['table']['prefix'] = 'oA_'; $oDB_Upgrade->prefix = 'oA_'; $this->prefix = 'oA_'; // new tables table1 and table2 $this->_createTestTables($oDB_Upgrade->oSchema->db); // get the current definition $oTable->init($this->path . 'schema_test_tables_core2.xml'); $oDB_Upgrade->aDefinitionNew = $oTable->aDefinition; //$oTable->dropAllTables(); // get a changed definition and implement it $oTable->init($this->path . 'schema_test_tables_core1.xml'); $oTable->createAllTables(); // now the following have changed // to *imitate* a broken/tweaked database // missing password_recovery table // new column preference.user_custom_field1 // missing column preference.updates_enabled // changed column zones.cost from dec 10,4 to dec 12,2 $this->assertTrue($oDB_Upgrade->checkSchemaIntegrity(MAX_PATH . '/var/changes_tables_core2'), ''); $aConstructive = $oDB_Upgrade->aChanges['constructive']['tables']; $aDestructive = $oDB_Upgrade->aChanges['destructive']['tables']; $this->assertTrue(isset($aConstructive['add']), 'array of add tables not found'); $this->assertTrue(isset($aConstructive['add']['password_recovery']), 'password_recovery not found in array of add tables'); $this->assertTrue(isset($aConstructive['change']), 'change tables not found'); $this->assertTrue(isset($aConstructive['change']['zones']), 'zones table not found in change array'); $this->assertTrue(isset($aConstructive['change']['zones']['change']['fields']['cost']['length']), 'zones field changes not found in change array'); $this->assertTrue(isset($aConstructive['change']['preference']), 'preference table not found in change array'); $this->assertTrue(isset($aConstructive['change']['preference']['add']['fields']['updates_enabled']), 'preference field changes not found in change array'); $this->assertTrue(isset($aDestructive['remove']), 'remove tables not found'); $this->assertTrue(isset($aDestructive['remove']['table1']), 'table1 not found in remove tables array'); $this->assertTrue(isset($aDestructive['remove']['table2']), 'table2 not found in remove tables array'); $this->assertTrue(isset($aDestructive['change']), 'change tables not found'); $this->assertTrue(isset($aDestructive['change']['preference']), 'preference table not found in change array'); $this->assertTrue(isset($aDestructive['change']['preference']['remove']['user_custom_field1']), 'preference field changes not found in change array'); if (file_exists(MAX_PATH . '/var/changes_tables_core2')) { unlink(MAX_PATH . '/var/changes_tables_core2'); } $oTable->dropAllTables(); $this->prefix = $prefixOld; TestEnv::restoreConfig(); TestEnv::restoreEnv(); }
/** * test reseting of all sequences * * @return boolean true on success, false otherwise */ function test_resetAllSequences() { $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->createAllTables(); $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); $this->assertEqual($aExistingTables[0], 'test_table1'); $this->assertEqual($aExistingTables[1], 'test_table2'); if ($oDbh->dbsyntax == 'pgsql') { OA_DB::setCaseSensitive(); $aSequences = $oDbh->manager->listSequences(); OA_DB::disableCaseSensitive(); $this->assertEqual($aSequences[0], 'test_table1_test_id1'); $this->assertEqual($aSequences[1], 'test_table2_test_id2'); } // 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 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'); // table2 for ($i = 1; $i < 11; $i++) { $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table2', true) . " (test_desc2) VALUES ('{$i}')"; $oDbh->query($query); } $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table2', true); $aRows = $oDbh->queryAll($query); $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table2'); reset($aRows); foreach ($aRows as $k => $v) { $this->assertTrue($v['test_id2'] == $v['test_desc2'], 'sequence problem with new table'); } $query = "DELETE FROM " . $oDbh->quoteIdentifier('test_table2', true); $oDbh->query($query); $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table2', true); $aRows = $oDbh->queryAll($query); $this->assertEqual(count($aRows), 0, 'failed to delete rows from test_table2'); $this->assertTrue($oTable->resetAllSequences(), 'failed to reset all sequences'); // 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']); } $oTable->dropTable('test_table1'); // table2 for ($i = 1; $i < 11; $i++) { $query = "INSERT INTO " . $oDbh->quoteIdentifier('test_table2', true) . " (test_desc2) VALUES ('{$i}')"; $oDbh->query($query); } $query = "SELECT * FROM " . $oDbh->quoteIdentifier('test_table2', true); $aRows = $oDbh->queryAll($query); $this->assertEqual(count($aRows), 10, 'incorrect number of rows in test_table2'); reset($aRows); foreach ($aRows as $k => $v) { $this->assertTrue($v['test_id2'] == $v['test_desc2'], 'sequence problem after reset: ' . $v['test_id2'] . '=>' . $v['test_desc2']); } $oTable->dropTable('test_table2'); @unlink(MAX_PATH . '/var/test.xml'); }