1.20.x backdrop_web_test_case.php | protected BackdropWebTestCase::changeDatabasePrefix() |
Changes the database connection to the prefixed one.
See also
File
- modules/
simpletest/ backdrop_web_test_case.php, line 1502
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;
}