You are here

public function UserTest::testUserGetRoles in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 50
Contains \Drupal\Tests\user\Unit\Plugin\Core\Entity\UserTest.

Class

UserTest
@coversDefaultClass \Drupal\user\Entity\User @group user

Namespace

Drupal\Tests\user\Unit\Plugin\Core\Entity

Code

public function testUserGetRoles() {

  // Anonymous user.
  $user = $this
    ->createUserSession(array());
  $this
    ->assertEquals(array(
    RoleInterface::ANONYMOUS_ID,
  ), $user
    ->getRoles());
  $this
    ->assertEquals(array(), $user
    ->getRoles(TRUE));

  // Authenticated user.
  $user = $this
    ->createUserSession(array(), TRUE);
  $this
    ->assertEquals(array(
    RoleInterface::AUTHENTICATED_ID,
  ), $user
    ->getRoles());
  $this
    ->assertEquals(array(), $user
    ->getRoles(TRUE));
}