Browse Source

Ecriture de tests pour la page Mon compte

bastien 13 years ago
parent
commit
93c0028f9e

+ 1 - 1
src/Muzich/CoreBundle/Tests/Controller/IndexControllerTest.php View File

@@ -230,7 +230,7 @@ class IndexControllerTest extends FunctionalTest
230 230
     $this->isResponseRedirection();
231 231
     $this->followRedirection();
232 232
     $this->isResponseSuccess();
233
-    $this->outputDebug();
233
+    
234 234
     // A ce stade on a été connecté
235 235
     $this->assertEquals('bux', $this->getUser()->getUsername());
236 236
     

+ 103 - 0
src/Muzich/CoreBundle/Tests/Controller/UserControllerTest.php View File

@@ -72,4 +72,107 @@ class UserControllerTest extends FunctionalTest
72 72
     ;
73 73
     $this->assertEquals(1, count($Favorites));
74 74
   }
75
+  
76
+  /**
77
+   * Test du changement de mot de passe par le baisis de la page 'Mon compte'
78
+   */
79
+  public function testChangePassword()
80
+  {
81
+    $this->client = self::createClient();
82
+    $this->connectUser('bux', 'toor');
83
+    
84
+    // Ouverture de la page Mon compte
85
+    $this->crawler = $this->client->request('GET', $this->generateUrl('my_account'));
86
+    
87
+    $this->exist('form[action="'.($url = $this->generateUrl(
88
+      'change_password'
89
+    )).'"]');
90
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_change_password_form_current"]');
91
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_change_password_form_new_first"]');
92
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_change_password_form_new_second"]');
93
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
94
+    
95
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
96
+    $form['fos_user_change_password_form[current]'] = 'toor';
97
+    $form['fos_user_change_password_form[new][first]'] = 'trololo';
98
+    $form['fos_user_change_password_form[new][second]'] = 'trololo';
99
+    $this->submit($form);
100
+    
101
+    $this->isResponseRedirection();
102
+    $this->followRedirection();
103
+    $this->isResponseSuccess();
104
+    
105
+    // On se déconnecte
106
+    $this->disconnectUser();
107
+    
108
+    // Et on se connecte avec le nouveau mot de passe
109
+    $this->connectUser('bux', 'trololo');
110
+  }
111
+  
112
+  /**
113
+   * Test du formulaire de mise a jour des tags par le baisis de la page 'Mon compte'
114
+   */
115
+  public function testUpdateFavoriteTags()
116
+  {
117
+    $this->client = self::createClient();
118
+    $this->connectUser('bob', 'toor');
119
+    
120
+    // Ouverture de la page Mon compte
121
+    $this->crawler = $this->client->request('GET', $this->generateUrl('my_account'));
122
+    
123
+    $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
124
+    $tribe_id   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
125
+    
126
+    // Bob n'a aucun tag préféré
127
+    $prefereds = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
128
+      ->findBy(array('user' => $this->getUser()->getId()))
129
+    ;
130
+    
131
+    $this->assertEquals(0, count($prefereds));
132
+    
133
+    $this->exist('form[action="'.($url = $this->generateUrl(
134
+      'update_tag_favorites', array('redirect' => 'account')
135
+    )).'"]');
136
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
137
+    
138
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
139
+    $form['tag_favorites_form[tags]['.$hardtek_id.']'] = $hardtek_id;
140
+    $form['tag_favorites_form[tags]['.$tribe_id.']'] = $tribe_id;
141
+    $this->submit($form);
142
+    
143
+    $this->isResponseRedirection();
144
+    $this->followRedirection();
145
+    $this->isResponseSuccess();
146
+    
147
+    // On a été redirigé sur la page Mon compte
148
+    $this->exist('form[action="'.$url.'"]');
149
+    
150
+    // On vérifie la présence en base des enregistrements
151
+    $prefereds = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
152
+      ->findBy(array('user' => $this->getUser()->getId()))
153
+    ;
154
+    
155
+    $this->assertEquals(2, count($prefereds));
156
+    
157
+    // On vérifie la présence en base des enregistrements
158
+    $prefereds = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
159
+      ->findBy(array(
160
+          'user' => $this->getUser()->getId(),
161
+          'tag'  => $hardtek_id
162
+      ))
163
+    ;
164
+    
165
+    $this->assertEquals(1, count($prefereds));
166
+    
167
+    // On vérifie la présence en base des enregistrements
168
+    $prefereds = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
169
+      ->findBy(array(
170
+          'user' => $this->getUser()->getId(),
171
+          'tag'  => $tribe_id
172
+      ))
173
+    ;
174
+    
175
+    $this->assertEquals(1, count($prefereds));
176
+  }
177
+  
75 178
 }

+ 13 - 0
src/Muzich/UserBundle/Controller/UserController.php View File

@@ -74,6 +74,19 @@ class UserController extends Controller
74 74
   public function changePasswordAction()
75 75
   {
76 76
     $user = $this->getUser();
77
+    
78
+    /**
79
+     * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
80
+     * Docrine le voit si on faire une requete directe.
81
+     */
82
+    if ($this->container->getParameter('env') == 'test')
83
+    {
84
+      $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
85
+        $this->container->get('security.context')->getToken()->getUser()->getId(),
86
+        array()
87
+      )->getSingleResult();
88
+    }
89
+    
77 90
     if (!is_object($user) || !$user instanceof UserInterface) {
78 91
         throw new AccessDeniedException('This user does not have access to this section.');
79 92
     }