Commit 35c7673c authored by Dries's avatar Dries

- Patch #327480 by chx: remove DB specific code from simpletest.

parent a1d1cb5c
......@@ -1674,6 +1674,18 @@ function db_column_exists($table, $column) {
return Database::getActiveConnection()->schema()->columnExists($table, $column);
}
/**
* Find all tables that are like the specified base table name.
*
* @param table_expression
* An SQL expression, for example simpletest% . BEWARE: this is not
* prefixed, the caller should take care of that.
* @return
* Array, both the keys and the values are the matching tables.
*/
function db_find_tables($table_expression) {
return Database::getActiveConnection()->schema()->findTables($table_expression);
}
/**
* Given a Schema API field type, return the correct %-placeholder.
......
......@@ -405,6 +405,24 @@ public function fieldNames($fields) {
return $ret;
}
/**
* Find all tables that are like the specified base table name.
*
* @param table_expression
* An SQL expression, for example "simpletest%" (without the quotes).
* BEWARE: this is not prefixed, the caller should take care of that.
* @return
* Array, both the keys and the values are the matching tables.
*/
public function findTables($table_expression) {
global $db_prefix;
$info = Database::getConnectionInfo();
$result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = :database AND table_name LIKE :table_name", array(
':database' => $info['default']['database'],
':table_name' => $table_expression,
));
return $result->fetchAllKeyed(0, 0);
}
}
/**
......
......@@ -505,10 +505,10 @@ function simpletest_clean_environment() {
* Removed prefixed talbes from the database that are left over from crashed tests.
*/
function simpletest_clean_database() {
$tables = simpletest_get_like_tables();
$tables = db_find_tables(Database::getActiveConnection()->prefixTables('simpletest') . '%');
$schema = drupal_get_schema_unprocessed('simpletest');
$ret = array();
foreach ($tables as $table) {
foreach (array_diff_key($tables, $schema) as $table) {
db_drop_table($ret, $table);
}
......@@ -520,36 +520,6 @@ function simpletest_clean_database() {
}
}
/**
* Find all tables that are like the specified base table name.
*
* @param string $base_table Base table name.
* @param boolean $count Return the table count instead of list of tables.
* @return mixed Array of matching tables or count of tables.
*/
function simpletest_get_like_tables($base_table = 'simpletest', $count = FALSE) {
global $db_prefix, $database;
$connection_info = Database::getConnectionInfo();
$database_name = $connection_info['default']['database'];
$select = $count ? 'COUNT(table_name)' : 'table_name';
$result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = :database AND table_name LIKE :table_name", array(
':database' => $database_name,
':table_name' => $db_prefix . $base_table . '%',
));
$schema = drupal_get_schema_unprocessed('simpletest');
if ($count) {
return db_result($result);
}
$tables = array();
while ($table = db_result($result)) {
if (!isset($schema[$table])) {
$tables[] = $table;
}
}
return $tables;
}
/**
* Find all left over temporary directories and remove them.
*/
......
......@@ -118,12 +118,12 @@ class EnableDisableCoreTestCase extends DrupalWebTestCase {
* @return boolean Tables with specified base table.
*/
function assertTableCount($base_table, $count) {
$match_count = simpletest_get_like_tables($base_table, TRUE);
$tables = db_find_tables(Database::getActiveConnection()->prefixTables($base_table) . '%');
if ($count) {
return $this->assertTrue($match_count, t('Tables matching "@base_table" found.', array('@base_table' => $base_table)));
return $this->assertTrue($tables, t('Tables matching "@base_table" found.', array('@base_table' => $base_table)));
}
return $this->assertFalse($match_count, t('Tables matching "@base_table" not found.', array('@base_table' => $base_table)));
return $this->assertFalse($tables, t('Tables matching "@base_table" not found.', array('@base_table' => $base_table)));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment