public function PersistentLoginTest::testPersistentLogin in Persistent Login 8
Tests whether a user can be persistently logged in.
@dataProvider loginProvider
Parameters
bool $remember_me: Whether or not the "Remember me" option should be checked when logging in.
string $message: Error message for test failure.
File
- Tests/
src/ Functional/ PersistentLoginTest.php, line 55
Class
- PersistentLoginTest
- Tests the persistent login functionality.
Namespace
Drupal\Tests\persistent_login\FunctionalCode
public function testPersistentLogin($remember_me, $message) {
// Since we are not logged in yet, the homepage should show a "Log in" link.
// The reason we are testing the visibility of the "Log in" link rather than
// inspecting the session cookies, is because this way we can also validate
// that the page cache is correctly cleared in addition to checking if the
// user is logged in or not.
$this
->assertTrue($this
->homepageHasLoginForm(), 'The login form should be present on the page.');
// Log in through the UI.
$this
->drupalGet('user');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm([
'name' => $this->user
->getAccountName(),
'pass' => $this->user->passRaw,
'persistent_login' => $remember_me,
], t('Log in'));
// Check that the homepage now doesn't show the "Log in" link any more.
$this
->assertFalse($this
->homepageHasLoginForm(), 'The login form should not be present on the page.');
// Simulate the user closing the browser window and reopening it, by
// clearing the session cookies.
$this
->restartSession();
// The "Log in" link should now only be shown on the homepage when the
// "Remember me" option was enabled.
$this
->assertEquals($remember_me, !$this
->homepageHasLoginForm(), $message);
}