public function UserLoginTest::testValidLoginWithDestination in farmOS 2.x
Tests login with destination.
File
- modules/
core/ login/ tests/ src/ Functional/ UserLoginTest.php, line 35
Class
- UserLoginTest
- Test using an email in the UserLoginForm.
Namespace
Drupal\Tests\farm_login\FunctionalCode
public function testValidLoginWithDestination() {
// 1. Test for correct text in the login form.
$this
->drupalGet('user/login');
$this
->assertSession()
->pageTextContains($this
->t('Email or username'));
$this
->assertSession()
->pageTextContains($this
->t('Enter your @s email address or username.', [
'@s' => $this
->config('system.site')
->get('name'),
]));
// 2. Login the user using their username.
$user = $this
->drupalCreateUser([]);
$this
->drupalGet('user/login', [
'query' => [
'destination' => 'foo',
],
]);
$edit = [
'name' => $user
->getAccountName(),
'pass' => $user->passRaw,
];
$this
->submitForm($edit, 'Log in');
$this
->assertSession()
->addressEquals('foo');
$this
->drupalLogout();
// 3. Login the user using their email.
$user = $this
->drupalCreateUser([]);
$this
->drupalGet('user/login', [
'query' => [
'destination' => 'foo',
],
]);
$edit = [
'name' => $user
->getEmail(),
'pass' => $user->passRaw,
];
$this
->submitForm($edit, 'Log in');
$this
->assertSession()
->addressEquals('foo');
$this
->drupalLogout();
// 4. Login with an invalid username/email.
$user = $this
->drupalCreateUser([]);
$this
->drupalGet('user/login', [
'query' => [
'destination' => 'foo',
],
]);
$edit = [
'name' => 'invalid@email.com',
'pass' => $user->passRaw,
];
$this
->submitForm($edit, 'Log in');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldValueEquals('pass', '');
$this
->assertSession()
->pageTextcontains('Unrecognized username or password. Forgot your password?');
}