]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Tests\Wallabag\UserBundle\Mailer; | |
4 | ||
5 | use PHPUnit\Framework\TestCase; | |
6 | use Twig\Environment; | |
7 | use Twig\Loader\ArrayLoader; | |
8 | use Wallabag\UserBundle\Entity\User; | |
9 | use Wallabag\UserBundle\Mailer\AuthCodeMailer; | |
10 | ||
11 | class AuthCodeMailerTest extends TestCase | |
12 | { | |
13 | protected $mailer; | |
14 | protected $spool; | |
15 | protected $twig; | |
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 | ||
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 %} | |
30 | TWIG; | |
31 | ||
32 | $this->twig = new Environment(new ArrayLoader(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate])); | |
33 | } | |
34 | ||
35 | public function testSendEmail() | |
36 | { | |
37 | $user = new User(); | |
38 | $user->setEmailTwoFactor(true); | |
39 | $user->setEmailAuthCode(666666); | |
40 | $user->setEmail('test@wallabag.io'); | |
41 | $user->setName('Bob'); | |
42 | ||
43 | $authCodeMailer = new AuthCodeMailer( | |
44 | $this->mailer, | |
45 | $this->twig, | |
46 | 'nobody@test.io', | |
47 | 'wallabag test', | |
48 | 'http://0.0.0.0/support', | |
49 | 'http://0.0.0.0/' | |
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()); | |
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()); | |
62 | } | |
63 | } |