protected function UserTest::createUserSession in Drupal 9
Same name and namespace in other branches
- 8 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 17
Class
- UserTest
- @coversDefaultClass \Drupal\user\Entity\User @group user
Namespace
Drupal\Tests\user\Unit\Plugin\Core\EntityCode
protected function createUserSession(array $rids = [], $authenticated = FALSE) {
$user = $this
->getMockBuilder('Drupal\\user\\Entity\\User')
->disableOriginalConstructor()
->setMethods([
'get',
'id',
])
->getMock();
$user
->expects($this
->any())
->method('id')
->will($this
->returnValue($authenticated ? 2 : 0));
$roles = [];
foreach ($rids as $rid) {
$roles[] = (object) [
'target_id' => $rid,
];
}
$user
->expects($this
->any())
->method('get')
->with('roles')
->will($this
->returnValue($roles));
return $user;
}