소스 검색

Ecriture du test du mot de passe oublié.

bastien 13 년 전
부모
커밋
f20ce77c7a

+ 3 - 0
src/Muzich/CoreBundle/Tests/Controller/FavoriteControllerTest.php 파일 보기

@@ -12,6 +12,7 @@ class FavoriteControllerTest extends FunctionalTest
12 12
    */
13 13
   public function testMyFavorites()
14 14
   {
15
+    $this->client = self::createClient();
15 16
     $this->connectUser('bux', 'toor');
16 17
     
17 18
     // On va cliquer sur le lien 'Mes favoris'
@@ -45,6 +46,7 @@ class FavoriteControllerTest extends FunctionalTest
45 46
    */
46 47
   public function testHisFavorites()
47 48
   {
49
+    $this->client = self::createClient();
48 50
     $this->connectUser('bob', 'toor');
49 51
     
50 52
     $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
@@ -80,6 +82,7 @@ class FavoriteControllerTest extends FunctionalTest
80 82
    */
81 83
   public function testFavoritesManagement()
82 84
   {
85
+    $this->client = self::createClient();
83 86
     $this->connectUser('bob', 'toor');
84 87
     
85 88
     // On se rend sur la page du groupe Dudeldrum

+ 2 - 0
src/Muzich/CoreBundle/Tests/Controller/GroupControllerTest.php 파일 보기

@@ -12,6 +12,7 @@ class GroupControllerTest extends FunctionalTest
12 12
    */
13 13
   public function testGroupAdd()
14 14
   {
15
+    $this->client = self::createClient();
15 16
     $this->connectUser('bob', 'toor');
16 17
     
17 18
     $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
@@ -85,6 +86,7 @@ class GroupControllerTest extends FunctionalTest
85 86
    */
86 87
   public function testGroupUpdate()
87 88
   {
89
+    $this->client = self::createClient();
88 90
     $this->connectUser('bob', 'toor');
89 91
     
90 92
     $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');

+ 8 - 0
src/Muzich/CoreBundle/Tests/Controller/HomeControllerTest.php 파일 보기

@@ -13,6 +13,7 @@ class HomeControllerTest extends FunctionalTest
13 13
    */
14 14
   public function testFilter()
15 15
   {
16
+    $this->client = self::createClient();
16 17
     $this->connectUser('bux', 'toor');
17 18
 
18 19
     // Présence du formulaire d'ajout d'un élément
@@ -77,6 +78,7 @@ class HomeControllerTest extends FunctionalTest
77 78
    */
78 79
   public function testUserPage()
79 80
   {
81
+    $this->client = self::createClient();
80 82
     $this->connectUser('bux', 'toor');
81 83
     $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
82 84
       ->findOneByUsername('jean')
@@ -106,6 +108,7 @@ class HomeControllerTest extends FunctionalTest
106 108
    */
107 109
   public function testGroupPage()
108 110
   {
111
+    $this->client = self::createClient();
109 112
     $this->connectUser('bux', 'toor');
110 113
     $fdp = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
111 114
       ->findOneBySlug('fans-de-psytrance')
@@ -136,6 +139,7 @@ class HomeControllerTest extends FunctionalTest
136 139
    */
137 140
   public function testAddElementSuccess()
138 141
   {
142
+    $this->client = self::createClient();
139 143
     $this->connectUser('bux', 'toor');
140 144
     
141 145
     $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
@@ -167,6 +171,7 @@ class HomeControllerTest extends FunctionalTest
167 171
    */
168 172
   public function testAddElementFailure()
169 173
   {
174
+    $this->client = self::createClient();
170 175
     $this->connectUser('bux', 'toor');
171 176
     
172 177
     $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
@@ -287,6 +292,7 @@ class HomeControllerTest extends FunctionalTest
287 292
    */
288 293
   public function testAddElementAtMyGroupSuccess()
289 294
   {
295
+    $this->client = self::createClient();
290 296
     $this->connectUser('bux', 'toor');
291 297
     // Un groupe open, donc pas de soucis
292 298
     $fan_de_psy = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
@@ -326,6 +332,7 @@ class HomeControllerTest extends FunctionalTest
326 332
     /*
327 333
      * Ajout d'un element dans un groupe que l'on posséde.
328 334
      */
335
+    $this->client = self::createClient();
329 336
     $this->connectUser('joelle', 'toor');
330 337
     $this->isResponseSuccess();
331 338
     
@@ -365,6 +372,7 @@ class HomeControllerTest extends FunctionalTest
365 372
    */
366 373
   public function testAddElementAtGroupFailure()
367 374
   {
375
+    $this->client = self::createClient();
368 376
     $this->connectUser('bux', 'toor');
369 377
     // Un groupe no open
370 378
     $dudeldrum = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');

+ 77 - 0
src/Muzich/CoreBundle/Tests/Controller/IndexControllerTest.php 파일 보기

@@ -162,4 +162,81 @@ class IndexControllerTest extends FunctionalTest
162 162
     );
163 163
   }
164 164
   
165
+  /**
166
+   * Test du changement de mot de passe
167
+   */
168
+  public function testPasswordLost()
169
+  {
170
+    $this->client = self::createClient();
171
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
172
+    
173
+    $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bux');
174
+    
175
+    // On peux voir le lien vers al page de demande de mot de passe
176
+    $this->exist('a[href="'.($url = $this->generateUrl('fos_user_resetting_request')).'"]');
177
+    $link = $this->selectLink('a[href="'.$url.'"]');
178
+    $this->clickOnLink($link);
179
+    
180
+    $this->isResponseSuccess();
181
+    
182
+    // On trouve le formulaire
183
+    $this->exist('form[action="'.($url = $this->generateUrl('fos_user_resetting_send_email')).'"]');
184
+    $this->exist('form[action="'.$url.'"] input[id="username"]');
185
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
186
+    
187
+    // On selectionne le form
188
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
189
+    $form['username'] = 'bux';
190
+    $this->submit($form);
191
+    
192
+    $mc = $this->getMailerMessageDataCollector();
193
+    $this->assertEquals(1, $mc->getMessageCount());
194
+    
195
+    $mails = $mc->getMessages();
196
+    $mail = $mails[0];
197
+       
198
+    // $mail = new Swift_Message();
199
+    
200
+    $this->assertTrue(!is_null(strpos($mail->getBody(), ($url = $this->generateUrl(
201
+      'fos_user_resetting_reset', 
202
+      array('token' => $bux->getConfirmationToken()), 
203
+      true
204
+    )))));
205
+    
206
+    $keys = array_keys($mail->getTo());
207
+    $this->assertEquals($bux->getEmail(), $keys[0]);
208
+        
209
+    $this->isResponseRedirection();
210
+    $this->followRedirection();
211
+    $this->isResponseSuccess();
212
+    $this->exist('html:contains("'.$bux->getEmail().'")');
213
+    
214
+    // On se rend sur le lien envoyé dans le mail
215
+    $this->crawler = $this->client->request('GET', $url);
216
+    
217
+    $this->exist('form[action="'.($url = $this->generateUrl(
218
+      'fos_user_resetting_reset', 
219
+      array('token' => $bux->getConfirmationToken())
220
+    )).'"]');
221
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_resetting_form_new_first"]');
222
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_resetting_form_new_second"]');
223
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
224
+    
225
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
226
+    $form['fos_user_resetting_form[new][first]'] = 'trololo';
227
+    $form['fos_user_resetting_form[new][second]'] = 'trololo';
228
+    $this->submit($form);
229
+    
230
+    $this->isResponseRedirection();
231
+    $this->followRedirection();
232
+    $this->isResponseSuccess();
233
+    $this->outputDebug();
234
+    // A ce stade on a été connecté
235
+    $this->assertEquals('bux', $this->getUser()->getUsername());
236
+    
237
+    // On se déconnecte pour aller tester ce nouveau mot de passe
238
+    $this->disconnectUser();
239
+    $this->connectUser('bux', 'trololo');
240
+  }
241
+  
165 242
 }

+ 4 - 0
src/Muzich/CoreBundle/Tests/Controller/MynetworkControllerTest.php 파일 보기

@@ -16,6 +16,7 @@ class MynetworkControllerTest extends FunctionalTest
16 16
      * les groupes DUDELDRUM et Fans de psytrance
17 17
      * et est suivis par joelle
18 18
      */
19
+    $this->client = self::createClient();
19 20
     $this->connectUser('bux', 'toor');
20 21
     $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
21 22
     $this->clickOnLink($link);
@@ -40,6 +41,7 @@ class MynetworkControllerTest extends FunctionalTest
40 41
    */
41 42
   public function testSearch()
42 43
   {
44
+    $this->client = self::createClient();
43 45
     $this->connectUser('bux', 'toor');
44 46
     $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
45 47
     $this->clickOnLink($link);
@@ -81,6 +83,7 @@ class MynetworkControllerTest extends FunctionalTest
81 83
    */
82 84
   public function testUserFollow()
83 85
   {
86
+    $this->client = self::createClient();
84 87
     // Connection de bob
85 88
     $this->connectUser('bob', 'toor');
86 89
     
@@ -157,6 +160,7 @@ class MynetworkControllerTest extends FunctionalTest
157 160
    */
158 161
   public function testGroupFollow()
159 162
   {
163
+    $this->client = self::createClient();
160 164
     // Connection de bob
161 165
     $this->connectUser('bob', 'toor');
162 166
     

+ 25 - 3
src/Muzich/CoreBundle/lib/FunctionalTest.php 파일 보기

@@ -39,8 +39,6 @@ class FunctionalTest extends WebTestCase
39 39
   
40 40
   protected function connectUser($login, $password)
41 41
   {
42
-    $this->client = self::createClient();
43
-
44 42
     $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
45 43
     $this->isResponseSuccess();
46 44
 
@@ -64,7 +62,14 @@ class FunctionalTest extends WebTestCase
64 62
     $this->isResponseSuccess();
65 63
 
66 64
     $user = $this->getUser();
67
-    $this->assertEquals($login, $user->getUsername());
65
+    if ('anon.' != $user)
66
+    {
67
+      $this->assertEquals($login, $user->getUsername());
68
+    }
69
+    else
70
+    {
71
+      $this->assertTrue(false);
72
+    }
68 73
   }
69 74
   
70 75
   protected function disconnectUser()
@@ -98,6 +103,8 @@ class FunctionalTest extends WebTestCase
98 103
       $pass2
99 104
     );
100 105
     
106
+    
107
+    
101 108
     $this->isResponseRedirection();
102 109
     $this->followRedirection();
103 110
     $this->isResponseSuccess();
@@ -213,6 +220,21 @@ class FunctionalTest extends WebTestCase
213 220
     return $this->getContainer()->get('session');
214 221
   }
215 222
   
223
+  protected function getCollector($name)
224
+  {
225
+    return$this->client->getProfile()->getCollector($name);
226
+  }
227
+  
228
+  /**
229
+   * Retourne le MessageDataCollector en cours
230
+   * 
231
+   * @return Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector
232
+   */
233
+  protected function getMailerMessageDataCollector()
234
+  {
235
+    return $this->getCollector('swiftmailer');
236
+  }
237
+  
216 238
   protected function clickOnLink($link)
217 239
   {
218 240
     $this->crawler = $this->client->click($link);