Skip to content
Snippets Groups Projects
Commit b993b5f8 authored by Camille Simiand's avatar Camille Simiand
Browse files

Add email tests

parent 9080ad06
No related branches found
No related tags found
1 merge request!23Tuleap 47 reset my password
<?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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment