Authenticates users through the Drupal one time login mechanism.
Authenticates users through the Drupal one time login mechanism in Behat scenarios.
This is intended for projects that do not use the default Drupal login form but instead rely on 2-Factor Authentication, Single Sign On or other non-standard authentication methods.
Add the library to your development dependencies:
$ composer require --dev drupaltest/behat-one-time-login
Add the following to your
behat.yml configuration file:
default: extensions: FriendsOfBehat\ServiceContainerExtension: imports: - "./vendor/drupaltest/behat-one-time-login/behat.services.yml"
This transparently replaces the standard login method, so in most cases it can be dropped in and used without requiring changes to existing test scenarios.
Do note that in the standard Drupal login procedure the user ends up on the homepage after logging in, and with this library they end up on the user profile page. We do not include a redirection to the homepage since in Behavior Driven Development the tests are supposed to be readable by business stakeholders. Non- technical users might not know that Drupal internally redirects to the homepage after logging in. This means that any tests that are performing actions on the homepage should have a step telling the user to open the homepage. For example:
Given I am logged in as an administrator And I am on the homepage
Running tests locally:
composer installto get the codebase:
$ composer install
- Create a customized
$ cp behat.yml.dist behat.yml
- Adapt the values in
behat.ymlto your needs. You can keep the default Behat config and test using the PHP built-in web-server:
$ ./vendor/bin/drush runserver 8888or use your local web-server if any. In this case, you'll need to set the appropriate configurations in
- Install Drupal:
$ ./vendor/bin/drush site-install
- Run tests:
This is based on weitzman/logintrait by Moshe Weitzman.