function FunctionalTestSetupTrait::installModulesFromClassProperty

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installModulesFromClassProperty()
  2. 8.9.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installModulesFromClassProperty()
  3. 11.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installModulesFromClassProperty()

Install modules defined by `static::$modules`.

To install test modules outside of the testing environment, add

$settings['extension_discovery_scan_tests'] = TRUE;

to your settings.php.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The container.

6 calls to FunctionalTestSetupTrait::installModulesFromClassProperty()
BrowserTestBase::installDrupal in core/tests/Drupal/Tests/BrowserTestBase.php
Installs Drupal into the test site.
ViewsAddDefaultPaginationHeaderTest::setUp in core/modules/views/tests/src/Functional/Update/ViewsAddDefaultPaginationHeaderTest.php
ViewsAddMissingLabelsUpdateTest::setUp in core/modules/views/tests/src/Functional/Update/ViewsAddMissingLabelsUpdateTest.php
ViewsFixRevisionIdUpdateTest::setUp in core/modules/views/tests/src/Functional/Update/ViewsFixRevisionIdUpdateTest.php
ViewsRemoveDefaultArgumentSkipUrlTest::setUp in core/modules/views/tests/src/Functional/Update/ViewsRemoveDefaultArgumentSkipUrlTest.php

... See full list

1 method overrides FunctionalTestSetupTrait::installModulesFromClassProperty()
WebDriverTestBase::installModulesFromClassProperty in core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
Install modules defined by `static::$modules`.

File

core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php, line 488

Class

FunctionalTestSetupTrait
Defines a trait for shared functional test setup functionality.

Namespace

Drupal\Core\Test

Code

protected function installModulesFromClassProperty(ContainerInterface $container) {
    $class = static::class;
    $modules = [];
    while ($class) {
        if (property_exists($class, 'modules')) {
            $modules = array_merge($modules, $class::$modules);
        }
        $class = get_parent_class($class);
    }
    if ($modules) {
        $modules = array_unique($modules);
        try {
            $success = $container->get('module_installer')
                ->install($modules, TRUE);
            $this->assertTrue($success, 'Enabled modules: ' . implode(', ', $modules));
        } catch (MissingDependencyException $e) {
            // The exception message has all the details.
            $this->fail($e->getMessage());
        }
        // The container was already rebuilt by the ModuleInstaller.
        $this->container = \Drupal::getContainer();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.