function UserLoginHttpTest::doTestPasswordReset
Same name in other branches
- 9 core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::doTestPasswordReset()
- 8.9.x core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::doTestPasswordReset()
- 10 core/modules/user/tests/src/Functional/UserLoginHttpTest.php \Drupal\Tests\user\Functional\UserLoginHttpTest::doTestPasswordReset()
Do password reset testing for given format and account.
Parameters
string $format: Serialization format.
\Drupal\user\UserInterface $account: Test account.
1 call to UserLoginHttpTest::doTestPasswordReset()
- UserLoginHttpTest::testPasswordReset in core/
modules/ user/ tests/ src/ Functional/ UserLoginHttpTest.php - Tests user password reset.
File
-
core/
modules/ user/ tests/ src/ Functional/ UserLoginHttpTest.php, line 533
Class
- UserLoginHttpTest
- Tests login and password reset via direct HTTP.
Namespace
Drupal\Tests\user\FunctionalCode
protected function doTestPasswordReset($format, $account) {
$response = $this->passwordRequest([], $format);
$this->assertHttpResponseWithMessage($response, 400, 'Missing credentials.name or credentials.mail', $format);
$response = $this->passwordRequest([
'name' => 'drama llama',
], $format);
$this->assertEquals(200, $response->getStatusCode());
$response = $this->passwordRequest([
'mail' => 'llama@drupal.org',
], $format);
$this->assertEquals(200, $response->getStatusCode());
$account->block()
->save();
$response = $this->passwordRequest([
'name' => $account->getAccountName(),
], $format);
$this->assertEquals(200, $response->getStatusCode());
// Check that the proper warning has been logged.
$arguments = [
'%identifier' => $account->getAccountName(),
];
$logged = Database::getConnection()->select('watchdog')
->fields('watchdog', [
'variables',
])
->condition('type', 'user')
->condition('message', 'Unable to send password reset email for blocked or not yet activated user %identifier.')
->orderBy('wid', 'DESC')
->range(0, 1)
->execute()
->fetchField();
$this->assertEquals(serialize($arguments), $logged);
$response = $this->passwordRequest([
'mail' => $account->getEmail(),
], $format);
$this->assertEquals(200, $response->getStatusCode());
// Check that the proper warning has been logged.
$arguments = [
'%identifier' => $account->getEmail(),
];
$logged = Database::getConnection()->select('watchdog')
->fields('watchdog', [
'variables',
])
->condition('type', 'user')
->condition('message', 'Unable to send password reset email for blocked or not yet activated user %identifier.')
->orderBy('wid', 'DESC')
->range(0, 1)
->execute()
->fetchField();
$this->assertEquals(serialize($arguments), $logged);
$account->activate()
->save();
$response = $this->passwordRequest([
'name' => $account->getAccountName(),
], $format);
$this->assertEquals(200, $response->getStatusCode());
$this->loginFromResetEmail();
$this->drupalLogout();
$response = $this->passwordRequest([
'mail' => $account->getEmail(),
], $format);
$this->assertEquals(200, $response->getStatusCode());
$this->loginFromResetEmail();
$this->drupalLogout();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.