diff --git a/behat.yml.dist b/behat.yml.dist index eb9bcce0..fb24f7d9 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -8,6 +8,7 @@ default: - Drupal\DrupalExtension\Context\MessageContext - Drupal\DrupalExtension\Context\MinkContext - Drupal\DrupalExtension\Context\MarkupContext + - Drupal\DrupalExtension\Context\TestModuleContext filters: tags: "@blackbox" extensions: diff --git a/composer.json b/composer.json index e5ecd2b2..5ab14427 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "behat/mink-extension": "~2.0", "behat/mink-goutte-driver": "~1.0", "behat/mink-selenium2-driver": "~1.1", - "drupal/drupal-driver": "dev-master", + "drupal/drupal-driver": "dev-master#e692d85d56fc613d2601619d7873d157c724112b", "symfony/dependency-injection": "~2.7|~3.0", "symfony/event-dispatcher": "~2.7|~3.0" }, diff --git a/doc/contexts.rst b/doc/contexts.rst index 6a722135..63d3649f 100644 --- a/doc/contexts.rst +++ b/doc/contexts.rst @@ -37,6 +37,14 @@ following contexts: *BatchContext* Steps for creating batch items and ensuring a batch is finished processing. +*TestModuleContext* + Allows modules to be automatically installed during a scenario, then + automatically uninstalled afterwards. Scenarios can enable as many modules as + they like using tags; for example, a scenario with the ```@with-module:webform``` + tag will install Webform before the scenario begins, then uninstall it after + the scenario ends. Features can also use this tag to enable modules for every + one of their scenarios. + Custom Contexts --------------- diff --git a/features/modules.feature b/features/modules.feature new file mode 100644 index 00000000..c6554556 --- /dev/null +++ b/features/modules.feature @@ -0,0 +1,10 @@ +@api @d8 +Feature: Ensure that test modules are automatically enabled in annotated scenarios + In order to use special test modules during test scenarios + Modules should be automatically enabled + + @with-module:migrate + Scenario: Enabling a module + Given I am logged in as a user with the "administer modules" permission + When I visit "/admin/modules" + Then the checkbox "modules[migrate][enable]" should be checked diff --git a/src/Drupal/DrupalExtension/Context/TestModuleContext.php b/src/Drupal/DrupalExtension/Context/TestModuleContext.php new file mode 100644 index 00000000..9e189361 --- /dev/null +++ b/src/Drupal/DrupalExtension/Context/TestModuleContext.php @@ -0,0 +1,64 @@ +getFeature()->getTags(), $scope->getScenario()->getTags()); + + foreach ($tags as $tag) { + if (strpos($tag, 'with-module:') === 0) { + array_push($modules, substr($tag, 12)); + } + } + return array_unique($modules); + } + + /** + * Installs test modules for this scenario. + * + * @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope + * The scenario scope. + * + * @BeforeScenario + */ + public function installTestModules(BeforeScenarioScope $scope) + { + foreach ($this->getTestModulesFromTags($scope) as $module) { + $this->getDriver()->moduleInstall($module); + } + } + + /** + * Unistalls test modules for this scenario. + * + * @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope + * The scenario scope. + * + * @AfterScenario + */ + public function uninstallTestModules(BeforeScenarioScope $scope) + { + foreach ($this->getTestModulesFromTags($scope) as $module) { + $this->getDriver()->moduleUninstall($module); + } + } +}