You are here

protected function UserTest::createUserSession 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::createUserSession()

Setups a user session for the test.

Parameters

array $rids: The rids of the user.

bool $authenticated: TRUE if it is an authenticated user.

Return value

\Drupal\Core\Session\AccountInterface The created user session.

Overrides UserSessionTest::createUserSession

1 call to UserTest::createUserSession()
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/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php, line 22
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

protected function createUserSession(array $rids = array(), $authenticated = FALSE) {
  $user = $this
    ->getMockBuilder('Drupal\\user\\Entity\\User')
    ->disableOriginalConstructor()
    ->setMethods(array(
    'get',
    'id',
  ))
    ->getMock();
  $user
    ->expects($this
    ->any())
    ->method('id')
    ->will($this
    ->returnValue($authenticated ? 2 : 0));
  $roles = array();
  foreach ($rids as $rid) {
    $roles[] = (object) array(
      'target_id' => $rid,
    );
  }
  $user
    ->expects($this
    ->any())
    ->method('get')
    ->with('roles')
    ->will($this
    ->returnValue($roles));
  return $user;
}