]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
Merge pull request #4021 from wallabag/doc/improve-contributing
[github/wallabag/wallabag.git] / tests / Wallabag / UserBundle / Mailer / AuthCodeMailerTest.php
CommitLineData
23ff8d36
JB
1<?php
2
23634d5d 3namespace Tests\Wallabag\UserBundle\Mailer;
23ff8d36 4
bd91bd5c 5use PHPUnit\Framework\TestCase;
a2f4efe6
JB
6use Twig\Environment;
7use Twig\Loader\ArrayLoader;
23ff8d36
JB
8use Wallabag\UserBundle\Entity\User;
9use Wallabag\UserBundle\Mailer\AuthCodeMailer;
23ff8d36 10
bd91bd5c 11class AuthCodeMailerTest extends TestCase
23ff8d36
JB
12{
13 protected $mailer;
14 protected $spool;
7ce895bf 15 protected $twig;
23ff8d36
JB
16
17 protected function setUp()
18 {
19 $this->spool = new CountableMemorySpool();
20 $transport = new \Swift_Transport_SpoolTransport(
21 new \Swift_Events_SimpleEventDispatcher(),
22 $this->spool
23 );
24 $this->mailer = new \Swift_Mailer($transport);
25
084fb0d3 26 $twigTemplate = <<<'TWIG'
7ce895bf 27{% block subject %}subject{% endblock %}
abd454c4
JB
28{% block body_html %}html body {{ code }}{% endblock %}
29{% block body_text %}text body {{ support_url }}{% endblock %}
30TWIG;
31
a2f4efe6 32 $this->twig = new Environment(new ArrayLoader(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate]));
23ff8d36
JB
33 }
34
35 public function testSendEmail()
36 {
37 $user = new User();
a6b242a1 38 $user->setEmailTwoFactor(true);
23ff8d36
JB
39 $user->setEmailAuthCode(666666);
40 $user->setEmail('test@wallabag.io');
41 $user->setName('Bob');
42
43 $authCodeMailer = new AuthCodeMailer(
44 $this->mailer,
7ce895bf 45 $this->twig,
23ff8d36
JB
46 'nobody@test.io',
47 'wallabag test',
e1632cea
JB
48 'http://0.0.0.0/support',
49 'http://0.0.0.0/'
23ff8d36
JB
50 );
51
52 $authCodeMailer->sendAuthCode($user);
53
54 $this->assertCount(1, $this->spool);
55
56 $msg = $this->spool->getMessages()[0];
57 $this->assertArrayHasKey('test@wallabag.io', $msg->getTo());
f808b016
JB
58 $this->assertSame(['nobody@test.io' => 'wallabag test'], $msg->getFrom());
59 $this->assertSame('subject', $msg->getSubject());
abd454c4
JB
60 $this->assertContains('text body http://0.0.0.0/support', $msg->toString());
61 $this->assertContains('html body 666666', $msg->toString());
23ff8d36
JB
62 }
63}