Users
DrevOps\BehatSteps\Steps\Drupal\UserTrait - Source, Example, Helpers
Manage Drupal users with role and permission assignments.
- Create user accounts
- Create user roles
- Visit user profile pages for editing and deletion.
- Assert user roles.
- Assert user account status (active/inactive).
Prerequisites
| Prerequisite | Capability |
|---|---|
| A backend in the scenario's list provides "UserCapabilityInterface" | UserCapabilityInterface |
Steps
@Given the following users do not exist:
Remove users specified in a table
Given the following users do not exist:
| name |
| John |
| Jane |
Given the following users do not exist:
| mail |
| john@example.com |
| jane@example.com |
@Given the following users with fields exist:
Create users with vertical field format
Given the following users with fields exist:
| name | [TEST] user1 | [TEST] user2 |
| mail | user1@example.com | user2@example.com |
| roles | editor | author |
@Given the following users exist:
Create users from a table of field values
Given the following users exist:
| name | mail | roles |
| [TEST] user1 | user1@example.com | editor |
@Given I am an anonymous user
Log the current user out so the session is anonymous
Given I am an anonymous user
@Given the password for the user :name is :password
Set a password for a user
Given the password for the user "John" is "password"
@Given the last access time for the user :name is :datetime
Set last access time for a user
Given the last access time for the user "John" is "Friday, 22 November 2024 13:46:14"
Given the last access time for the user "John" is "1732319174"
@Given the last login time for the user :name is :datetime
Set last login time for a user
Given the last login time for the user "John" is "Friday, 22 November 2024 13:46:14"
Given the last login time for the user "John" is "1732319174"
@Given the role :role has the permission(s) :permissions
Create a single role with specified permissions
Given the role "Content Manager" has the permissions "access content, create article content, edit any article content"
@Given the following roles exist:
Create multiple roles from the specified table
Given the following roles exist:
| name | permissions |
| Content Editor | access content, create article content |
| Content Approver | access content, edit any article content |
@Given I am logged in as a user with the role(s) :roles
Create a user with the roles and log in as them
Given I am logged in as a user with the role "editor"
Given I am logged in as a user with the roles "editor, admin"
@Given I am logged in as a user with the role(s) :roles and I have the following fields:
Create a user with the roles and fields, and log in as them
Given I am logged in as a user with the role "editor" and I have the following fields:
| field_user_name | John |
| field_user_surname | Smith |
@Given I am logged in as a user with the permission(s) :permissions
Create a role carrying the permissions, then log in as a user with it
Given I am logged in as a user with the permission "administer nodes"
Given I am logged in as a user with the permissions "administer nodes, access content"
@Given I am logged in as the user :name
Log in as an existing user created earlier in the scenario
Given I am logged in as the user "[TEST] user1"
@When I log out
Log the current user out
When I log out
@When I visit the profile page of the user :name
Visit the profile page of the specified user
When I visit the profile page of the user "John"
@When I visit my own profile page
Visit the profile page of the current user
When I visit my own profile page
@When I visit the profile edit page of the user :name
Visit the profile edit page of the specified user
When I visit the profile edit page of the user "John"
@When I visit my own profile edit page
Visit the profile edit page of the current user
When I visit my own profile edit page
@When I visit the profile delete page of the user :name
Visit the profile delete page of the specified user
When I visit the profile delete page of the user "John"
@When I visit my own profile delete page
Visit the profile delete page of the current user
When I visit my own profile delete page
@When I visit the password reset link for the user :name
Visit the password reset link for a user
When I visit the password reset link for the user "admin"
When I visit the password reset link for the user "test_user"
@When I visit my own password reset link
Visit the password reset link for the currently logged-in user
When I visit my own password reset link
@Then the user :name should have the role(s) :roles assigned
Assert that a user has roles assigned
Then the user "John" should have the roles "administrator, editor" assigned
@Then the user :name should not have the role(s) :roles assigned
Assert that a user does not have roles assigned
Then the user "John" should not have the roles "administrator, editor" assigned
@Then the user with the email :address should exist
Assert that a user with an email address exists
Then the user with the email "alice@example.com" should exist
@Then the user with the email :address should not exist
Assert that a user with an email address does not exist
Then the user with the email "alice@example.com" should not exist
@Then the user :name should be blocked
Assert that a user is blocked
Then the user "John" should be blocked
@Then the user :name should not be blocked
Assert that a user is not blocked
Then the user "John" should not be blocked