diff options
Diffstat (limited to 'src/Wallabag/UserBundle/Tests')
-rw-r--r-- | src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php | 25 |
1 files changed, 13 insertions, 12 deletions
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 | ||
5 | use Wallabag\UserBundle\Entity\User; | 5 | use Wallabag\UserBundle\Entity\User; |
6 | use Wallabag\UserBundle\Mailer\AuthCodeMailer; | 6 | use Wallabag\UserBundle\Mailer\AuthCodeMailer; |
7 | use Symfony\Component\Translation\Translator; | ||
8 | use 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%', | 43 | TWIG; |
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 | } |