3 namespace Tests\Wallabag\UserBundle\Mailer
;
5 use PHPUnit\Framework\TestCase
;
6 use Wallabag\UserBundle\Entity\User
;
7 use Wallabag\UserBundle\Mailer\AuthCodeMailer
;
9 class AuthCodeMailerTest
extends TestCase
15 protected function setUp()
17 $this->spool
= new CountableMemorySpool();
18 $transport = new \
Swift_Transport_SpoolTransport(
19 new \
Swift_Events_SimpleEventDispatcher(),
22 $this->mailer
= new \
Swift_Mailer($transport);
24 $twigTemplate = <<<'TWIG'
25 {% block subject %}subject{% endblock %}
26 {% block body_html %}html body {{ code }}{% endblock %}
27 {% block body_text %}text body {{ support_url }}{% endblock %}
30 $this->twig
= new \
Twig_Environment(new \
Twig_Loader_Array(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate]));
33 public function testSendEmail()
36 $user->setEmailTwoFactor(true);
37 $user->setEmailAuthCode(666666);
38 $user->setEmail('test@wallabag.io');
39 $user->setName('Bob');
41 $authCodeMailer = new AuthCodeMailer(
46 'http://0.0.0.0/support',
50 $authCodeMailer->sendAuthCode($user);
52 $this->assertCount(1, $this->spool
);
54 $msg = $this->spool
->getMessages()[0];
55 $this->assertArrayHasKey('test@wallabag.io', $msg->getTo());
56 $this->assertSame(['nobody@test.io' => 'wallabag test'], $msg->getFrom());
57 $this->assertSame('subject', $msg->getSubject());
58 $this->assertContains('text body http://0.0.0.0/support', $msg->toString());
59 $this->assertContains('html body 666666', $msg->toString());