diff --git a/tests/Behat/AuthenticationContext.php b/tests/Behat/AuthenticationContext.php index 4990e16..e485415 100644 --- a/tests/Behat/AuthenticationContext.php +++ b/tests/Behat/AuthenticationContext.php @@ -35,4 +35,29 @@ public function setConfigProxyInitialize(): void { $this->setConfig('cas.settings', 'proxy.initialize', TRUE); } + /** + * Blocks a user given its username. + * + * @var string $username + * The name of the user to be blocked. + * + * @When the user :username is blocked + * + * @throws \Exception + * Thrown when the user with the given name does not exist. + */ + public function blockUser(string $username): void { + $users = \Drupal::entityTypeManager() + ->getStorage('user') + ->loadByProperties([ + 'name' => $username, + ]); + /** @var \Drupal\user\Entity\User $user */ + $user = $users ? reset($users) : FALSE; + if ($user) { + $user->block(); + $user->save(); + } + } + } diff --git a/tests/features/ecas-login.feature b/tests/features/ecas-login.feature index 745c38c..69ba5e7 100644 --- a/tests/features/ecas-login.feature +++ b/tests/features/ecas-login.feature @@ -34,3 +34,16 @@ Feature: Login through OE Authentication And I should not see the link "My account" And I should not see the link "Log out" 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 + 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 press the "Login!" button + Then I should see "There was a problem logging in, please contact a site administrator." diff --git a/tests/features/ecas-register.feature b/tests/features/ecas-register.feature index d124947..4b0d1f5 100644 --- a/tests/features/ecas-register.feature +++ b/tests/features/ecas-register.feature @@ -9,4 +9,4 @@ Feature: Register through OE Authentication And I visit "/user/register" # Redirected to the Ecas mockup server. - Then I should see "Service Create an account" + Then I should see "Create an account"