protected function TestSetupTrait::prepareDatabasePrefix in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Test/TestSetupTrait.php \Drupal\Core\Test\TestSetupTrait::prepareDatabasePrefix()
- 9 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()
1 call to TestSetupTrait::prepareDatabasePrefix()
- InstallerTestBase::setUp in core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerTestBase.php
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 133
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();
}