瀏覽代碼

Playlists tests: add and remove element

Bastien Sevajol 11 年之前
父節點
當前提交
0bfe1dddbf

+ 54 - 0
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php 查看文件

@@ -314,4 +314,58 @@ class PlaylistControllerTest extends FunctionalTest
314 314
     $this->jsonResponseIsSuccess($response);
315 315
   }
316 316
   
317
+  public function testAddAndRemoveElement()
318
+  {
319
+    $this->init();
320
+    $this->initAddRemoveContextData();
321
+    $this->connectUser('bux', 'toor');
322
+    
323
+    $this->tests_cases->playlistShow($this->users['bux']->getSlug(), $this->playlists['bux_2_priv']->getId());
324
+    $this->checkReadPlaylist($this->playlists['bux_2_priv'],
325
+      array($this->playlists['bux_2_priv']->getId() => array(
326
+        $this->elements['heretik'],
327
+        $this->elements['fab']
328
+      ))
329
+    );
330
+    
331
+    $this->addElementToPlaylist($this->playlists['bux_2_priv'], $this->elements['azyd']);
332
+    
333
+    $this->tests_cases->playlistShow($this->users['bux']->getSlug(), $this->playlists['bux_2_priv']->getId());
334
+    $this->checkReadPlaylist($this->playlists['bux_2_priv'],
335
+      array($this->playlists['bux_2_priv']->getId() => array(
336
+        $this->elements['heretik'],
337
+        $this->elements['fab'],
338
+        $this->elements['azyd']
339
+      ))
340
+    );
341
+    
342
+    $this->removeElementFromPlaylist($this->playlists['bux_2_priv'], $this->elements['fab']);
343
+    
344
+    $this->tests_cases->playlistShow($this->users['bux']->getSlug(), $this->playlists['bux_2_priv']->getId());
345
+    $this->checkReadPlaylist($this->playlists['bux_2_priv'],
346
+      array($this->playlists['bux_2_priv']->getId() => array(
347
+        $this->elements['heretik'],
348
+        $this->elements['azyd']
349
+      ))
350
+    );
351
+  }
352
+  
353
+  protected function initAddRemoveContextData()
354
+  {
355
+    $this->initOrderContextData();
356
+    $this->elements['heretik'] = $this->findOneBy('Element', 'Heretik System Popof - Resistance');
357
+    $this->elements['fab'] = $this->findOneBy('Element', 'DJ FAB');
358
+    $this->elements['azyd'] = $this->findOneBy('Element', 'AZYD AZYLUM Live au Café Provisoire'); 
359
+  }
360
+  
361
+  protected function addElementToPlaylist($playlist, $element)
362
+  {
363
+    $this->tests_cases->playlistAddElement($playlist->getId(), $element->getId());
364
+  }
365
+  
366
+  protected function removeElementFromPlaylist($playlist, $element)
367
+  {
368
+    $this->tests_cases->playlistremoveElement($playlist->getId(), $element->getId());
369
+  }
370
+  
317 371
 }

+ 28 - 16
src/Muzich/CoreBundle/Tests/lib/Security/ContextTestCases.php 查看文件

@@ -251,20 +251,26 @@ class ContextTestCases
251 251
   
252 252
   public function playlistAddElementResponseIs($success, $condition)
253 253
   {
254
+    $this->playlistAddElement(0, 0);
254 255
     return $this->ajaxResponseSatisfyConditions(
255
-      $this->getAjaxRequestContentResponse(
256
-        'GET',
257
-        $this->test->generateUrl('playlists_add_element', array(
258
-          'playlist_id' => 0,
259
-          'element_id'  => 0,
260
-          '_locale'     => 'fr'
261
-        ))
262
-      ), 
256
+      $this->test->getClient()->getResponse()->getContent(), 
263 257
       $success, 
264 258
       $condition
265 259
     );
266 260
   }
267 261
   
262
+  public function playlistAddElement($playlist_id, $element_id)
263
+  {
264
+    return $this->getAjaxRequestContentResponse(
265
+      'GET',
266
+      $this->test->generateUrl('playlists_add_element', array(
267
+        'playlist_id' => $playlist_id,
268
+        'element_id'  => $element_id,
269
+        '_locale'     => 'fr'
270
+      ))
271
+    );
272
+  }
273
+  
268 274
   public function playlistUpdateOrderResponseIs($success, $condition)
269 275
   {
270 276
     $this->playlistUpdateOrder(0, array());
@@ -297,20 +303,26 @@ class ContextTestCases
297 303
   
298 304
   public function playlistRemoveElementResponseIs($success, $condition)
299 305
   {
306
+    $this->playlistRemoveElement(0, 0);
300 307
     return $this->ajaxResponseSatisfyConditions(
301
-      $this->getAjaxRequestContentResponse(
302
-        'GET',
303
-        $this->test->generateUrl('playlist_remove_element', array(
304
-          'playlist_id' => 0,
305
-          'element_id'  => 0,
306
-          '_locale'     => 'fr'
307
-        ))
308
-      ), 
308
+      $this->test->getClient()->getResponse()->getContent(),
309 309
       $success, 
310 310
       $condition
311 311
     );
312 312
   }
313 313
   
314
+  public function playlistRemoveElement($playlist_id, $element_id)
315
+  {
316
+    return $this->getAjaxRequestContentResponse(
317
+      'GET',
318
+      $this->test->generateUrl('playlist_remove_element', array(
319
+        'playlist_id' => $playlist_id,
320
+        'element_id'  => $element_id,
321
+        '_locale'     => 'fr'
322
+      ))
323
+    );
324
+  }
325
+  
314 326
   public function playlistCreateResponseIs($success, $condition)
315 327
   {
316 328
     $this->playlistCreate(0, 'my_super_playlist');