diff --git a/behat.yml.dist b/behat.yml.dist index 171ffae..8be9f0b 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -5,6 +5,7 @@ default: - %paths.base%/tests/features contexts: - Drupal\DrupalExtension\Context\MinkContext + - Drupal\DrupalExtension\Context\ConfigContext - Drupal\DrupalExtension\Context\DrupalContext - Drupal\DrupalExtension\Context\MessageContext - Drupal\Tests\oe_authentication\Behat\AuthenticationContext diff --git a/tests/Behat/AuthenticationContext.php b/tests/Behat/AuthenticationContext.php index 5326953..bd6282b 100644 --- a/tests/Behat/AuthenticationContext.php +++ b/tests/Behat/AuthenticationContext.php @@ -4,18 +4,35 @@ namespace Drupal\Tests\oe_authentication\Behat; -use Drupal\DrupalExtension\Context\ConfigContext; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use Drupal\DrupalExtension\Context\RawDrupalContext; + /** * Defines step definitions specifically for testing the CAS options. - * - * We are extending ConfigContext to override the setConfig() method until - * issue https://github.com/jhedstrom/drupalextension/issues/498 is fixed. - * - * @todo Extend DrupalRawContext and gather the config context when the above - * issue is fixed. */ -class AuthenticationContext extends ConfigContext { +class AuthenticationContext extends RawDrupalContext { + + + /** + * The config context. + * + * @var \Drupal\DrupalExtension\Context\ConfigContext + */ + protected $configContext; + + /** + * Gathers some other contexts. + * + * @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope + * The before scenario scope. + * + * @BeforeScenario + */ + public function gatherContexts(BeforeScenarioScope $scope) { + $environment = $scope->getEnvironment(); + $this->configContext = $environment->getContext('Drupal\DrupalExtension\Context\ConfigContext'); + } /** * Configures the CAS module to use Drupal login. @@ -23,7 +40,17 @@ class AuthenticationContext extends ConfigContext { * @BeforeScenario @DrupalLogin */ public function setConfigDrupalLogin(): void { - $this->setConfig('cas.settings', 'forced_login.enabled', FALSE); + $this->configContext->setConfig('cas.settings', 'forced_login.enabled', FALSE); + } + + /** + * Configures the CAS module to use Cas login. + * For some reason this is being cached. + * + * @AfterScenario @DrupalLogin + */ + public function setConfigCasLogin(): void { + $this->configContext->setConfig('cas.settings', 'forced_login.enabled', TRUE); } /** @@ -32,7 +59,7 @@ public function setConfigDrupalLogin(): void { * @Given the site is configured to initialize this client as a proxy */ public function setConfigProxyInitialize(): void { - $this->setConfig('cas.settings', 'proxy.initialize', TRUE); + $this->configContext->setConfig('cas.settings', 'proxy.initialize', TRUE); } /** @@ -69,8 +96,8 @@ public function backupCasConfigs(): void { $name = 'oe_authentication.settings'; $configs = $this->getDriver()->getCore()->configGet($name); - foreach ($configs as $key => $backup) { - $this->config[$name][$key] = $backup; + foreach ($configs as $key => $value) { + $this->configContext->setConfig($name, $key, $value); } } diff --git a/tests/features/ecas-login.feature b/tests/features/ecas-login.feature index 69ba5e7..1468ccc 100644 --- a/tests/features/ecas-login.feature +++ b/tests/features/ecas-login.feature @@ -1,4 +1,4 @@ -@javascript +@api @javascript Feature: Login through OE Authentication In order to be able to access the CMS backend As user of the system @@ -36,14 +36,17 @@ Feature: Login through OE Authentication And I should see the link "Log in" Scenario: A blocked user should not be able to log in - Given the user "chucknorris" is blocked + Given users: + | name | + | lsalander | + And the user "lsalander" is blocked When I am on the homepage Then I should see the link "Log in" And I should not see the link "Log out" # When I try to log in again I will be denied access. When I click "Log in" - And I fill in "Username or e-mail address" with "texasranger@chuck_norris.com.eu" - And I fill in "Password" with "Qwerty098" + And I fill in "Username or e-mail address" with "Lisbeth.SALANDER@ext.ec.europa.eu" + And I fill in "Password" with "dragon_tattoo" And I press the "Login!" button Then I should see "There was a problem logging in, please contact a site administrator."