diff --git a/tests/functional/ResetPasswordControllerTest.php b/tests/functional/ResetPasswordControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0487400d3a30c3bed461fa2d37522c00e65c786d --- /dev/null +++ b/tests/functional/ResetPasswordControllerTest.php @@ -0,0 +1,52 @@ +<?php + +namespace App\Tests\Controller; + +use Symfony\Bundle\FrameworkBundle\KernelBrowser; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\DomCrawler\Form; + +class ResetPasswordControllerTest extends WebTestCase +{ + private KernelBrowser $client; + private Form $form; + private const VERIFIED_USER_EMAIL = 'defaultUser@localhost.com'; + private const UNVERIFIED_USER_EMAIL = 'notRegistered@localhost.com'; + + protected function setUp(): void + { + $this->client = static::createClient(); + $crawler = $this->client->request('GET', '/reset-password'); + $this->assertResponseIsSuccessful(); + + $this->client->enableProfiler(); + + $submit_button = $crawler->selectButton('Reset password'); + $this->form = $submit_button->form(); + } + + public function testVerifiedUserShouldReceiveAnEmailLinkToResetHisPassword(): void + { + $this->form['reset_password_request_form[email]'] = self::VERIFIED_USER_EMAIL; + $this->client->submit($this->form); + + $emailMessage = $this->getMailerMessage(0); + + $this->assertEmailCount(1, null); + $this->assertEmailTextBodyContains($emailMessage, 'To reset your password, please visit the following link'); + $this->assertEmailAddressContains( + $emailMessage, + 'To', + self::VERIFIED_USER_EMAIL, + 'When resetting a password, an already registered user should receive an email with the reset password link' + ); + } + + public function testUnverifiedUserShouldNotReceiveAnEmailLinkToResetHisPassword(): void + { + $this->form['reset_password_request_form[email]'] = self::UNVERIFIED_USER_EMAIL; + $this->client->submit($this->form); + + $this->assertEmailCount(0); + } +}