TestBase deprecated
abstract class TestBase (View source)
deprecated
Base class for Drupal tests.
Do not extend this class directly; use \Drupal\simpletest\WebTestBase.
Traits
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. |
from TestSetupTrait |
| protected ContainerInterface | $container | The dependency injection container used in the test. |
from TestSetupTrait |
| protected string | $siteDirectory | The site directory of this test run. |
from TestSetupTrait |
| protected string | $publicFilesDirectory | The public file directory for the test environment. |
from TestSetupTrait |
| protected string | $originalSite | The site directory of the original parent site. |
from TestSetupTrait |
| protected string | $privateFilesDirectory | The private file directory for the test environment. |
from TestSetupTrait |
| protected bool | $strictConfigSchema | Set to TRUE to strict check all configuration saved. |
from TestSetupTrait |
| protected DrupalKernel | $kernel | The DrupalKernel instance used in the test. |
from TestSetupTrait |
| protected string | $tempFilesDirectory | The temporary file directory for the test environment. |
from TestSetupTrait |
| protected string | $testId | The test run ID. |
from TestSetupTrait |
| protected string | $databasePrefix | The database prefix of this test run. |
|
| protected int | $timeLimit | Time limit for the test. |
|
| array | $results | Current results of this test case. |
|
| protected array | $assertions | Assertions thrown in that test case. |
|
| protected | $skipClasses | This class is skipped when looking for the source of an assertion. |
|
| bool | $verbose | TRUE if verbose debugging is enabled. |
|
| protected int | $verboseId | Incrementing identifier for verbose output filenames. |
|
| protected string | $verboseClassName | Safe class name for use in verbose output filenames. |
|
| protected string | $verboseDirectory | Directory where verbose output files are put. |
|
| protected string | $verboseDirectoryUrl | URL to the verbose output file directory. |
|
| protected string | $originalConf | The original configuration (variables), if available. |
|
| protected string | $originalConfig | The original configuration (variables). |
|
| protected array | $originalConfigDirectories | The original configuration directories. |
|
| protected ContainerInterface | $originalContainer | The original container. |
|
| protected string | $originalFileDirectory | The original file directory, before it was changed for testing purposes. |
|
| protected LanguageInterface | $originalLanguage | The original language. |
|
| protected string | $originalPrefix | The original database prefix when running inside Simpletest. |
|
| protected string | $originalSessionName | The name of the session cookie of the test-runner. |
|
| protected array | $originalSettings | The settings array. |
|
| protected array | $originalShutdownCallbacks | The original array of shutdown function callbacks. |
|
| protected AccountProxyInterface | $originalUser | The original user, before testing began. |
|
| protected string | $translationFilesDirectory | The translation file directory for the test environment. |
|
| bool | $dieOnFail | Whether to die in case any test assertion fails. |
|
| protected ConfigImporter | $configImporter | The config importer that can used in a test. |
|
| protected int | $httpAuthMethod | HTTP authentication method (specified as a CURLAUTH_* constant). |
|
| protected string | $httpAuthCredentials | HTTP authentication credentials ( |
Methods
Returns the database connection to the site running Simpletest.
Gets the config schema exclusions for this test.
Constructor for Test.
Fail the test if it belongs to a PHPUnit-based framework.
Performs setup tasks before each individual test method is run.
Checks the matching requirements for Test.
Helper method to store an assertion record in the configured database.
Internal helper: stores the assert.
Store an assertion from outside the testing context.
Delete an assertion record by message ID.
Cycles through backtrace until the first non-assertion method is found.
Check to see if a value is not false.
Check to see if a value is false.
Check to see if a value is NULL.
Check to see if a value is not NULL.
Check to see if two values are equal.
Check to see if two values are not equal.
Check to see if two values are identical.
Check to see if two values are not identical.
Checks to see if two objects are identical.
Asserts that no errors have been logged to the PHP error.log thus far.
Asserts that a specific error has been logged to the PHP error log.
Fire an assertion that is always positive.
Fire an assertion that is always negative.
Fire an error assertion.
Logs a verbose message in a text file.
Run all tests in this class.
Act on global state information before the environment is altered for a test.
Performs cleanup tasks after each individual test method has been run.
Handle errors during test runs.
Handle exceptions.
Changes in memory settings.
Ensures test files are deletable.
Gets the database prefix.
Gets the temporary files directory.
Details
static Connection
getDatabaseConnection()
Returns the database connection to the site running Simpletest.
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.
protected
changeDatabasePrefix()
Changes the database connection to the prefixed one.
protected string[]
getConfigSchemaExclusions()
Gets the config schema exclusions for this test.
__construct($test_id = NULL)
Constructor for Test.
checkTestHierarchyMismatch()
Fail the test if it belongs to a PHPUnit-based framework.
This would probably be caused by automated test conversions such as those in https://www.drupal.org/project/drupal/issues/2770921.
abstract protected
setUp()
Performs setup tasks before each individual test method is run.
protected array
checkRequirements()
Checks the matching requirements for Test.
protected StatementInterface|int|null
storeAssertion(array $assertion)
Helper method to store an assertion record in the configured database.
This method decouples database access from assertion logic.
protected
assert($status, string|MarkupInterface $message = '', $group = 'Other', array $caller = NULL)
Internal helper: stores the assert.
static Message
insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = [])
deprecated
deprecated
Store an assertion from outside the testing context.
This is useful for inserting assertions that can only be recorded after the test case has been destroyed, such as PHP fatal errors. The caller information is not automatically gathered since the caller is most likely inserting the assertion on behalf of other code. In all other respects the method behaves just like \Drupal\simpletest\TestBase::assert() in terms of storing the assertion.
static true
deleteAssert($message_id)
Delete an assertion record by message ID.
protected array
getAssertionCall()
Cycles through backtrace until the first non-assertion method is found.
protected true
assertTrue($value, $message = '', $group = 'Other')
Check to see if a value is not false.
False values are: empty string, 0, NULL, and FALSE.
protected true
assertFalse($value, $message = '', $group = 'Other')
Check to see if a value is false.
False values are: empty string, 0, NULL, and FALSE.
protected true
assertNull($value, $message = '', $group = 'Other')
Check to see if a value is NULL.
protected true
assertNotNull($value, $message = '', $group = 'Other')
Check to see if a value is not NULL.
protected true
assertEqual($first, $second, $message = '', $group = 'Other')
Check to see if two values are equal.
protected true
assertNotEqual($first, $second, $message = '', $group = 'Other')
Check to see if two values are not equal.
protected true
assertIdentical($first, $second, $message = '', $group = 'Other')
Check to see if two values are identical.
protected true
assertNotIdentical($first, $second, $message = '', $group = 'Other')
Check to see if two values are not identical.
protected true
assertIdenticalObject(object $object1, object $object2, $message = '', $group = 'Other')
Checks to see if two objects are identical.
protected bool
assertNoErrorsLogged()
Asserts that no errors have been logged to the PHP error.log thus far.
protected bool
assertErrorLogged(string $error_message)
Asserts that a specific error has been logged to the PHP error log.
protected
pass($message = NULL, $group = 'Other')
Fire an assertion that is always positive.
protected
fail($message = NULL, $group = 'Other')
Fire an assertion that is always negative.
protected
error($message = '', $group = 'Other', array $caller = NULL)
Fire an error assertion.
protected
verbose($message)
Logs a verbose message in a text file.
The link to the verbose message will be placed in the test results as a passing assertion with the text '[verbose message]'.
run(array $methods = [])
Run all tests in this class.
Regardless of whether $methods are passed or not, only method names starting with "test" are executed.
protected
beforePrepareEnvironment()
Act on global state information before the environment is altered for a test.
Allows e.g. KernelTestBase to prime system/extension info from the parent site (and inject it into the test environment so as to improve performance).
protected
tearDown()
Performs cleanup tasks after each individual test method has been run.
errorHandler($severity, $message, $file = NULL, $line = NULL)
Handle errors during test runs.
Because this is registered in set_error_handler(), it has to be public.
protected
exceptionHandler($exception)
Handle exceptions.
protected
settingsSet($name, $value)
Changes in memory settings.
static
filePreDeleteCallback($path)
Ensures test files are deletable.
Some tests chmod generated files to be read only. During TestBase::restoreEnvironment() and other cleanup operations, these files need to get deleted too.
protected Config
config($name)
Configuration accessor for tests. Returns non-overridden configuration.
string
getDatabasePrefix()
Gets the database prefix.
string
getTempFilesDirectory()
Gets the temporary files directory.