function DrupalWebTestCase::changeDatabasePrefix

Changes the database connection to the prefixed one.

See also

DrupalWebTestCase::setUp()

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

File

modules/simpletest/drupal_web_test_case.php, line 1430

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.