diff options
author | Jeremy <jeremy.benoist@gmail.com> | 2015-03-07 23:25:36 +0100 |
---|---|---|
committer | Jeremy <jeremy.benoist@gmail.com> | 2015-03-08 07:35:24 +0100 |
commit | 6894d48e03c397096bb64420373afa60c397fe97 (patch) | |
tree | 0deb201b05b6aea527abc82ba7989732c4afbdb9 /src/Wallabag/CoreBundle/Tests | |
parent | f37d1427a1b75f9d7a2e273b2e9fb0e895a769ab (diff) | |
download | wallabag-6894d48e03c397096bb64420373afa60c397fe97.tar.gz wallabag-6894d48e03c397096bb64420373afa60c397fe97.tar.zst wallabag-6894d48e03c397096bb64420373afa60c397fe97.zip |
Handle forgot password
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php index 54cf5073..e02c4d05 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | |||
@@ -3,6 +3,8 @@ | |||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | 3 | namespace Wallabag\CoreBundle\Tests\Controller; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagTestCase; | 5 | use Wallabag\CoreBundle\Tests\WallabagTestCase; |
6 | use Symfony\Component\Filesystem\Filesystem; | ||
7 | use Symfony\Component\Finder\Finder; | ||
6 | 8 | ||
7 | class SecurityControllerTest extends WallabagTestCase | 9 | class SecurityControllerTest extends WallabagTestCase |
8 | { | 10 | { |
@@ -37,4 +39,99 @@ class SecurityControllerTest extends WallabagTestCase | |||
37 | 39 | ||
38 | $this->assertContains('Bad credentials', $client->getResponse()->getContent()); | 40 | $this->assertContains('Bad credentials', $client->getResponse()->getContent()); |
39 | } | 41 | } |
42 | |||
43 | public function testForgotPassword() | ||
44 | { | ||
45 | $client = $this->getClient(); | ||
46 | |||
47 | $crawler = $client->request('GET', '/forgot-password'); | ||
48 | |||
49 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
50 | |||
51 | $this->assertContains('Forgot password', $client->getResponse()->getContent()); | ||
52 | |||
53 | $form = $crawler->filter('button[type=submit]'); | ||
54 | |||
55 | $this->assertCount(1, $form); | ||
56 | |||
57 | return array( | ||
58 | 'form' => $form->form(), | ||
59 | 'client' => $client, | ||
60 | ); | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * @depends testForgotPassword | ||
65 | */ | ||
66 | public function testSubmitForgotPasswordFail($parameters) | ||
67 | { | ||
68 | $form = $parameters['form']; | ||
69 | $client = $parameters['client']; | ||
70 | |||
71 | $data = array( | ||
72 | 'forgot_password[email]' => 'baggy', | ||
73 | ); | ||
74 | |||
75 | $client->submit($form, $data); | ||
76 | |||
77 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
78 | $this->assertContains('No user found with this email', $client->getResponse()->getContent()); | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * @depends testForgotPassword | ||
83 | * | ||
84 | * Instead of using collector which slow down the test suite | ||
85 | * http://symfony.com/doc/current/cookbook/email/testing.html | ||
86 | * | ||
87 | * Use a different way where Swift store email as file | ||
88 | */ | ||
89 | public function testSubmitForgotPassword($parameters) | ||
90 | { | ||
91 | $form = $parameters['form']; | ||
92 | $client = $parameters['client']; | ||
93 | |||
94 | $spoolDir = $client->getKernel()->getContainer()->getParameter('swiftmailer.spool.default.file.path'); | ||
95 | |||
96 | // cleanup pool dir | ||
97 | $filesystem = new Filesystem(); | ||
98 | $filesystem->remove($spoolDir); | ||
99 | |||
100 | // to use `getCollector` since `collect: false` in config_test.yml | ||
101 | $client->enableProfiler(); | ||
102 | |||
103 | $data = array( | ||
104 | 'forgot_password[email]' => 'bobby@wallabag.org', | ||
105 | ); | ||
106 | |||
107 | $client->submit($form, $data); | ||
108 | |||
109 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
110 | |||
111 | $crawler = $client->followRedirect(); | ||
112 | |||
113 | $this->assertContains('An email has been sent to', $client->getResponse()->getContent()); | ||
114 | |||
115 | // find every files (ie: emails) inside the spool dir except hidden files | ||
116 | $finder = new Finder(); | ||
117 | $finder | ||
118 | ->in($spoolDir) | ||
119 | ->ignoreDotFiles(true) | ||
120 | ->files(); | ||
121 | |||
122 | $this->assertCount(1, $finder, 'Only one email has been sent'); | ||
123 | |||
124 | foreach ($finder as $file) { | ||
125 | $message = unserialize(file_get_contents($file)); | ||
126 | |||
127 | $this->assertInstanceOf('Swift_Message', $message); | ||
128 | $this->assertEquals('Reset Password', $message->getSubject()); | ||
129 | $this->assertEquals('no-reply@wallabag.org', key($message->getFrom())); | ||
130 | $this->assertEquals('bobby@wallabag.org', key($message->getTo())); | ||
131 | $this->assertContains( | ||
132 | 'To reset your password - please visit', | ||
133 | $message->getBody() | ||
134 | ); | ||
135 | } | ||
136 | } | ||
40 | } | 137 | } |