Repository navigation
[#1090] Treated the 'anonymous' role as a logout in 'I am logged in as a user with the role(s) :roles'. - #1094
Merged
Conversation
…s a user with the role(s) :roles'.
…role is assigned.
…step, not only denied access.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1094 +/- ##
==========================================
+ Coverage 99.22% 99.23% +0.01%
==========================================
Files 180 180
Lines 9570 9583 +13
==========================================
+ Hits 9496 9510 +14
+ Misses 74 73 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1090
Summary
Given I am logged in as a user with the role "anonymous"now logs the current user out, the same wayGiven I am an anonymous userdoes.anonymous userand any capitalization of either work too, so a Scenario Outline can listanonymousin its Examples table beside the real roles.On 4.0.0-rc2 that row failed at the login step with Drupal's
Anonymous or authenticated role ID must not be assigned manually.(InvalidArgumentException), becauseUserTrait::userLoginWithRoles()created an account and tried to assignanonymousto it.Given I am an anonymous usertakes no argument, so an Examples row couldn't pick it, and every access-matrix outline had to be split up or the step overridden inFeatureContext.When
anonymoussits beside other roles ("anonymous, editor"), or shows up in the... and I have the following fields:step or arolescolumn ofGiven the following users exist:, the step fails withThe role "anonymous" cannot be assigned to a user.(\RuntimeException). It fails before any account is saved or any role is assigned, on both the Drupal and Drush backends. The step text and every other role stay as they were.Before / After
Changes
Step and helpers (
src/Steps/Drupal/UserTrait.php)userLoginWithRoles()callsauthLogout(TRUE)and returns whenuserIsAnonymousRole()holds; otherwise it creates and logs in a user as before.userIsAnonymousRole()(new, public) is TRUE when the list holds exactly 1 role,anonymousoranonymous user, in any case.userParseRoles()(new, public) turns a role list into the roles an account can be assigned: it dropsauthenticatedand empty entries, and throws onanonymous.userAssignRoles()assigns the parsed roles, so a list naminganonymousassigns none of them.userCreate()anduserCreateAndLogin()parse the list before saving the account.Tests
tests/phpunit/src/Unit/Steps/Drupal/UserTraitTest.php(new) coversuserIsAnonymousRole(),userParseRoles()anduserAssignRoles(), includinganonymousbefore and after another role.tests/behat/features/drupal_user.featureadds the access-matrix outline from the issue (administrator,authenticated,anonymous,anonymous user,Anonymous). It also adds an outline that logs in asadministrator, switches to each anonymous spelling and asserts thatuser/loginstays on/user/login. A logged-in user gets redirected to their profile there, so this tells a real logout apart from a non-admin account. 2@test-traitscenarios cover the mixed list and arolescolumn ofanonymous user.Docs
MIGRATION.mddescribes theanonymousrole as logging out again in the 3.14 step table and theOverrideTraitmethod table.STEPS.md,HELPERS.mdanddocs/content/drupal-steps/user.mdare regenerated withahoy update-docs.Summary
UserTraitnow treatsanonymousandanonymous useras a request to log out when either is the only role specified, regardless of capitalization.Step-definition review
No step-definition rule violations were identified in the inspected definitions. The change adds helper methods and tests; it does not add a step definition.