You are here

protected function MasqueradeWebTestBase::masqueradeAs in Masquerade 8.2

Masquerades as another user.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user account to masquerade as.

Throws

\Behat\Mink\Exception\ExpectationException

\Behat\Mink\Exception\ResponseTextException

2 calls to MasqueradeWebTestBase::masqueradeAs()
MasqueradeCacheTest::testMasqueradeToolbarLinkCaching in tests/src/Functional/MasqueradeCacheTest.php
Tests caching for the Unmasquerade link in the admin toolbar.
MasqueradeTest::testMasquerade in tests/src/Functional/MasqueradeTest.php
Tests masquerade user links.

File

tests/src/Functional/MasqueradeWebTestBase.php, line 180

Class

MasqueradeWebTestBase
Base test class for Masquerade module web tests.

Namespace

Drupal\Tests\masquerade\Functional

Code

protected function masqueradeAs(AccountInterface $account) {
  $this
    ->drupalGet('user/' . $account
    ->id());
  $this
    ->clickLink($this
    ->t('Masquerade as @name', [
    '@name' => $account
      ->getDisplayName(),
  ]));

  //$this->drupalGet('user/' . $account->id() . '/masquerade', [

  //  'query' => [
  //    'token' => $this->drupalGetToken('user/' . $account->id() . '/masquerade'),
  //  ],

  //]);

  //$this->assertSession()->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('You are now masquerading as ' . $account
    ->label());

  // Update the logged in user account.
  // @see \Drupal\Tests\BrowserTestBase::drupalLogin()
  if (isset($this->session_id)) {

    //$this->loggedInUser = $account;

    //$this->loggedInUser->session_id = $this->session_id;
  }
}