aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle')
-rw-r--r--src/Wallabag/UserBundle/Controller/ResettingController.php75
-rw-r--r--src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php41
-rw-r--r--src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php58
-rw-r--r--src/Wallabag/UserBundle/Resources/config/services.yml15
-rw-r--r--src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml13
-rw-r--r--src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml13
-rw-r--r--src/Wallabag/UserBundle/Resources/translations/wallabag_user.tr.yml7
-rw-r--r--src/Wallabag/UserBundle/Resources/views/TwoFactor/email_auth_code.html.twig117
-rw-r--r--src/Wallabag/UserBundle/Resources/views/themes/material/layout.html.twig2
-rw-r--r--src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php25
10 files changed, 240 insertions, 126 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ResettingController.php b/src/Wallabag/UserBundle/Controller/ResettingController.php
deleted file mode 100644
index 62e27d00..00000000
--- a/src/Wallabag/UserBundle/Controller/ResettingController.php
+++ /dev/null
@@ -1,75 +0,0 @@
1<?php
2
3namespace Wallabag\UserBundle\Controller;
4
5use FOS\UserBundle\Event\FilterUserResponseEvent;
6use FOS\UserBundle\Event\FormEvent;
7use FOS\UserBundle\Event\GetResponseUserEvent;
8use FOS\UserBundle\FOSUserEvents;
9use Symfony\Component\HttpFoundation\RedirectResponse;
10use Symfony\Component\HttpFoundation\Request;
11use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13class ResettingController extends \FOS\UserBundle\Controller\ResettingController
14{
15 /**
16 * Extends ResettingController to change the redirection after success.
17 *
18 * @param Request $request
19 * @param $token
20 *
21 * @return null|RedirectResponse|\Symfony\Component\HttpFoundation\Response
22 */
23 public function resetAction(Request $request, $token)
24 {
25 /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
26 $formFactory = $this->get('fos_user.resetting.form.factory');
27 /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
28 $userManager = $this->get('fos_user.user_manager');
29 /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
30 $dispatcher = $this->get('event_dispatcher');
31
32 $user = $userManager->findUserByConfirmationToken($token);
33
34 if (null === $user) {
35 throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
36 }
37
38 $event = new GetResponseUserEvent($user, $request);
39 $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_INITIALIZE, $event);
40
41 if (null !== $event->getResponse()) {
42 return $event->getResponse();
43 }
44
45 $form = $formFactory->createForm();
46 $form->setData($user);
47
48 $form->handleRequest($request);
49
50 if ($form->isValid()) {
51 $event = new FormEvent($form, $request);
52 $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_SUCCESS, $event);
53
54 $userManager->updateUser($user);
55
56 if (null === $response = $event->getResponse()) {
57 $this->get('session')->getFlashBag()->add(
58 'notice',
59 'Password updated'
60 );
61 $url = $this->generateUrl('homepage');
62 $response = new RedirectResponse($url);
63 }
64
65 $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
66
67 return $response;
68 }
69
70 return $this->render('FOSUserBundle:Resetting:reset.html.twig', array(
71 'token' => $token,
72 'form' => $form->createView(),
73 ));
74 }
75}
diff --git a/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php b/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php
new file mode 100644
index 00000000..128e85a4
--- /dev/null
+++ b/src/Wallabag/UserBundle/EventListener/PasswordResettingListener.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\UserBundle\EventListener;
4
5use FOS\UserBundle\FOSUserEvents;
6use FOS\UserBundle\Event\FormEvent;
7use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8use Symfony\Component\HttpFoundation\RedirectResponse;
9use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
10
11/**
12 * Listener responsible to change the redirection at the end of the password resetting.
13 *
14 * @see http://symfony.com/doc/current/bundles/FOSUserBundle/controller_events.html
15 */
16class PasswordResettingListener implements EventSubscriberInterface
17{
18 private $router;
19
20 public function __construct(UrlGeneratorInterface $router)
21 {
22 $this->router = $router;
23 }
24
25 /**
26 * {@inheritdoc}
27 */
28 public static function getSubscribedEvents()
29 {
30 return array(
31 FOSUserEvents::RESETTING_RESET_SUCCESS => 'onPasswordResettingSuccess',
32 );
33 }
34
35 public function onPasswordResettingSuccess(FormEvent $event)
36 {
37 $url = $this->router->generate('homepage');
38
39 $event->setResponse(new RedirectResponse($url));
40 }
41}
diff --git a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
index be370e71..6b108dd3 100644
--- a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
+++ b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
@@ -4,7 +4,6 @@ namespace Wallabag\UserBundle\Mailer;
4 4
5use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; 5use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
6use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface; 6use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
7use Symfony\Component\Translation\TranslatorInterface;
8 7
9/** 8/**
10 * Custom mailer for TwoFactorBundle email. 9 * Custom mailer for TwoFactorBundle email.
@@ -20,11 +19,11 @@ class AuthCodeMailer implements AuthCodeMailerInterface
20 private $mailer; 19 private $mailer;
21 20
22 /** 21 /**
23 * Translator for email content. 22 * Twig to render the html's email.
24 * 23 *
25 * @var TranslatorInterface 24 * @var \Twig_Environment
26 */ 25 */
27 private $translator; 26 private $twig;
28 27
29 /** 28 /**
30 * Sender email address. 29 * Sender email address.
@@ -48,21 +47,30 @@ class AuthCodeMailer implements AuthCodeMailerInterface
48 private $supportUrl; 47 private $supportUrl;
49 48
50 /** 49 /**
50 * Url for the wallabag instance.
51 *
52 * @var string
53 */
54 private $wallabagUrl;
55
56 /**
51 * Initialize the auth code mailer with the SwiftMailer object. 57 * Initialize the auth code mailer with the SwiftMailer object.
52 * 58 *
53 * @param \Swift_Mailer $mailer 59 * @param \Swift_Mailer $mailer
54 * @param TranslatorInterface $translator 60 * @param \Twig_Environment $twig
55 * @param string $senderEmail 61 * @param string $senderEmail
56 * @param string $senderName 62 * @param string $senderName
57 * @param string $supportUrl 63 * @param string $supportUrl
64 * @param string $wallabagUrl
58 */ 65 */
59 public function __construct(\Swift_Mailer $mailer, TranslatorInterface $translator, $senderEmail, $senderName, $supportUrl) 66 public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig, $senderEmail, $senderName, $supportUrl, $wallabagUrl)
60 { 67 {
61 $this->mailer = $mailer; 68 $this->mailer = $mailer;
62 $this->translator = $translator; 69 $this->twig = $twig;
63 $this->senderEmail = $senderEmail; 70 $this->senderEmail = $senderEmail;
64 $this->senderName = $senderName; 71 $this->senderName = $senderName;
65 $this->supportUrl = $supportUrl; 72 $this->supportUrl = $supportUrl;
73 $this->wallabagUrl = $wallabagUrl;
66 } 74 }
67 75
68 /** 76 /**
@@ -72,20 +80,28 @@ class AuthCodeMailer implements AuthCodeMailerInterface
72 */ 80 */
73 public function sendAuthCode(TwoFactorInterface $user) 81 public function sendAuthCode(TwoFactorInterface $user)
74 { 82 {
83 $template = $this->twig->loadTemplate('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig');
84
85 $subject = $template->renderBlock('subject', array());
86 $bodyHtml = $template->renderBlock('body_html', [
87 'user' => $user->getName(),
88 'code' => $user->getEmailAuthCode(),
89 'support_url' => $this->supportUrl,
90 'wallabag_url' => $this->wallabagUrl,
91 ]);
92 $bodyText = $template->renderBlock('body_text', [
93 'user' => $user->getName(),
94 'code' => $user->getEmailAuthCode(),
95 'support_url' => $this->supportUrl,
96 ]);
97
75 $message = new \Swift_Message(); 98 $message = new \Swift_Message();
76 $message 99 $message
77 ->setTo($user->getEmail()) 100 ->setTo($user->getEmail())
78 ->setFrom($this->senderEmail, $this->senderName) 101 ->setFrom($this->senderEmail, $this->senderName)
79 ->setSubject($this->translator->trans('auth_code.mailer.subject', array(), 'wallabag_user')) 102 ->setSubject($subject)
80 ->setBody($this->translator->trans( 103 ->setBody($bodyText, 'text/plain')
81 'auth_code.mailer.body', 104 ->addPart($bodyHtml, 'text/html')
82 [
83 '%user%' => $user->getName(),
84 '%code%' => $user->getEmailAuthCode(),
85 '%support%' => $this->supportUrl,
86 ],
87 'wallabag_user'
88 ))
89 ; 105 ;
90 106
91 $this->mailer->send($message); 107 $this->mailer->send($message);
diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml
index 9109b6a3..8321473a 100644
--- a/src/Wallabag/UserBundle/Resources/config/services.yml
+++ b/src/Wallabag/UserBundle/Resources/config/services.yml
@@ -1,9 +1,22 @@
1services: 1services:
2 # might be fixed in the symfony release
3 # https://github.com/FriendsOfSymfony/FOSUserBundle/issues/2048
4 fos_user.doctrine_registry:
5 alias: doctrine
6
2 wallabag_user.auth_code_mailer: 7 wallabag_user.auth_code_mailer:
3 class: Wallabag\UserBundle\Mailer\AuthCodeMailer 8 class: Wallabag\UserBundle\Mailer\AuthCodeMailer
4 arguments: 9 arguments:
5 - "@mailer" 10 - "@mailer"
6 - "@translator" 11 - "@twig"
7 - "%scheb_two_factor.email.sender_email%" 12 - "%scheb_two_factor.email.sender_email%"
8 - "%scheb_two_factor.email.sender_name%" 13 - "%scheb_two_factor.email.sender_name%"
9 - "%wallabag_support_url%" 14 - "%wallabag_support_url%"
15 - "%wallabag_url%"
16
17 wallabag_user.password_resetting:
18 class: Wallabag\UserBundle\EventListener\PasswordResettingListener
19 arguments:
20 - "@router"
21 tags:
22 - { name: kernel.event_subscriber }
diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml
index f806d1d6..4da6075f 100644
--- a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml
+++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.en.yml
@@ -1,10 +1,7 @@
1# Two factor mail 1# Two factor mail
2auth_code.mailer.subject: 'Wallabag authentication Code' 2auth_code.mailer.subject: 'Wallabag authentication Code'
3auth_code.mailer.body: | 3auth_code.mailer.body.hello: "Hi %user%,"
4 Hi %user%, 4auth_code.mailer.body.first_para: "Since you enable two factor authentication on your wallabag account and you just logged in from a new device (computer, phone, etc.), we send you a code to validate your connection."
5 5auth_code.mailer.body.second_para: "Here is the code:"
6 Since you enable two factor authentication on your wallabag account and you just logged in from a new device (computer, phone, etc.), we send you a code to validate your connection. 6auth_code.mailer.body.support: "Please don't hesitate to contact us if you have any problems:"
7 Here is the code: %code% 7auth_code.mailer.body.signature: "The wallabag team"
8
9 Please don't hesitate to contact us if you have any problems: %support%
10 The wallabag team
diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml
index 386b2d9e..b4448d3a 100644
--- a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml
+++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.fr.yml
@@ -1,10 +1,7 @@
1# Two factor mail 1# Two factor mail
2auth_code.mailer.subject: "Code d'authentification wallabag" 2auth_code.mailer.subject: "Code d'authentification wallabag"
3auth_code.mailer.body: | 3auth_code.mailer.body.hello: "Bonjour %user%,"
4 Bonjour %user%, 4auth_code.mailer.body.first_para: "Comme vous avez activé la double authentification sur votre compte wallabag et que vous venez de vous connecter depuis un nouvel appareil (ordinateur, téléphone, etc.), nous vous envoyons un code pour valider votre connexion."
5 5auth_code.mailer.body.second_para: "Voici le code à renseigner :"
6 Comme vous avez activé la double authentification sur votre compte wallabag et que vous venez de vous connecter depuis un nouvel appareil (ordinateur, téléphone, etc.), nous vous envoyons un code pour valider votre connexion. 6auth_code.mailer.body.support: "Si vous avez un problème de connexion, n'hésitez pas à contacter le support :"
7 Voici le code à renseigner: %code% 7auth_code.mailer.body.signature: "L'équipe wallabag"
8
9 Si vous avez un problème de connexion, n'hésitez pas à contacter le support: %support%
10 L'équipe wallabag
diff --git a/src/Wallabag/UserBundle/Resources/translations/wallabag_user.tr.yml b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.tr.yml
new file mode 100644
index 00000000..d1fcb0e0
--- /dev/null
+++ b/src/Wallabag/UserBundle/Resources/translations/wallabag_user.tr.yml
@@ -0,0 +1,7 @@
1# Two factor mail
2auth_code.mailer.subject: 'Wallabag DoÄŸrulama Kodu'
3auth_code.mailer.body.hello: "Merhaba %user%,"
4auth_code.mailer.body.first_para: "wallabag hesabınızda iki adımlı doğrulamayı etkinleştirdiğinizde ve bu yeni cihaz olduğunda (bilgisayar, telefon, vs.), biz size bu işlemi doğrulamak için bir kod göndeririz."
5auth_code.mailer.body.second_para: "Bu işlem için doğrulama kodunuz:"
6auth_code.mailer.body.support: "Eğer herhangi bir soru/sorununuz varsa, bizimle iletişime geçmekten çekinmeyin:"
7auth_code.mailer.body.signature: "wallabag ekibi"
diff --git a/src/Wallabag/UserBundle/Resources/views/TwoFactor/email_auth_code.html.twig b/src/Wallabag/UserBundle/Resources/views/TwoFactor/email_auth_code.html.twig
new file mode 100644
index 00000000..69d23160
--- /dev/null
+++ b/src/Wallabag/UserBundle/Resources/views/TwoFactor/email_auth_code.html.twig
@@ -0,0 +1,117 @@
1{% block subject %}
2{{ "auth_code.mailer.subject"|trans({}, 'wallabag_user') }}
3{% endblock %}
4
5{% block body_text %}
6{{ "auth_code.mailer.body.hello"|trans({'%user%': user}, 'wallabag_user') }}
7
8{{ "auth_code.mailer.body.first_para"|trans({}, 'wallabag_user') }}
9{{ "auth_code.mailer.body.second_para"|trans({}, 'wallabag_user') }} {{ code }}
10
11{{ "auth_code.mailer.body.support"|trans({}, 'wallabag_user') }} {{ support_url }}
12
13{{ "auth_code.mailer.body.signature"|trans({}, 'wallabag_user') }}
14{% endblock %}
15
16{% block body_html %}
17<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
18
19<html xmlns="http://www.w3.org/1999/xhtml">
20<head>
21 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
22 <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
23 <title>{{ "auth_code.mailer.subject"|trans({}, 'wallabag_user') }}</title>
24 <style type="text/css">
25 #outlook a {padding:0;}
26 body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0; font-family: Helvetica, Arial, sans-serif; background: #c6d4e0;}
27 .ExternalClass {width:100%;}
28 .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}
29 #backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important; background: #c6d4e0;}
30 img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;}
31 a img {border:none;}
32 .image_fix {display:block;}
33 p {margin: 1em 0;}
34 h1, h2, h3, h4, h5, h6 {color: black !important;}
35 h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}
36 h1 a:active, h2 a:active, h3 a:active, h4 a:active, h5 a:active, h6 a:active {
37 color: red !important;
38 }
39 h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
40 color: purple !important;
41 }
42 table td {border-collapse: collapse;}
43 table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }
44 a {color: #373737;}
45
46 #card {
47 background: #ffffff;
48 border: 1px solid #c5c5c5;
49 width: 89%;
50 margin: 5%;
51 }
52 #cell_desc h1, h5 {
53 display: block;
54 margin: 0;
55 }
56 #cell_desc h1 {
57 line-height: 35px;
58 margin-bottom: 10px;
59 }
60 #bg {background: #f2f2f2}
61
62 </style>
63</head>
64<body>
65
66 <!-- hidden text for preview -->
67 <div style="display:none;font-size:1px;color:#333333;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;">
68 {{ "auth_code.mailer.body.hello"|trans({'%user%': user}, 'wallabag_user') }}
69 </div>
70
71 <table cellpadding="0" cellspacing="0" border="0" id="backgroundTable">
72 <tr>
73 <td>
74
75 <table cellpadding="0" cellspacing="0" border="0" align="center" id="card">
76 <tr>
77 <td style="padding: 20px;" width="96px" valign="top"><img class="image_fix" src="{{ wallabag_url }}/themes/material/img/logo-other_themes.png" alt="logo" title="{{ wallabag_url }}" style="width: 96px; height: 96px;" /></td>
78 <td style="padding: 20px; padding-left: 0;" valign="top" id="cell_desc">
79 <h1>wallabag</h1>
80 <h5>{% trans %}on{% endtrans %} {{ wallabag_url }}</h5>
81 </td>
82 </tr>
83 <tr><td colspan="2" style="padding: 0;"><div style="height: 0; border-top: 1px solid #c5c5c5;">&nbsp;</div></td></tr>
84 <tr id="bg">
85 <td style="padding: 20px;" colspan="2" valign="top">
86
87 <p><b>{{ "auth_code.mailer.body.hello"|trans({'%user%': user}, 'wallabag_user') }}</b></p>
88
89 <p>{{ "auth_code.mailer.body.first_para"|trans({}, 'wallabag_user') }}</p>
90 <p>{{ "auth_code.mailer.body.second_para"|trans({}, 'wallabag_user') }} <b>{{ code }}</b></p>
91
92 <p>{{ "auth_code.mailer.body.support"|trans({}, 'wallabag_user') }} <a href="{{ support_url }}">{{ support_url }}</a></p>
93 <p>{{ "auth_code.mailer.body.signature"|trans({}, 'wallabag_user') }}</p>
94 </td>
95 </tr>
96 <tr><td colspan="2" style="padding: 0;"><div style="height: 0; border-top: 1px solid #c5c5c5;">&nbsp;</div></td></tr>
97 <tr>
98 <td colspan="2">
99
100 <table cellpadding="0" cellspacing="0" border="0" width="100%">
101 <tr>
102 <td valign="top" style="padding: 20px; text-align: center"><a href="{{ wallabag_url }}">{{ wallabag_url }}</a></td>
103 <td valign="top" style="padding: 20px; text-align: center">Powered by <a href="https://www.wallabag.org/">wallabag</a></td>
104 </tr>
105 </table>
106
107 </td>
108 </tr>
109 </table>
110
111 </td>
112 </tr>
113 </table>
114
115</body>
116</html>
117{% endblock %}
diff --git a/src/Wallabag/UserBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/UserBundle/Resources/views/themes/material/layout.html.twig
index a69e68c2..9247a2c0 100644
--- a/src/Wallabag/UserBundle/Resources/views/themes/material/layout.html.twig
+++ b/src/Wallabag/UserBundle/Resources/views/themes/material/layout.html.twig
@@ -11,7 +11,7 @@
11<main class="valign-wrapper"> 11<main class="valign-wrapper">
12 <div class="valign row"> 12 <div class="valign row">
13 <div class="card sw"> 13 <div class="card sw">
14 <div class="center"><img src="{{ asset('themes/material/img/logo-other_themes.png') }}" alt="wallabag logo" /></div> 14 <div class="center"><img src="{{ asset('bundles/wallabagcore/themes/material/img/logo-other_themes.png') }}" alt="wallabag logo" /></div>
15 {% block fos_user_content %} 15 {% block fos_user_content %}
16 {% endblock fos_user_content %} 16 {% endblock fos_user_content %}
17 </div> 17 </div>
diff --git a/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php b/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php
index 61e960f9..e3f43a7e 100644
--- a/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php
+++ b/src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php
@@ -4,8 +4,6 @@ namespace Wallabag\UserBundle\Tests\Mailer;
4 4
5use Wallabag\UserBundle\Entity\User; 5use Wallabag\UserBundle\Entity\User;
6use Wallabag\UserBundle\Mailer\AuthCodeMailer; 6use Wallabag\UserBundle\Mailer\AuthCodeMailer;
7use Symfony\Component\Translation\Translator;
8use Symfony\Component\Translation\Loader\ArrayLoader;
9 7
10/** 8/**
11 * @see https://www.pmg.com/blog/integration-testing-swift-mailer/ 9 * @see https://www.pmg.com/blog/integration-testing-swift-mailer/
@@ -27,7 +25,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
27{ 25{
28 protected $mailer; 26 protected $mailer;
29 protected $spool; 27 protected $spool;
30 protected $translator; 28 protected $twig;
31 29
32 protected function setUp() 30 protected function setUp()
33 { 31 {
@@ -38,12 +36,13 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
38 ); 36 );
39 $this->mailer = new \Swift_Mailer($transport); 37 $this->mailer = new \Swift_Mailer($transport);
40 38
41 $this->translator = new Translator('en'); 39 $twigTemplate = <<<TWIG
42 $this->translator->addLoader('array', new ArrayLoader()); 40{% block subject %}subject{% endblock %}
43 $this->translator->addResource('array', array( 41{% block body_html %}html body {{ code }}{% endblock %}
44 'auth_code.mailer.subject' => 'auth_code subject', 42{% block body_text %}text body {{ support_url }}{% endblock %}
45 'auth_code.mailer.body' => 'Hi %user%, here is the code: %code% and the support: %support%', 43TWIG;
46 ), 'en', 'wallabag_user'); 44
45 $this->twig = new \Twig_Environment(new \Twig_Loader_Array(array('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig' => $twigTemplate)));
47 } 46 }
48 47
49 public function testSendEmail() 48 public function testSendEmail()
@@ -56,9 +55,10 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
56 55
57 $authCodeMailer = new AuthCodeMailer( 56 $authCodeMailer = new AuthCodeMailer(
58 $this->mailer, 57 $this->mailer,
59 $this->translator, 58 $this->twig,
60 'nobody@test.io', 59 'nobody@test.io',
61 'wallabag test', 60 'wallabag test',
61 'http://0.0.0.0/support',
62 'http://0.0.0.0' 62 'http://0.0.0.0'
63 ); 63 );
64 64
@@ -69,7 +69,8 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
69 $msg = $this->spool->getMessages()[0]; 69 $msg = $this->spool->getMessages()[0];
70 $this->assertArrayHasKey('test@wallabag.io', $msg->getTo()); 70 $this->assertArrayHasKey('test@wallabag.io', $msg->getTo());
71 $this->assertEquals(array('nobody@test.io' => 'wallabag test'), $msg->getFrom()); 71 $this->assertEquals(array('nobody@test.io' => 'wallabag test'), $msg->getFrom());
72 $this->assertEquals('auth_code subject', $msg->getSubject()); 72 $this->assertEquals('subject', $msg->getSubject());
73 $this->assertContains('Hi Bob, here is the code: 666666 and the support: http://0.0.0.0', $msg->toString()); 73 $this->assertContains('text body http://0.0.0.0/support', $msg->toString());
74 $this->assertContains('html body 666666', $msg->toString());
74 } 75 }
75} 76}