You are here

protected function DrupalWebTestCase::prepareDatabasePrefix in Drupal 7

Generates a database prefix for running tests.

The generated database table prefix is used for the Drupal installation being performed for the test. It is also used as user agent HTTP header value by the cURL-based browser of DrupalWebTestCase, which is sent to the Drupal installation of the test. During early Drupal bootstrap, the user agent HTTP header is parsed, and if it matches, all database queries use the database table prefix that has been generated here.

See also

DrupalWebTestCase::curlInitialize()

drupal_valid_test_ua()

DrupalWebTestCase::setUp()

3 calls to DrupalWebTestCase::prepareDatabasePrefix()
DrupalWebTestCase::changeDatabasePrefix in modules/simpletest/drupal_web_test_case.php
Changes the database connection to the prefixed one.
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 1358

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function prepareDatabasePrefix() {
  $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);

  // As soon as the database prefix is set, the test might start to execute.
  // All assertions as well as the SimpleTest batch operations are associated
  // with the testId, so the database prefix has to be associated with it.
  db_update('simpletest_test_id')
    ->fields(array(
    'last_prefix' => $this->databasePrefix,
  ))
    ->condition('test_id', $this->testId)
    ->execute();
}