protected function DrupalWebTestCase::changeDatabasePrefix

7.x drupal_web_test_case.php protected DrupalWebTestCase::changeDatabasePrefix()

Changes the database connection to the prefixed one.

See also

DrupalWebTestCase::setUp()

2 calls to DrupalWebTestCase::changeDatabasePrefix()
DrupalWebTestCase::setUp in drupal/modules/simpletest/drupal_web_test_case.php
Sets up a Drupal site for running functional and integration tests.
UpgradePathTestCase::setUp in drupal/modules/simpletest/tests/upgrade/upgrade.test
Overrides DrupalWebTestCase::setUp() for upgrade testing.

File

drupal/modules/simpletest/drupal_web_test_case.php, line 1302

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;
}