TestModuleContext.behat.inc in Lightning Core 8.5
File
tests/contexts/TestModuleContext.behat.inc
View source
<?php
namespace Acquia\LightningExtension\Context;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Scope\ScenarioScope;
use Drupal\Core\Site\Settings;
use Drupal\DrupalExtension\Context\DrupalSubContextBase;
final class TestModuleContext extends DrupalSubContextBase {
private 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);
}
public function install(BeforeScenarioScope $scope) {
$modules = $this
->getModules($scope);
if ($modules) {
$driver = $this
->getDriver();
if (!$driver
->isBootstrapped()) {
$driver
->bootstrap();
}
$settings = Settings::getAll();
$settings['extension_discovery_scan_tests'] = TRUE;
new Settings($settings);
\Drupal::service('module_installer')
->install($modules);
}
}
public function uninstall(AfterScenarioScope $scope) {
$modules = $this
->getModules($scope);
if ($modules) {
\Drupal::service('module_installer')
->uninstall($modules);
}
}
}
Classes
Name |
Description |
TestModuleContext |
Allows test modules to be installed during a scenario and uninstalled after. |