function UserSessionTest::testUserGetRoles

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::testUserGetRoles()
  2. 8.9.x core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::testUserGetRoles()
  3. 10 core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::testUserGetRoles()

Tests the method getRoles exclude or include locked roles based in param.

@covers ::getRoles @todo Move roles constants to a class/interface

1 method overrides UserSessionTest::testUserGetRoles()
UserTest::testUserGetRoles in core/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php
Tests the method getRoles exclude or include locked roles based in param.

File

core/tests/Drupal/Tests/Core/Session/UserSessionTest.php, line 60

Class

UserSessionTest
@coversDefaultClass \Drupal\Core\Session\UserSession @group Session

Namespace

Drupal\Tests\Core\Session

Code

public function testUserGetRoles() : void {
    $user = $this->createUserSession([
        'role_two',
    ], TRUE);
    $this->assertEquals([
        RoleInterface::AUTHENTICATED_ID,
        'role_two',
    ], $user->getRoles());
    $this->assertEquals([
        'role_two',
    ], $user->getRoles(TRUE));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.