Просмотр исходного кода

Evolution #124: Du tessst et encore du test: Mise / Retrait favoris en ajax.

bastien 13 лет назад
Родитель
Сommit
4c4e1bf821
1 измененных файлов: 53 добавлений и 0 удалений
  1. 53 0
      src/Muzich/CoreBundle/Tests/Controller/FavoriteControllerTest.php

+ 53 - 0
src/Muzich/CoreBundle/Tests/Controller/FavoriteControllerTest.php Просмотреть файл

@@ -166,4 +166,57 @@ class FavoriteControllerTest extends FunctionalTest
166 166
     $this->assertTrue(is_null($favorite));
167 167
   }
168 168
   
169
+  public function testAjax()
170
+  {
171
+    $this->client = self::createClient();
172
+    $this->connectUser('bux', 'toor');
173
+    
174
+    $bux = $this->getUser();
175
+    
176
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
177
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
178
+    ;
179
+    
180
+    // Ajout d'un élément en favoris
181
+    // Il ajoute cet élément en favoris
182
+    $url = $this->generateUrl('favorite_add', array(
183
+      'id'    => $element->getId(),
184
+      'token' => $bux->getPersonalHash()
185
+    ));
186
+    
187
+    $crawler = $this->client->request('GET', $url, array(), array(), array(
188
+        'HTTP_X-Requested-With' => 'XMLHttpRequest',
189
+    ));
190
+    
191
+    $this->isResponseSuccess();
192
+    
193
+    // On contrôle la présence du favoris
194
+    $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
195
+      ->findOneBy(array(
196
+        'user'    => $bux->getId(),
197
+        'element' => $element->getId()
198
+      ));
199
+    
200
+    $this->assertTrue(!is_null($fav));
201
+    
202
+    // On enlève des favoris
203
+    $url = $this->generateUrl('favorite_remove', array(
204
+      'id'    => $element->getId(),
205
+      'token' => $bux->getPersonalHash()
206
+    ));
207
+    
208
+    $crawler = $this->client->request('GET', $url, array(), array(), array(
209
+        'HTTP_X-Requested-With' => 'XMLHttpRequest',
210
+    ));
211
+    
212
+    // On contrôle l'absence du favoris
213
+    $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
214
+      ->findOneBy(array(
215
+        'user'    => $bux->getId(),
216
+        'element' => $element->getId()
217
+      ));
218
+    
219
+    $this->assertTrue(is_null($fav));
220
+  }
221
+  
169 222
 }