]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
Enable PHPStan
[github/wallabag/wallabag.git] / tests / Wallabag / UserBundle / Mailer / AuthCodeMailerTest.php
1 <?php
2
3 namespace Tests\Wallabag\UserBundle\Mailer;
4
5 use PHPUnit\Framework\TestCase;
6 use Wallabag\UserBundle\Entity\User;
7 use Wallabag\UserBundle\Mailer\AuthCodeMailer;
8
9 class AuthCodeMailerTest extends TestCase
10 {
11 protected $mailer;
12 protected $spool;
13 protected $twig;
14
15 protected function setUp()
16 {
17 $this->spool = new CountableMemorySpool();
18 $transport = new \Swift_Transport_SpoolTransport(
19 new \Swift_Events_SimpleEventDispatcher(),
20 $this->spool
21 );
22 $this->mailer = new \Swift_Mailer($transport);
23
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 %}
28 TWIG;
29
30 $this->twig = new \Twig_Environment(new \Twig_Loader_Array(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate]));
31 }
32
33 public function testSendEmail()
34 {
35 $user = new User();
36 $user->setTwoFactorAuthentication(true);
37 $user->setEmailAuthCode(666666);
38 $user->setEmail('test@wallabag.io');
39 $user->setName('Bob');
40
41 $authCodeMailer = new AuthCodeMailer(
42 $this->mailer,
43 $this->twig,
44 'nobody@test.io',
45 'wallabag test',
46 'http://0.0.0.0/support',
47 'http://0.0.0.0/'
48 );
49
50 $authCodeMailer->sendAuthCode($user);
51
52 $this->assertCount(1, $this->spool);
53
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());
60 }
61 }