Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1197 from ec-europa/ISAICP-4519
Browse files Browse the repository at this point in the history
Isaicp 4519
  • Loading branch information
idimopoulos authored May 24, 2018
2 parents 80486b6 + 4853fbb commit f4e3cf8
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 29 deletions.
55 changes: 53 additions & 2 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Contains step definitions for the Joinup project.
*/

declare(strict_types = 1);

use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Gherkin\Node\TableNode;
Expand All @@ -17,6 +19,7 @@
use Drupal\joinup\Traits\ContextualLinksTrait;
use Drupal\joinup\Traits\EntityTrait;
use Drupal\joinup\Traits\TraversingTrait;
use Drupal\joinup\Traits\UserTrait;
use Drupal\joinup\Traits\UtilityTrait;
use LoversOfBehat\TableExtension\Hook\Scope\AfterTableFetchScope;

Expand All @@ -29,6 +32,7 @@ class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext
use ContextualLinksTrait;
use EntityTrait;
use TraversingTrait;
use UserTrait;
use UtilityTrait;

/**
Expand Down Expand Up @@ -508,14 +512,61 @@ public function assertContentPageByTitle($type, $title) {
*
* @Then I should have a :username user
*/
public function assertUserExistence($username) {
$user = user_load_by_name($username);
public function assertUserExistence(string $username): void {
$user = $this->getUserByName($username);

if (empty($user)) {
throw new \Exception("Unable to load expected user " . $username);
}
}

/**
* Checks the status of the given user.
*
* @param string $username
* The name of the user to statusilize.
* @param string $status
* The expected status, can be either 'active' or 'blocked'.
*
* @throws \Exception
* Thrown when the user does not exist or doesn't have the expected status.
*
* @Then the account for :username should be :status
*/
public function assertUserStatus(string $username, string $status): void {
/** @var \Drupal\user\UserInterface $user */
$user = $this->getUserByName($username);
$expected_status = $status === 'active';

if (empty($user)) {
throw new \Exception("Unable to load expected user $username.");
}

if ($user->isActive() !== $expected_status) {
throw new \Exception("The user does not have the $status status.");
}
}

/**
* Deletes the user account with the given name.
*
* This intended to be used for user accounts that are created through the UI
* and are not cleaned up automatically when a test ends.
*
* @param string $username
* The name of the user to delete.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown when an error occurs while the user is being deleted.
*
* @Then I delete the :username user
*/
public function deleteUser(string $username): void {
/** @var \Drupal\user\UserInterface $user */
$user = $this->getUserByName($username);
$user->delete();
}

/**
* Click on an element by css class.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/features/user/block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ Feature: Block users
And I press the "Apply to selected items" button
Then I should see the success message "Unblock the selected user(s) was applied to 1 item."
And the following system email should have been sent:
| recipient | Liam Lego |
| subject | Your account was just unblocked. |
| body | For more information about how to avoid your account being blocked in the future, please visit our |
| recipient | Liam Lego |
| subject | Your Joinup account has been activated. |
| body | Your account at Joinup has been activated. You may now log in by clicking this link or copying and pasting it into your browser |
24 changes: 19 additions & 5 deletions tests/features/user/register.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ Feature: User registration
| Username | TeStUSer |
| First name | Test |
| Family name | User |
Then I should see the success message "A welcome message with further instructions has been sent to your email address."
Then I should see the success message "Thank you for applying for an account. Your account is currently pending approval by the site administrator."
And the following system email should have been sent:
| recipient | TeStUSer |
| subject | You're one step away to create your Joinup account. Please confirm your email address before you can sign in to Joinup. |
| body | You are one step away from creating your account in Joinup, the European Commission collaborative platform for Interoperability solutions for public administrations, businesses and citizens. |
| recipient | TeStUSer |
| subject | Your Joinup account is pending approval. |
| body | Thank you for registering at Joinup. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to sign in, set your password, and other details. |
And the account for TeStUSer should be blocked
Given I am logged in as a moderator
And I am on the homepage
When I click "People"
And I click "Edit" in the "Test User" row
And I select the radio button "Active"
And I press "Save"
Then the following system email should have been sent:
| recipient | TeStUSer |
| subject | Your Joinup account has been activated. |
| body | Your account at Joinup has been activated. You may now log in by clicking this link or copying and pasting it into your browser |
And the account for TeStUSer should be active

Scenario: A moderator can register a user
Given users:
Expand All @@ -42,7 +54,9 @@ Feature: User registration
| Password | SuperSecret |
| Confirm password | SuperSecret |
| Notify user of new account | 1 |
And the following system email should have been sent:
| Active | 1 |
Then the following system email should have been sent:
| recipient | SuperUser |
| subject | Your Joinup account was created successfully. |
| body | Your account on Joinup has been created. If you believe that a Joinup account linked to this email address was erroneously created, please contact The Joinup Support Team |
And the account for SuperUser should be active
18 changes: 16 additions & 2 deletions tests/src/Traits/UserTrait.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php

declare(strict_types = 1);

namespace Drupal\joinup\Traits;

use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\user\UserInterface;

/**
* Helper methods for dealing with users created in Behat tests.
*/
Expand Down Expand Up @@ -110,14 +115,23 @@ protected function createUser(array $values) {
* @throws \RuntimeException
* Thrown when a user with the provided name is not found.
*/
protected function getUserByName($name) {
protected function getUserByName($name): UserInterface {
$user = user_load_by_name($name);

if (!$user) {
throw new \RuntimeException("The user with name '$name' was not found.");
}

/** @var \Drupal\user\Entity\User $user */
// The user object might be cached, make sure to return it straight from the
// data storage.
try {
/** @var \Drupal\user\UserInterface $user */
$user = \Drupal::entityTypeManager()->getStorage('user')->loadUnchanged($user->id());
}
catch (InvalidPluginDefinitionException $e) {
throw new \RuntimeException('The user entity storage is not defined.', 0, $e);
}

return $user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,12 @@ class JoinupNotificationSubContext extends DrupalSubContextBase implements Drupa
throw new \Exception('There were arguments found in the mail or the body that were not replaced.');
}

// Check the existence or absence of the signature.
// In the previous steps all whitespace has been converted to spaces and
// HTML tags were removed, but this might cause double spaces to appear.
// Replace all double spaces with single spaces.
$body = preg_replace("/\s+/", ' ', $body);
$mail_body = preg_replace("/\s+/", ' ', $mail_body);

// Check the existence or absence of the signature.
$signature_present = preg_match('/Kind regards,\s{0,2}The Joinup Support Team/', $mail_body);
if ($signature_required && !$signature_present) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ content:
region: content
settings: { }
third_party_settings: { }
invite_link:
weight: 7
region: content
settings: { }
third_party_settings: { }
links:
weight: 3
region: content
Expand Down Expand Up @@ -144,11 +149,6 @@ content:
joinup:
template_suggestion: no_wrappers
type: link
invite_link:
weight: 7
region: content
settings: { }
third_party_settings: { }
share_link:
weight: 8
region: content
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
langcode: en
status: true
dependencies: { }
id: default
weight: 0
name: Published
description: 'Default graph. This is available for all entity types and bundles.'
entity_types: null
8 changes: 4 additions & 4 deletions web/profiles/joinup/config/install/user.mail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ register_no_approval_required:
body: "Dear [user:field_user_first_name],\r\n\r\nYou are one step away from creating your account in Joinup, the European Commission collaborative platform for Interoperability solutions for public administrations, businesses and citizens.\r\n\r\nPlease confirm your email address by clicking <a href=\"[user:one-time-login-url]\">[user:one-time-login-url]</a> to complete the creation of your new Joinup account.\r\n\r\nIf you think that this email was erroneously sent to you, please disregard this message. \r\n\r\nKind regards,\r\n\r\nThe Joinup Support Team"
subject: 'You''re one step away to create your Joinup account. Please confirm your email address before you can sign in to Joinup.'
register_pending_approval:
body: "[user:display-name],\r\n\r\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to sign in, set your password, and other details.\r\n\r\n\r\n-- [site:name] team"
subject: 'Account details for [user:display-name] at [site:name] (pending admin approval)'
body: "Dear [user:field_user_first_name],\r\n\r\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to sign in, set your password, and other details.\r\n\r\nKind regards,\r\n\r\nThe Joinup Support Team."
subject: 'Your [site:name] account is pending approval.'
register_pending_approval_admin:
body: "[user:display-name] has applied for an account.\r\n\r\n<a href=\"[user:edit-url]\">[user:edit-url]</a>"
subject: 'Account details for [user:display-name] at [site:name] (pending admin approval)'
status_activated:
body: "Dear [user:field_user_first_name],\r\n\r\nYour Joinup account was recently unblocked by our moderators. \r\nFor more information about how to avoid your account being blocked in the future, please visit our FAQ section.\r\n\r\nKind regards,\r\n\r\nThe Joinup Support Team."
subject: 'Your account was just unblocked.'
body: "Dear [user:field_user_first_name],\r\n\r\nYour account at [site:name] has been activated.\r\n\r\nYou may now log in by clicking this link or copying and pasting it into your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis link can only be used once to log in and will lead you to a page where you can set your password.\r\n\r\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\r\n\r\nusername: [user:account-name]\r\npassword: Your password\r\n\r\nKind regards,\r\n\r\nThe Joinup Support Team."
subject: 'Your Joinup account has been activated.'
status_blocked:
body: "Dear [user:field_user_first_name],\r\n\r\nYour Joinup account was recently blocked by our moderators. \r\nFor more information about blocked accounts, please visit our FAQ section.\r\n\r\nKind regards,\r\n\r\nThe Joinup Support Team."
subject: 'Your account was just blocked.'
Expand Down
2 changes: 1 addition & 1 deletion web/profiles/joinup/config/install/user.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ notify:
register_admin_created: true
register_no_approval_required: true
register_pending_approval: true
register: visitors
register: visitors_admin_approval
cancel_method: user_cancel_delete
password_reset_timeout: 86400
password_strength: false
Expand Down
6 changes: 0 additions & 6 deletions web/profiles/joinup/joinup.install
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ function joinup_install() {
->set('features.node_user_picture', FALSE)
->save(TRUE);

// Allow visitor account creation.
\Drupal::configFactory()
->getEditable('user.settings')
->set('register', USER_REGISTER_VISITORS)
->save(TRUE);

// Disable the warning about rebuilding node access. This is needlessly set
// in the install hook of the View Unpublished module.
// @todo Remove this once the bug is fixed.
Expand Down

0 comments on commit f4e3cf8

Please sign in to comment.