function DevelSwitchUserTest::testSwitchUserFunctionality

Same name in other branches
  1. 5.x tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::testSwitchUserFunctionality()

Tests switch user basic functionality.

File

tests/src/Functional/DevelSwitchUserTest.php, line 58

Class

DevelSwitchUserTest
Tests switch user.

Namespace

Drupal\Tests\devel\Functional

Code

public function testSwitchUserFunctionality() {
    $this->drupalLogin($this->webUser);
    $this->drupalGet('');
    $this->assertSession()
        ->pageTextNotContains($this->block
        ->label());
    // Ensure that a token is required to switch user.
    $this->drupalGet('/devel/switch/' . $this->webUser
        ->getDisplayName());
    $this->assertSession()
        ->statusCodeEquals(403);
    $this->drupalLogin($this->develUser);
    $this->drupalGet('');
    $this->assertSession()
        ->pageTextContains($this->block
        ->label(), 'Block title was found.');
    // Ensure that if name in not passed the controller returns access denied.
    $this->drupalGet('/devel/switch');
    $this->assertSession()
        ->statusCodeEquals(403);
    // Ensure that a token is required to switch user.
    $this->drupalGet('/devel/switch/' . $this->switchUser
        ->getDisplayName());
    $this->assertSession()
        ->statusCodeEquals(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, 'Switch');
    $this->assertSessionByUid($this->switchUser
        ->id());
    $this->assertNoSessionByUid($this->develUser
        ->id());
}