trait TestSetupTrait (View source)

Provides a trait for shared test setup functionality.

Properties

static protected string[] $configSchemaCheckerExclusions

An array of config object names that are excluded from schema checking.

protected ContainerInterface $container

The dependency injection container used in the test.

protected string $siteDirectory

The site directory of this test run.

protected string $publicFilesDirectory

The public file directory for the test environment.

protected string $originalSite

The site directory of the original parent site.

protected string $privateFilesDirectory

The private file directory for the test environment.

protected bool $strictConfigSchema

Set to TRUE to strict check all configuration saved.

protected DrupalKernel $kernel

The DrupalKernel instance used in the test.

protected string $tempFilesDirectory

The temporary file directory for the test environment.

protected string $testId

The test run ID.

Methods

static Connection
getDatabaseConnection()

Returns the database connection to the site running Simpletest.

prepareDatabasePrefix()

Generates a database prefix for running tests.

changeDatabasePrefix()

Changes the database connection to the prefixed one.

string[]
getConfigSchemaExclusions()

Gets the config schema exclusions for this test.

Details

static Connection getDatabaseConnection()

Returns the database connection to the site running Simpletest.

Return Value

Connection

The database connection to use for inserting assertions.

protected 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 value by the cURL-based browser of WebTestBase, 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

\Drupal\Tests\BrowserTestBase::prepareEnvironment()
WebTestBase::curlInitialize
\Drupal\simpletest\TestBase::prepareEnvironment()
drupal_valid_test_ua()

protected changeDatabasePrefix()

Changes the database connection to the prefixed one.

protected string[] getConfigSchemaExclusions()

Gets the config schema exclusions for this test.

Return Value

string[]

An array of config object names that are excluded from schema checking.