protected function DrupalWebTestCase::changeDatabasePrefix
7.x drupal_web_test_case.php | protected DrupalWebTestCase::changeDatabasePrefix() |
Changes the database connection to the prefixed one.
See also
1 call to DrupalWebTestCase::changeDatabasePrefix()
- DrupalWebTestCase::setUp in drupal-7.x/
modules/ simpletest/ drupal_web_test_case.php - Sets up a Drupal site for running functional and integration tests.
File
- drupal-7.x/
modules/ simpletest/ drupal_web_test_case.php, line 1315
Class
- DrupalWebTestCase
- Test case for typical Drupal 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;
}