public function DevelSwitchUserTest::testSwitchUserListItems in Devel 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::testSwitchUserListItems()
- 8.2 tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::testSwitchUserListItems()
- 4.x tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::testSwitchUserListItems()
Test the user list items.
File
- tests/
src/ Functional/ DevelSwitchUserTest.php, line 154
Class
- DevelSwitchUserTest
- Tests switch user.
Namespace
Drupal\Tests\devel\FunctionalCode
public function testSwitchUserListItems() {
$anonymous = \Drupal::config('user.settings')
->get('anonymous');
$this
->setBlockConfiguration('list_size', 2);
// Login as web user so we are sure that this account is prioritized
// in the list if not enougth user with 'switch users' permission are
// present.
$this
->drupalLogin($this->webUser);
$this
->drupalLogin($this->develUser);
$this
->drupalGet('');
// Ensure that user with 'switch users' permission are prioritized.
$this
->assertSwitchUserListCount(2);
$this
->assertSwitchUserListContainsUser($this->develUser
->getDisplayName());
$this
->assertSwitchUserListContainsUser($this->switchUser
->getDisplayName());
// Ensure that blocked users are not shown in the list.
$this->switchUser
->set('status', 0)
->save();
$this
->drupalGet('');
$this
->assertSwitchUserListCount(2);
$this
->assertSwitchUserListContainsUser($this->develUser
->getDisplayName());
$this
->assertSwitchUserListContainsUser($this->webUser
->getDisplayName());
$this
->assertSwitchUserListNoContainsUser($this->switchUser
->getDisplayName());
// Ensure that anonymous user are prioritized if include_anon is set to true.
$this
->setBlockConfiguration('include_anon', TRUE);
$this
->drupalGet('');
$this
->assertSwitchUserListCount(2);
$this
->assertSwitchUserListContainsUser($this->develUser
->getDisplayName());
$this
->assertSwitchUserListContainsUser($anonymous);
// Ensure that the switch user block works properly even if no prioritized
// users are found (special handling for user 1).
$this
->drupalLogout();
$this->develUser
->delete();
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('');
$this
->assertSwitchUserListCount(2);
$this
->assertSwitchUserListContainsUser($this->rootUser
->getDisplayName());
$this
->assertSwitchUserListContainsUser($anonymous);
// Ensure that the switch user block works properly even if no roles have
// the 'switch users' permission associated (special handling for user 1).
$roles = user_roles(TRUE, 'switch users');
\Drupal::entityTypeManager()
->getStorage('user_role')
->delete($roles);
$this
->drupalGet('');
$this
->assertSwitchUserListCount(2);
$this
->assertSwitchUserListContainsUser($this->rootUser
->getDisplayName());
$this
->assertSwitchUserListContainsUser($anonymous);
}