Parcourir la source

Ecriture du test du mot de passe oublié.

bastien il y a 13 ans
Parent
révision
f20ce77c7a

+ 3 - 0
src/Muzich/CoreBundle/Tests/Controller/FavoriteControllerTest.php Voir le fichier

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

+ 2 - 0
src/Muzich/CoreBundle/Tests/Controller/GroupControllerTest.php Voir le fichier

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

+ 8 - 0
src/Muzich/CoreBundle/Tests/Controller/HomeControllerTest.php Voir le fichier

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

+ 77 - 0
src/Muzich/CoreBundle/Tests/Controller/IndexControllerTest.php Voir le fichier

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 Voir le fichier

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

+ 25 - 3
src/Muzich/CoreBundle/lib/FunctionalTest.php Voir le fichier

39
   
39
   
40
   protected function connectUser($login, $password)
40
   protected function connectUser($login, $password)
41
   {
41
   {
42
-    $this->client = self::createClient();
43
-
44
     $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
42
     $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
45
     $this->isResponseSuccess();
43
     $this->isResponseSuccess();
46
 
44
 
64
     $this->isResponseSuccess();
62
     $this->isResponseSuccess();
65
 
63
 
66
     $user = $this->getUser();
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
   protected function disconnectUser()
75
   protected function disconnectUser()
98
       $pass2
103
       $pass2
99
     );
104
     );
100
     
105
     
106
+    
107
+    
101
     $this->isResponseRedirection();
108
     $this->isResponseRedirection();
102
     $this->followRedirection();
109
     $this->followRedirection();
103
     $this->isResponseSuccess();
110
     $this->isResponseSuccess();
213
     return $this->getContainer()->get('session');
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
   protected function clickOnLink($link)
238
   protected function clickOnLink($link)
217
   {
239
   {
218
     $this->crawler = $this->client->click($link);
240
     $this->crawler = $this->client->click($link);