KernelTestBaseTest
class KernelTestBaseTest extends KernelTestBase (View source)
Tests KernelTestBase functionality.
Traits
Provides test methods to assert content.
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. |
from TestBase |
| protected int | $timeLimit | Time limit for the test. |
from TestBase |
| array | $results | Current results of this test case. |
from TestBase |
| protected array | $assertions | Assertions thrown in that test case. |
from TestBase |
| protected | $skipClasses | This class is skipped when looking for the source of an assertion. |
from TestBase |
| bool | $verbose | TRUE if verbose debugging is enabled. |
from TestBase |
| protected int | $verboseId | Incrementing identifier for verbose output filenames. |
from TestBase |
| protected string | $verboseClassName | Safe class name for use in verbose output filenames. |
from TestBase |
| protected string | $verboseDirectory | Directory where verbose output files are put. |
from TestBase |
| protected string | $verboseDirectoryUrl | URL to the verbose output file directory. |
from TestBase |
| protected string | $originalConf | The original configuration (variables), if available. |
from TestBase |
| protected string | $originalConfig | The original configuration (variables). |
from TestBase |
| protected array | $originalConfigDirectories | The original configuration directories. |
from TestBase |
| protected ContainerInterface | $originalContainer | The original container. |
from TestBase |
| protected string | $originalFileDirectory | The original file directory, before it was changed for testing purposes. |
from TestBase |
| protected LanguageInterface | $originalLanguage | The original language. |
from TestBase |
| protected string | $originalPrefix | The original database prefix when running inside Simpletest. |
from TestBase |
| protected string | $originalSessionName | The name of the session cookie of the test-runner. |
from TestBase |
| protected array | $originalSettings | The settings array. |
from TestBase |
| protected array | $originalShutdownCallbacks | The original array of shutdown function callbacks. |
from TestBase |
| protected AccountProxyInterface | $originalUser | The original user, before testing began. |
from TestBase |
| protected string | $translationFilesDirectory | The translation file directory for the test environment. |
from TestBase |
| bool | $dieOnFail | Whether to die in case any test assertion fails. |
from TestBase |
| protected ConfigImporter | $configImporter | The config importer that can used in a test. |
from TestBase |
| protected int | $httpAuthMethod | HTTP authentication method (specified as a CURLAUTH_* constant). |
from TestBase |
| protected string | $httpAuthCredentials | HTTP authentication credentials ( |
from TestBase |
| static array | $modules | Modules to enable. |
|
| protected array | $configDirectories | The configuration directories for this test run. |
from KernelTestBase |
| protected KeyValueMemoryFactory | $keyValueFactory | A KeyValueMemoryFactory instance to use when building the container. |
from KernelTestBase |
| protected array | $streamWrappers | Array of registered stream wrappers. |
from KernelTestBase |
Methods
Returns the database connection to the site running Simpletest.
Gets the config schema exclusions for this test.
Fail the test if it belongs to a PHPUnit-based framework.
Performs setup tasks before each individual test method is run.
Helper method to store an assertion record in the configured database.
Internal helper: stores the assert.
Store an assertion from outside the testing context.
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.
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.
Provides the data for setting the default language on the container.
Installs default configuration for a given list of modules.
Installs a specific table from a module schema definition.
Installs the storage schema for a specific entity type.
Registers a stream wrapper for this test.
Tests expected behavior of setUp().
Tests expected load behavior of enableModules().
Tests expected installation behavior of enableModules().
Tests installing modules with DependencyInjection services.
Tests expected behavior of installSchema().
Tests expected behavior of installEntitySchema().
Tests expected behavior of installConfig().
Tests that the module list is retained after enabling/installing/disabling.
Tests that ThemeManager works right after loading a module.
Tests that there is no theme by default.
Tests that \Drupal::installProfile() returns NULL.
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.
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.
protected string
prepareConfigDirectories()
Create and set new configuration directories.
containerBuild(ContainerBuilder $container)
Sets up the base service container for this test.
Extend this method in your test to register additional service overrides that need to persist a DrupalKernel reboot. This method is called whenever the kernel is rebuilt.
protected array
defaultLanguageData()
Provides the data for setting the default language on the container.
protected
installConfig(array $modules)
Installs default configuration for a given list of modules.
protected
installSchema(string $module, string|array $tables)
Installs a specific table from a module schema definition.
protected
installEntitySchema(string $entity_type_id)
Installs the storage schema for a specific entity type.
protected
enableModules(array $modules)
Enables modules for this test.
To install test modules outside of the testing environment, add
protected
disableModules(array $modules)
Disables modules for this test.
protected
registerStreamWrapper(string $scheme, string $class, int $type = StreamWrapperInterface::NORMAL)
Registers a stream wrapper for this test.
protected string
render(array $elements)
Renders a render array.
testSetUp()
Tests expected behavior of setUp().
testEnableModulesLoad()
Tests expected load behavior of enableModules().
testEnableModulesInstall()
Tests expected installation behavior of enableModules().
testEnableModulesInstallContainer()
Tests installing modules with DependencyInjection services.
testInstallSchema()
Tests expected behavior of installSchema().
testInstallEntitySchema()
Tests expected behavior of installEntitySchema().
testInstallConfig()
Tests expected behavior of installConfig().
testEnableModulesFixedList()
Tests that the module list is retained after enabling/installing/disabling.
testEnableModulesTheme()
Tests that ThemeManager works right after loading a module.
testNoThemeByDefault()
Tests that there is no theme by default.
testDrupalGetProfile()
Tests that \Drupal::installProfile() returns NULL.
As the currently active installation profile is used when installing configuration, for example, this is essential to ensure test isolation.