aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Tests
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas@loeuillet.org>2015-12-29 20:32:58 +0100
committerNicolas Lœuillet <nicolas@loeuillet.org>2015-12-29 20:32:58 +0100
commite6a228c43bf98f64d2d046314bae224c5b87399e (patch)
tree950c2c0533d4425b6572cfa9de84c40c44956b12 /src/Wallabag/UserBundle/Tests
parentc997cfcc9c161241a6398b0942a1a869688d807a (diff)
parentab64c3d9ac591d30447428bd357b5b8c3a9bbcd7 (diff)
downloadwallabag-e6a228c43bf98f64d2d046314bae224c5b87399e.tar.gz
wallabag-e6a228c43bf98f64d2d046314bae224c5b87399e.tar.zst
wallabag-e6a228c43bf98f64d2d046314bae224c5b87399e.zip
Merge pull request #1544 from wallabag/2fa-email
v2 – Add custom email for 2FA
Diffstat (limited to 'src/Wallabag/UserBundle/Tests')
-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}