function TestSetupTrait::prepareDatabasePrefix
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Test/TestSetupTrait.php \Drupal\Core\Test\TestSetupTrait::prepareDatabasePrefix()
- 10 core/lib/Drupal/Core/Test/TestSetupTrait.php \Drupal\Core\Test\TestSetupTrait::prepareDatabasePrefix()
- 11.x core/lib/Drupal/Core/Test/TestSetupTrait.php \Drupal\Core\Test\TestSetupTrait::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 as user agent HTTP header it is also used in the user agent HTTP header value by BrowserTestBase, which is sent to the Drupal installation of the test. During early Drupal all bootstrap, the user agent HTTP header is parsed, and if it matches, database queries use the database table prefix that has been generated here.
See also
\Drupal\Tests\BrowserTestBase::prepareEnvironment()
2 calls to TestSetupTrait::prepareDatabasePrefix()
- InstallerTestBase::setUp in core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerTestBase.php - TestSetupTrait::changeDatabasePrefix in core/
lib/ Drupal/ Core/ Test/ TestSetupTrait.php - Changes the database connection to the prefixed one.
1 method overrides TestSetupTrait::prepareDatabasePrefix()
- TestSiteInstallCommand::prepareDatabasePrefix in core/
tests/ Drupal/ TestSite/ Commands/ TestSiteInstallCommand.php - Generates a database prefix for running tests.
File
-
core/
lib/ Drupal/ Core/ Test/ TestSetupTrait.php, line 150
Class
- TestSetupTrait
- Provides a trait for shared test setup functionality.
Namespace
Drupal\Core\TestCode
protected function prepareDatabasePrefix() {
$test_db = new TestDatabase();
$this->siteDirectory = $test_db->getTestSitePath();
$this->databasePrefix = $test_db->getDatabasePrefix();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.