protected function BrowserTestBase::drupalLogin in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/simpletest/src/BrowserTestBase.php \Drupal\simpletest\BrowserTestBase::drupalLogin()
Logs in a user using the Mink controlled browser.
If a user is already logged in, then the current user is logged out before logging in the specified user.
Please note that neither the current user nor the passed-in user object is populated with data of the logged in user. If you need full access to the user object after logging in, it must be updated manually. If you also need access to the plain-text password of the user (set by drupalCreateUser()), e.g. to log in the same user again, then it must be re-assigned manually. For example:
// Create a user.
$account = $this
->drupalCreateUser(array());
$this
->drupalLogin($account);
// Load real user object.
$pass_raw = $account->passRaw;
$account = User::load($account
->id());
$account->passRaw = $pass_raw;
Parameters
\Drupal\Core\Session\AccountInterface $account: User object representing the user to log in.
See also
drupalCreateUser()
1 call to BrowserTestBase::drupalLogin()
- BrowserTestBaseTest::testGoTo in core/
modules/ simpletest/ tests/ src/ Functional/ BrowserTestBaseTest.php - Tests basic page test.
File
- core/
modules/ simpletest/ src/ BrowserTestBase.php, line 687 - Contains \Drupal\simpletest\BrowserTestBase.
Class
- BrowserTestBase
- Provides a test case for functional Drupal tests.
Namespace
Drupal\simpletestCode
protected function drupalLogin(AccountInterface $account) {
if ($this->loggedInUser) {
$this
->drupalLogout();
}
$this
->drupalGet('user');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm(array(
'name' => $account
->getUsername(),
'pass' => $account->passRaw,
), t('Log in'));
// @see BrowserTestBase::drupalUserIsLoggedIn()
$account->sessionId = $this
->getSession()
->getCookie($this
->getSessionName());
$this
->assertTrue($this
->drupalUserIsLoggedIn($account), SafeMarkup::format('User %name successfully logged in.', array(
'name' => $account
->getUsername(),
)));
$this->loggedInUser = $account;
$this->container
->get('current_user')
->setAccount($account);
}