Browse Source

Playlists tests: + update order

Bastien Sevajol 11 years ago
parent
commit
4ea96b7a3e

+ 45 - 0
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php View File

6
 use Muzich\CoreBundle\Tests\lib\Security\Context as SecurityContextTest;
6
 use Muzich\CoreBundle\Tests\lib\Security\Context as SecurityContextTest;
7
 use Muzich\CoreBundle\Security\Context as SecurityContext;
7
 use Muzich\CoreBundle\Security\Context as SecurityContext;
8
 use Muzich\CoreBundle\Tests\lib\Security\ContextTestCases;
8
 use Muzich\CoreBundle\Tests\lib\Security\ContextTestCases;
9
+use Muzich\CoreBundle\lib\Collection\ElementCollectionManager;
9
 
10
 
10
 class PlaylistControllerTest extends FunctionalTest
11
 class PlaylistControllerTest extends FunctionalTest
11
 {
12
 {
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 View File

267
   
267
   
268
   public function playlistUpdateOrderResponseIs($success, $condition)
268
   public function playlistUpdateOrderResponseIs($success, $condition)
269
   {
269
   {
270
+    $this->playlistUpdateOrder(0, array());
270
     return $this->ajaxResponseSatisfyConditions(
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
       $success, 
273
       $success, 
279
       $condition
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
   public function playlistRemoveElementResponseIs($success, $condition)
298
   public function playlistRemoveElementResponseIs($success, $condition)
284
   {
299
   {
285
     return $this->ajaxResponseSatisfyConditions(
300
     return $this->ajaxResponseSatisfyConditions(

+ 0 - 2
src/Muzich/CoreBundle/lib/Collection/ElementCollectionManager.php View File

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