]>
Commit | Line | Data |
---|---|---|
23ff8d36 JB |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\UserBundle\Mailer; |
23ff8d36 | 4 | |
bd91bd5c | 5 | use PHPUnit\Framework\TestCase; |
23ff8d36 JB |
6 | use Wallabag\UserBundle\Entity\User; |
7 | use Wallabag\UserBundle\Mailer\AuthCodeMailer; | |
23ff8d36 | 8 | |
bd91bd5c | 9 | class AuthCodeMailerTest extends TestCase |
23ff8d36 JB |
10 | { |
11 | protected $mailer; | |
12 | protected $spool; | |
7ce895bf | 13 | protected $twig; |
23ff8d36 JB |
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 | ||
084fb0d3 | 24 | $twigTemplate = <<<'TWIG' |
7ce895bf | 25 | {% block subject %}subject{% endblock %} |
abd454c4 JB |
26 | {% block body_html %}html body {{ code }}{% endblock %} |
27 | {% block body_text %}text body {{ support_url }}{% endblock %} | |
28 | TWIG; | |
29 | ||
4094ea47 | 30 | $this->twig = new \Twig_Environment(new \Twig_Loader_Array(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate])); |
23ff8d36 JB |
31 | } |
32 | ||
33 | public function testSendEmail() | |
34 | { | |
35 | $user = new User(); | |
a6b242a1 | 36 | $user->setEmailTwoFactor(true); |
23ff8d36 JB |
37 | $user->setEmailAuthCode(666666); |
38 | $user->setEmail('test@wallabag.io'); | |
39 | $user->setName('Bob'); | |
40 | ||
41 | $authCodeMailer = new AuthCodeMailer( | |
42 | $this->mailer, | |
7ce895bf | 43 | $this->twig, |
23ff8d36 JB |
44 | 'nobody@test.io', |
45 | 'wallabag test', | |
e1632cea JB |
46 | 'http://0.0.0.0/support', |
47 | 'http://0.0.0.0/' | |
23ff8d36 JB |
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()); | |
f808b016 JB |
56 | $this->assertSame(['nobody@test.io' => 'wallabag test'], $msg->getFrom()); |
57 | $this->assertSame('subject', $msg->getSubject()); | |
abd454c4 JB |
58 | $this->assertContains('text body http://0.0.0.0/support', $msg->toString()); |
59 | $this->assertContains('html body 666666', $msg->toString()); | |
23ff8d36 JB |
60 | } |
61 | } |