Warning: Undefined variable $use_statements in /home/wordpri/www/cci/amar/Projet-v1 2 apache/vendor/symfony/maker-bundle/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php on line 4
class ResetPasswordTest extends WebTestCase
{
private KernelBrowser $client;
private EntityManagerInterface $em;
private
Warning: Undefined variable $user_repo_short_name in /home/wordpri/www/cci/amar/Projet-v1 2 apache/vendor/symfony/maker-bundle/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php on line 10
$userRepository;
protected function setUp(): void
{
$this->client = static::createClient();
// Ensure we have a clean database
$container = static::getContainer();
/** @var EntityManagerInterface $em */
$em = $container->get('doctrine')->getManager();
$this->em = $em;
$this->userRepository = $container->get(
Warning: Undefined variable $user_repo_short_name in /home/wordpri/www/cci/amar/Projet-v1 2 apache/vendor/symfony/maker-bundle/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php on line 23
::class);
foreach ($this->userRepository->findAll() as $user) {
$this->em->remove($user);
}
$this->em->flush();
}
public function testResetPasswordController(): void
{
// Create a test user
$user = (new
Warning: Undefined variable $user_short_name in /home/wordpri/www/cci/amar/Projet-v1 2 apache/vendor/symfony/maker-bundle/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php on line 35
())
->setEmail('me@example.com')
->setPassword('a-test-password-that-will-be-changed-later')
;
$this->em->persist($user);
$this->em->flush();
// Test Request reset password page
$this->client->request('GET', '/reset-password');
self::assertResponseIsSuccessful();
self::assertPageTitleContains('Reset your password');
// Submit the reset password form and test email message is queued / sent
$this->client->submitForm('Send password reset email', [
'reset_password_request_form[email]' => 'me@example.com',
]);
// Ensure the reset password email was sent
// Use either assertQueuedEmailCount() || assertEmailCount() depending on your mailer setup
// self::assertQueuedEmailCount(1);
self::assertEmailCount(1);
self::assertCount(1, $messages = $this->getMailerMessages());
self::assertEmailAddressContains($messages[0], 'from', '
Warning: Undefined variable $from_email in /home/wordpri/www/cci/amar/Projet-v1 2 apache/vendor/symfony/maker-bundle/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php on line 60
');
self::assertEmailAddressContains($messages[0], 'to', 'me@example.com');
self::assertEmailTextBodyContains($messages[0], 'This link will expire in 1 hour.');
self::assertResponseRedirects('/reset-password/check-email');
// Test check email landing page shows correct "expires at" time
$crawler = $this->client->followRedirect();
self::assertPageTitleContains('Password Reset Email Sent');
self::assertStringContainsString('This link will expire in 1 hour', $crawler->html());
// Test the link sent in the email is valid
$email = $messages[0]->toString();
preg_match('#(/reset-password/reset/[a-zA-Z0-9]+)#', $email, $resetLink);
$this->client->request('GET', $resetLink[1]);
self::assertResponseRedirects('/reset-password/reset');
$this->client->followRedirect();
// Test we can set a new password
$this->client->submitForm('Reset password', [
'change_password_form[plainPassword][first]' => 'newStrongPassword',
'change_password_form[plainPassword][second]' => 'newStrongPassword',
]);
self::assertResponseRedirects('
Warning: Undefined variable $success_route_path in /home/wordpri/www/cci/amar/Projet-v1 2 apache/vendor/symfony/maker-bundle/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php on line 88
');
$user = $this->userRepository->findOneBy(['email' => 'me@example.com']);
self::assertInstanceOf(
Warning: Undefined variable $user_short_name in /home/wordpri/www/cci/amar/Projet-v1 2 apache/vendor/symfony/maker-bundle/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php on line 92
::class, $user);
/** @var UserPasswordHasherInterface $passwordHasher */
$passwordHasher = static::getContainer()->get(UserPasswordHasherInterface::class);
self::assertTrue($passwordHasher->isPasswordValid($user, 'newStrongPassword'));
}
}