FunctionalTestSetupTrait
trait FunctionalTestSetupTrait (View source)
Defines a trait for shared functional test setup functionality.
Traits
Provides a method to refresh in-memory configuration and state information.
Properties
| protected AccountInterface | $rootUser | The "#1" admin user. |
|
| protected Classloader | $classLoader | The class loader to use for installation and initialization of setup. |
|
| protected deprecated | $configDirectories | The config directories used in this test. |
|
| protected bool | $apcuEnsureUniquePrefix | The flag to set 'apcu_ensure_unique_prefix' setting. |
Methods
Refreshes in-memory configuration and state information.
Prepares site settings and services before installation.
Rewrites the settings.php file of the test site.
Changes parameters in the services.yml file.
Rebuilds \Drupal::getContainer().
Resets all data structures after having enabled new modules.
Creates a mock request and sets it on the generator.
Execute the non-interactive installer.
Initialize settings created during install.
Initialize various configurations post-installation.
Initializes user 1 for the site to be installed.
Initializes the kernel after installation.
Installs the default theme defined by static::$defaultTheme when needed.
Install modules defined by static::$modules.
Resets and rebuilds the environment after setup.
Returns the parameters that will be used when Simpletest installs Drupal.
Sets up the base URL based upon the environment variable.
Prepares the current environment for running the test.
Returns all supported database driver installer objects.
Details
protected
refreshVariables()
Refreshes in-memory configuration and state information.
Useful after a page request is made that changes configuration or state in a different thread.
In other words calling a settings page with $this->drupalPostForm() with a changed value would update configuration to reflect that change, but in the thread that made the call (thread running the test) the changed values would not be picked up.
This method clears the cache and loads a fresh copy.
protected
prepareSettings()
Prepares site settings and services before installation.
protected
writeSettings(array $settings)
Rewrites the settings.php file of the test site.
protected
setContainerParameter(string $name, string $value)
Changes parameters in the services.yml file.
protected
rebuildContainer()
Rebuilds \Drupal::getContainer().
Use this to update the test process's kernel with a new service container. For example, when the list of enabled modules is changed via the internal browser the test process's kernel has a service container with an out of date module list.
protected
resetAll()
Resets all data structures after having enabled new modules.
This method is called by FunctionalTestSetupTrait::rebuildAll() after enabling the requested modules. It must be called again when additional modules are enabled later.
protected Request
prepareRequestForGenerator(bool $clean_urls = TRUE, array $override_server_vars = [])
Creates a mock request and sets it on the generator.
This is used to manipulate how the generator generates paths during tests. It also ensures that calls to $this->drupalGet() will work when running from run-tests.sh because the url generator no longer looks at the global variables that are set there but relies on getting this information from a request object.
protected
doInstall()
Execute the non-interactive installer.
protected
initSettings()
Initialize settings created during install.
protected
initConfig(ContainerInterface $container)
Initialize various configurations post-installation.
protected
initUserSession()
Initializes user 1 for the site to be installed.
protected ContainerInterface
initKernel(Request $request)
Initializes the kernel after installation.
protected
installDefaultThemeFromClassProperty(ContainerInterface $container)
Installs the default theme defined by static::$defaultTheme when needed.
To install a test theme outside of the testing environment, add
protected
installModulesFromClassProperty(ContainerInterface $container)
Install modules defined by static::$modules.
To install test modules outside of the testing environment, add
protected
rebuildAll()
Resets and rebuilds the environment after setup.
protected array
installParameters()
Returns the parameters that will be used when Simpletest installs Drupal.
protected
setupBaseUrl()
Sets up the base URL based upon the environment variable.
protected
prepareEnvironment()
Prepares the current environment for running the test.
Also sets up new resources for the testing environment, such as the public filesystem and configuration directories.
This method is private as it must only be called once by BrowserTestBase::setUp() (multiple invocations for the same test would have unpredictable consequences) and it must not be callable or overridable by test classes.
protected Tasks[]
getDatabaseTypes()
Returns all supported database driver installer objects.
This wraps drupal_get_database_types() for use without a current container.