Skip to content

Commit

Permalink
OPENEUROPA-1501: Extend the proper class for behat context and fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyad committed Jan 10, 2019
1 parent 47e0a4d commit 092430f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
1 change: 1 addition & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 39 additions & 12 deletions tests/Behat/AuthenticationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,53 @@

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.
*
* @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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down
11 changes: 7 additions & 4 deletions tests/features/ecas-login.feature
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."

0 comments on commit 092430f

Please sign in to comment.