1 backdrop_web_test_case.php | protected BackdropWebTestCase::changeDatabasePrefix() |
Changes the database connection to the prefixed one.
See also
File
- core/
modules/ simpletest/ backdrop_web_test_case.php, line 1498
Class
- BackdropWebTestCase
- Test case for typical Backdrop tests.
Code
protected function changeDatabasePrefix() {
if (empty($this->databasePrefix)) {
$this->prepareDatabasePrefix();
// If $this->prepareDatabasePrefix() failed to work, return without
// setting $this->setupDatabasePrefix to TRUE, so setUp() methods will
// know to bail out.
if (empty($this->databasePrefix)) {
return;
}
}
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
Database::renameConnection('default', 'simpletest_original_default');
foreach ($connection_info as $target => $value) {
$connection_info[$target]['prefix'] = array(
'default' => $value['prefix']['default'] . $this->databasePrefix,
);
}
Database::addConnectionInfo('default', 'default', $connection_info['default']);
// Indicate the database prefix was set up correctly.
$this->setupDatabasePrefix = TRUE;
}