aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 09:59:46 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 11:17:06 +0100
commit23ff8d36199c0cddb5bae4a5010cb71f861eeef8 (patch)
tree0da3a5941c85f80408e49db63ecd3b3ba5347a40 /src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php
parentc997cfcc9c161241a6398b0942a1a869688d807a (diff)
downloadwallabag-23ff8d36199c0cddb5bae4a5010cb71f861eeef8.tar.gz
wallabag-23ff8d36199c0cddb5bae4a5010cb71f861eeef8.tar.zst
wallabag-23ff8d36199c0cddb5bae4a5010cb71f861eeef8.zip
Add custom email for 2FA
Related #1490
Diffstat (limited to 'src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php')
-rw-r--r--src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php b/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php
new file mode 100644
index 00000000..9122576a
--- /dev/null
+++ b/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php
@@ -0,0 +1,78 @@
1<?php
2
3namespace Wallabag\UserBundle\Tests\Mailer;
4
5use Wallabag\UserBundle\Entity\User;
6use Wallabag\UserBundle\Mailer\AuthCodeMailer;
7use Symfony\Component\Translation\Translator;
8use Symfony\Component\Translation\Loader\ArrayLoader;
9use Symfony\Component\Translation\DataCollectorTranslator;
10
11/**
12 * @see https://www.pmg.com/blog/integration-testing-swift-mailer/
13 */
14final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable
15{
16 public function count()
17 {
18 return count($this->messages);
19 }
20
21 public function getMessages()
22 {
23 return $this->messages;
24 }
25}
26
27class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
28{
29 protected $mailer;
30 protected $spool;
31 protected $dataCollector;
32
33 protected function setUp()
34 {
35 $this->spool = new CountableMemorySpool();
36 $transport = new \Swift_Transport_SpoolTransport(
37 new \Swift_Events_SimpleEventDispatcher(),
38 $this->spool
39 );
40 $this->mailer = new \Swift_Mailer($transport);
41
42 $translator = new Translator('en');
43 $translator->addLoader('array', new ArrayLoader());
44 $translator->addResource('array', array(
45 'auth_code.mailer.subject' => 'auth_code subject',
46 'auth_code.mailer.body' => 'Hi %user%, here is the code: %code% and the support: %support%',
47 ), 'en', 'wallabag_user');
48
49 $this->dataCollector = new DataCollectorTranslator($translator);
50 }
51
52 public function testSendEmail()
53 {
54 $user = new User();
55 $user->setTwoFactorAuthentication(true);
56 $user->setEmailAuthCode(666666);
57 $user->setEmail('test@wallabag.io');
58 $user->setName('Bob');
59
60 $authCodeMailer = new AuthCodeMailer(
61 $this->mailer,
62 $this->dataCollector,
63 'nobody@test.io',
64 'wallabag test',
65 'http://0.0.0.0'
66 );
67
68 $authCodeMailer->sendAuthCode($user);
69
70 $this->assertCount(1, $this->spool);
71
72 $msg = $this->spool->getMessages()[0];
73 $this->assertArrayHasKey('test@wallabag.io', $msg->getTo());
74 $this->assertEquals(array('nobody@test.io' => 'wallabag test'), $msg->getFrom());
75 $this->assertEquals('auth_code subject', $msg->getSubject());
76 $this->assertContains('Hi Bob, here is the code: 666666 and the support: http://0.0.0.0', $msg->toString());
77 }
78}