function UserTest::testUserGetRoles
Same name in other branches
- 9 core/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php \Drupal\Tests\user\Unit\Plugin\Core\Entity\UserTest::testUserGetRoles()
- 10 core/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php \Drupal\Tests\user\Unit\Plugin\Core\Entity\UserTest::testUserGetRoles()
- 11.x core/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php \Drupal\Tests\user\Unit\Plugin\Core\Entity\UserTest::testUserGetRoles()
Tests the method getRoles exclude or include locked roles based in param.
@covers ::getRoles
Overrides UserSessionTest::testUserGetRoles
See also
\Drupal\user\Entity\User::getRoles()
File
-
core/
modules/ user/ tests/ src/ Unit/ Plugin/ Core/ Entity/ UserTest.php, line 45
Class
- UserTest
- @coversDefaultClass \Drupal\user\Entity\User @group user
Namespace
Drupal\Tests\user\Unit\Plugin\Core\EntityCode
public function testUserGetRoles() {
// Anonymous user.
$user = $this->createUserSession([]);
$this->assertEquals([
RoleInterface::ANONYMOUS_ID,
], $user->getRoles());
$this->assertEquals([], $user->getRoles(TRUE));
// Authenticated user.
$user = $this->createUserSession([], TRUE);
$this->assertEquals([
RoleInterface::AUTHENTICATED_ID,
], $user->getRoles());
$this->assertEquals([], $user->getRoles(TRUE));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.