Problem/Motivation

In #2096717: Add parameter to User::getRoles() to exclude built in rids, (authenticated, anonymous), a regression was introduced for anonymous user sessions for getRoles. This happened because the constants for RID weren't used. It wasn't caught because test coveraged didn't cover anonymous roles.

Proposed resolution

Switch to use constants.
Add test coverage

Remaining tasks

none

User interface changes

n/a

API changes

n/a

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

heddn’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.84 KB
heddn’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 1: 2277547-user_getRoles.patch, failed testing.

heddn’s picture

Added constants for RIDs to the unit tests.

heddn’s picture

Status: Needs work » Needs review

Added constants for RIDs to the unit tests.

Status: Needs review » Needs work

The last submitted patch, 4: 2277547-user_getRoles-4.patch, failed testing.

heddn’s picture

Another attempt to make the testbot happy.

heddn’s picture

Re-worked the tests and added a tests only patch.

heddn’s picture

Status: Needs work » Needs review

The last submitted patch, 8: 2277547-user_getRoles-8-TESTS_ONLY.patch, failed testing.

heddn’s picture

Including UserSession in this patch.

The last submitted patch, 11: 2277547-user_getRoles-11-TEST_ONLY.patch, failed testing.

jcfiala’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. The use of the constants instead of the string "anonymous" and "authenticated" helps both fix the unfortunate misspelling of anonymous in the code and helps to future-proof the code in case the roles are renamed for Drupal 9. The tests look good and cover the case that bootstrap isn't called, necessitating the re-declaration of the role constants.

And I've tried applying the patch to the latest HEAD, and it applies cleanly.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 35bc4a2 and pushed to 8.x. Thanks!

  • Commit 35bc4a2 on 8.x by alexpott:
    Issue #2277547 by heddn: Fixed User::getRoles test coverage...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.