3 namespace Tests\Wallabag\UserBundle\Mailer
;
5 use PHPUnit\Framework\TestCase
;
7 use Twig\Loader\ArrayLoader
;
8 use Wallabag\UserBundle\Entity\User
;
9 use Wallabag\UserBundle\Mailer\AuthCodeMailer
;
11 class AuthCodeMailerTest
extends TestCase
17 protected function setUp()
19 $this->spool
= new CountableMemorySpool();
20 $transport = new \
Swift_Transport_SpoolTransport(
21 new \
Swift_Events_SimpleEventDispatcher(),
24 $this->mailer
= new \
Swift_Mailer($transport);
26 $twigTemplate = <<<'TWIG'
27 {% block subject %}subject{% endblock %}
28 {% block body_html %}html body {{ code }}{% endblock %}
29 {% block body_text %}text body {{ support_url }}{% endblock %}
32 $this->twig
= new Environment(new ArrayLoader(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate]));
35 public function testSendEmail()
38 $user->setEmailTwoFactor(true);
39 $user->setEmailAuthCode(666666);
40 $user->setEmail('test@wallabag.io');
41 $user->setName('Bob');
43 $authCodeMailer = new AuthCodeMailer(
48 'http://0.0.0.0/support',
52 $authCodeMailer->sendAuthCode($user);
54 $this->assertCount(1, $this->spool
);
56 $msg = $this->spool
->getMessages()[0];
57 $this->assertArrayHasKey('test@wallabag.io', $msg->getTo());
58 $this->assertSame(['nobody@test.io' => 'wallabag test'], $msg->getFrom());
59 $this->assertSame('subject', $msg->getSubject());
60 $this->assertContains('text body http://0.0.0.0/support', $msg->toString());
61 $this->assertContains('html body 666666', $msg->toString());