public function DevelSwitchUserTest::testSwitchUserFunctionality in Devel 8.2
Same name and namespace in other branches
- 8.3 tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::testSwitchUserFunctionality()
- 4.x tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::testSwitchUserFunctionality()
Tests switch user basic functionality.
File
- tests/
src/ Functional/ DevelSwitchUserTest.php, line 66
Class
- DevelSwitchUserTest
- Tests switch user.
Namespace
Drupal\Tests\devel\FunctionalCode
public function testSwitchUserFunctionality() {
$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());
}