You are here

class TestModuleContext in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 tests/contexts/TestModuleContext.behat.inc \Acquia\LightningExtension\Context\TestModuleContext
  2. 8.2 tests/contexts/TestModuleContext.behat.inc \Acquia\LightningExtension\Context\TestModuleContext
  3. 8.3 tests/contexts/TestModuleContext.behat.inc \Acquia\LightningExtension\Context\TestModuleContext
  4. 8.4 tests/contexts/TestModuleContext.behat.inc \Acquia\LightningExtension\Context\TestModuleContext

Allows test modules to be installed during a scenario and uninstalled after.

Hierarchy

  • class \Acquia\LightningExtension\Context\TestModuleContext extends \Drupal\DrupalExtension\Context\DrupalSubContextBase

Expanded class hierarchy of TestModuleContext

File

tests/contexts/TestModuleContext.behat.inc, line 14

Namespace

Acquia\LightningExtension\Context
View source
class TestModuleContext extends DrupalSubContextBase {

  /**
   * Determines the test modules to install during the scenario.
   *
   * @param ScenarioScope $scope
   *   The current scenario scope.
   *
   * @return string[]
   *   The test modules to install.
   */
  protected function getModules(ScenarioScope $scope) {
    $modules = [];
    $tags = array_merge($scope
      ->getFeature()
      ->getTags(), $scope
      ->getScenario()
      ->getTags());
    foreach ($tags as $tag) {
      if (strpos($tag, 'with-module:') === 0) {
        $modules[] = substr($tag, 12);
      }
    }
    return array_unique($modules);
  }

  /**
   * Installs test modules for this scenario.
   *
   * @param BeforeScenarioScope $scope
   *   The scenario scope.
   *
   * @BeforeScenario
   */
  public function install(BeforeScenarioScope $scope) {
    $modules = $this
      ->getModules($scope);
    if ($modules) {
      $this
        ->getDriver()
        ->bootstrap();

      // Ensure that test directories are scanned for modules.
      $settings = Settings::getAll();
      $settings['extension_discovery_scan_tests'] = TRUE;
      new Settings($settings);
      \Drupal::service('module_installer')
        ->install($modules);
    }
  }

  /**
   * Uninstalls any test modules installed for the scenario.
   *
   * @param AfterScenarioScope $scope
   *   The scenario scope.
   *
   * @AfterScenario
   */
  public function uninstall(AfterScenarioScope $scope) {
    $modules = $this
      ->getModules($scope);
    if ($modules) {
      \Drupal::service('module_installer')
        ->uninstall($modules);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestModuleContext::getModules protected function Determines the test modules to install during the scenario.
TestModuleContext::install public function Installs test modules for this scenario.
TestModuleContext::uninstall public function Uninstalls any test modules installed for the scenario.