public function ForcePasswordChangeServiceTest::testGetUsersForRole in Force Password Change 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/Service/ForcePasswordChangeServiceTest.php \Drupal\Tests\force_password_change\Unit\Service\ForcePasswordChangeServiceTest::testGetUsersForRole()
* @covers ::getUsersForRole
File
- tests/
src/ Unit/ Service/ ForcePasswordChangeServiceTest.php, line 348
Class
- ForcePasswordChangeServiceTest
- @coversDefaultClass \Drupal\force_password_change\Service\ForcePasswordChangeService @group force_password_change
Namespace
Drupal\Tests\force_password_change\Unit\ServiceCode
public function testGetUsersForRole() {
$role = 'authenticated';
$this->mapper
->expects($this
->at(0))
->method('getUserIdsForRole')
->with($role)
->willReturn([
1,
2,
]);
$value = $this->forcePasswordChangeService
->getUsersForRole($role, TRUE);
$this
->assertCount(2, $value, 'The correct number of User IDs was returned for the authenticated role');
$role = 'admin';
$this->mapper
->expects($this
->at(0))
->method('getUserIdsForRole')
->with($role)
->willReturn([
1,
2,
3,
]);
$value = $this->forcePasswordChangeService
->getUsersForRole($role, TRUE);
$this
->assertCount(3, $value, 'The correct number of User IDs was returned for the admin role');
$role = 'authenticated';
$this->mapper
->expects($this
->at(0))
->method('getUserIdsForRole')
->with($role)
->willReturn([
1,
2,
]);
$value = $this->forcePasswordChangeService
->getUsersForRole($role, FALSE);
$this
->assertCount(2, $value, 'The correct number of Users was returned for the authenticated role');
$this
->assertEquals('user1', $value[1], 'The correct username was returned for user 1');
$this
->assertEquals('user2', $value[2], 'The correct username was returned for user 2');
$role = 'admin';
$this->mapper
->expects($this
->at(0))
->method('getUserIdsForRole')
->with($role)
->willReturn([
3,
4,
]);
$value = $this->forcePasswordChangeService
->getUsersForRole($role, FALSE);
$this
->assertCount(2, $value, 'The correct number of Users was returned for the admin role');
$this
->assertEquals('user3', $value[3], 'The correct username was returned for user 3');
$this
->assertEquals('user4', $value[4], 'The correct username was returned for user 4');
}