function DevelSwitchUserTest::testSwitchUser
Tests switch user.
File
-
tests/
src/ Functional/ DevelSwitchUserTest.php, line 66
Class
- DevelSwitchUserTest
- Tests switch user.
Namespace
Drupal\Tests\devel\FunctionalCode
public function testSwitchUser() {
$this->drupalLogin($this->webUser);
$this->drupalGet('');
$this->assertNoText($this->block
->label(), 'Block title was not found.');
// Ensure that a token is required to switch user.
$this->drupalGet('/devel/switch/' . $this->webUser
->getDisplayName());
$this->assertResponse(403);
$this->drupalLogin($this->develUser);
$this->drupalGet('');
$this->assertText($this->block
->label(), 'Block title was found.');
// Ensure that if name in not passed the controller returns access denied.
$this->drupalGet('/devel/switch');
$this->assertResponse(403);
// Ensure that a token is required to switch user.
$this->drupalGet('/devel/switch/' . $this->switchUser
->getDisplayName());
$this->assertResponse(403);
// Switch to another user account.
$this->drupalGet('/user/' . $this->switchUser
->id());
$this->clickLink($this->switchUser
->getDisplayName());
$this->assertSessionByUid($this->switchUser
->id());
$this->assertNoSessionByUid($this->develUser
->id());
// Switch back to initial account.
$this->clickLink($this->develUser
->getDisplayName());
$this->assertNoSessionByUid($this->switchUser
->id());
$this->assertSessionByUid($this->develUser
->id());
// Use the search form to switch to another account.
$edit = [
'userid' => $this->switchUser
->getDisplayName(),
];
$this->drupalPostForm(NULL, $edit, t('Switch'));
$this->assertSessionByUid($this->switchUser
->id());
$this->assertNoSessionByUid($this->develUser
->id());
}