You are here

private function BrowserTestBase::prepareDatabasePrefix in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/BrowserTestBase.php \Drupal\simpletest\BrowserTestBase::prepareDatabasePrefix()

Generates a database prefix for running tests.

The database prefix is used by prepareEnvironment() to setup a public files directory for the test to be run, which also contains the PHP error log, which is written to in case of a fatal error. Since that directory is based on the database prefix, all tests (even unit tests) need to have one, in order to access and read the error log.

The generated database table prefix is used for the Drupal installation being performed for the test. It is also used by the cookie value of SIMPLETEST_USER_AGENT by the Mink controlled browser. During early Drupal bootstrap, the cookie is parsed, and if it matches, all database queries use the database table prefix that has been generated here.

See also

drupal_valid_test_ua()

BrowserTestBase::prepareEnvironment()

2 calls to BrowserTestBase::prepareDatabasePrefix()
BrowserTestBase::changeDatabasePrefix in core/modules/simpletest/src/BrowserTestBase.php
Changes the database connection to the prefixed one.
BrowserTestBase::prepareEnvironment in core/modules/simpletest/src/BrowserTestBase.php
Prepares the current environment for running the test.

File

core/modules/simpletest/src/BrowserTestBase.php, line 1026
Contains \Drupal\simpletest\BrowserTestBase.

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\simpletest

Code

private function prepareDatabasePrefix() {

  // Ensure that the generated test site directory does not exist already,
  // which may happen with a large amount of concurrent threads and
  // long-running tests.
  do {
    $suffix = mt_rand(100000, 999999);
    $this->siteDirectory = 'sites/simpletest/' . $suffix;
    $this->databasePrefix = 'simpletest' . $suffix;
  } while (is_dir(DRUPAL_ROOT . '/' . $this->siteDirectory));
}