瀏覽代碼

Playlists tests: + update order

Bastien Sevajol 11 年之前
父節點
當前提交
4ea96b7a3e

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

@@ -6,6 +6,7 @@ use Muzich\CoreBundle\lib\FunctionalTest;
6 6
 use Muzich\CoreBundle\Tests\lib\Security\Context as SecurityContextTest;
7 7
 use Muzich\CoreBundle\Security\Context as SecurityContext;
8 8
 use Muzich\CoreBundle\Tests\lib\Security\ContextTestCases;
9
+use Muzich\CoreBundle\lib\Collection\ElementCollectionManager;
9 10
 
10 11
 class PlaylistControllerTest extends FunctionalTest
11 12
 {
@@ -269,4 +270,48 @@ class PlaylistControllerTest extends FunctionalTest
269 270
     }
270 271
   }
271 272
   
273
+  public function testUpdateOrder()
274
+  {
275
+    $this->init();
276
+    $this->initOrderContextData();
277
+    $this->connectUser('bux', 'toor');
278
+    
279
+    $this->checkPlaylistOrder($this->playlists['bux_2_priv'], array(
280
+      $this->elements['heretik'], $this->elements['fab']
281
+    ));
282
+    $this->updatePlaylistOrder($this->playlists['bux_2_priv'], array(
283
+      $this->elements['fab'], $this->elements['heretik']
284
+    ));
285
+    $this->playlists['bux_2_priv'] = $this->findOneBy('Playlist', 'Ma playlist perso');
286
+    $this->checkPlaylistOrder($this->playlists['bux_2_priv'], array(
287
+      $this->elements['fab'], $this->elements['heretik']
288
+    ));
289
+  }
290
+  
291
+  protected function initOrderContextData()
292
+  {
293
+    $this->initReadContextData();
294
+    $this->elements['heretik'] = $this->findOneBy('Element', 'Heretik System Popof - Resistance');
295
+    $this->elements['fab'] = $this->findOneBy('Element', 'DJ FAB');
296
+  }
297
+  
298
+  protected function checkPlaylistOrder($playlist, $elements)
299
+  {
300
+    $collection_manager = new ElementCollectionManager(array());
301
+    
302
+    foreach ($elements as $element)
303
+    {
304
+      $collection_manager->add($element);
305
+    }
306
+    
307
+    $this->assertEquals($collection_manager->getContent(), $playlist->getelements());
308
+  }
309
+  
310
+  protected function updatePlaylistOrder($playlist, $elements)
311
+  {
312
+    $response = $this->tests_cases->playlistUpdateOrder($playlist->getId(), $elements);
313
+    $this->outputDebug();
314
+    $this->jsonResponseIsSuccess($response);
315
+  }
316
+  
272 317
 }

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

@@ -267,19 +267,34 @@ class ContextTestCases
267 267
   
268 268
   public function playlistUpdateOrderResponseIs($success, $condition)
269 269
   {
270
+    $this->playlistUpdateOrder(0, array());
270 271
     return $this->ajaxResponseSatisfyConditions(
271
-      $this->getAjaxRequestContentResponse(
272
-        'GET',
273
-        $this->test->generateUrl('playlist_update_order', array(
274
-          'playlist_id' => 0,
275
-          '_locale'     => 'fr'
276
-        ))
277
-      ), 
272
+      $this->test->getClient()->getResponse()->getContent(), 
278 273
       $success, 
279 274
       $condition
280 275
     );
281 276
   }
282 277
   
278
+  public function playlistUpdateOrder($playlist_id, $elements)
279
+  {
280
+    $elements_ids = array();
281
+    foreach ($elements as $element)
282
+    {
283
+      $elements_ids[] = $element->getId();
284
+    }
285
+    
286
+    return $this->getAjaxRequestContentResponse(
287
+      'GET',
288
+      $this->test->generateUrl('playlist_update_order', array(
289
+        'playlist_id' => $playlist_id,
290
+        '_locale'     => 'fr'
291
+      )),
292
+      array(
293
+        'elements' => $elements_ids
294
+      )
295
+    );
296
+  }
297
+  
283 298
   public function playlistRemoveElementResponseIs($success, $condition)
284 299
   {
285 300
     return $this->ajaxResponseSatisfyConditions(

+ 0 - 2
src/Muzich/CoreBundle/lib/Collection/ElementCollectionManager.php 查看文件

@@ -2,8 +2,6 @@
2 2
 
3 3
 namespace Muzich\CoreBundle\lib\Collection;
4 4
 
5
-use Muzich\CoreBundle\Entity\Element;
6
-
7 5
 class ElementCollectionManager extends CollectionManager
8 6
 {
9 7