ソースを参照

Playlists tests: copys when delete or add element on picked playlist

Bastien Sevajol 11 年 前
コミット
08d7968ca4

+ 13 - 0
src/Muzich/CoreBundle/Entity/Playlist.php ファイルの表示

@@ -131,6 +131,19 @@ class Playlist
131 131
     return $users;
132 132
   }
133 133
   
134
+  public function havePickerUser(User $user)
135
+  {
136
+    foreach ($this->getPickedsUsers() as $user_picker)
137
+    {
138
+      if ($user_picker->getId() == $user->getId())
139
+      {
140
+        return true;
141
+      }
142
+    }
143
+    
144
+    return false;
145
+  }
146
+  
134 147
   public function setUserPlaylistsPickeds(Collection $user_playlists_pickeds = null)
135 148
   {
136 149
     $this->user_playlists_pickeds = $user_playlists_pickeds;

+ 65 - 1
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php ファイルの表示

@@ -310,7 +310,6 @@ class PlaylistControllerTest extends FunctionalTest
310 310
   protected function updatePlaylistOrder($playlist, $elements)
311 311
   {
312 312
     $response = $this->tests_cases->playlistUpdateOrder($playlist->getId(), $elements);
313
-    $this->outputDebug();
314 313
     $this->jsonResponseIsSuccess($response);
315 314
   }
316 315
   
@@ -368,4 +367,69 @@ class PlaylistControllerTest extends FunctionalTest
368 367
     $this->tests_cases->playlistremoveElement($playlist->getId(), $element->getId());
369 368
   }
370 369
   
370
+  public function testCopyWhenAddingElementToPickedPlaylist()
371
+  {
372
+    $this->init();
373
+    $this->initCopysContextData();
374
+    $this->connectUser('bux', 'toor');
375
+    
376
+    $this->checkPlaylistPickedBy($this->playlists['bob_pub'], $this->users['bux']);
377
+    $this->addElementAndCopyPlaylist($this->playlists['bob_pub'], $this->elements['azyd']);
378
+    $this->playlists['bux_bob_pub'] = $this->findOneBy('Playlist', array(
379
+      'name' => 'A travers l\'espace',
380
+      'owner' => $this->users['bux']->getId()
381
+    ));
382
+    $this->assertTrue(!is_null($this->playlists['bux_bob_pub']));
383
+    $this->checkPlaylistOwnedBy($this->playlists['bux_bob_pub'], $this->users['bux']);
384
+  }
385
+  
386
+  protected function initCopysContextData()
387
+  {
388
+    $this->initReadContextData();
389
+    $this->elements['azyd'] = $this->findOneBy('Element', 'AZYD AZYLUM Live au Café Provisoire'); 
390
+  }
391
+  
392
+  protected function checkPlaylistPickedBy($playlist, $user)
393
+  {
394
+    $this->assertTrue($playlist->havePickerUser($user));
395
+  }
396
+  
397
+  protected function addElementAndCopyPlaylist($playlist, $element)
398
+  {
399
+    $response = $this->tests_cases->playlistAddElementAndCopy($playlist->getId(), $element->getId());
400
+    $this->jsonResponseIsSuccess($response);
401
+  }
402
+  
403
+  protected function checkPlaylistOwnedBy($playlist, $user)
404
+  {
405
+    $this->assertEquals($playlist->getOwner()->getId(), $user->getId());
406
+  }
407
+  
408
+  protected function checkPlaylistNotOwnedBy($playlist, $user)
409
+  {
410
+    $this->assertNotEquals($playlist->getOwner()->getId(), $user->getId());
411
+  }
412
+  
413
+  public function testCopyWhenPickedPlaylistDeleted()
414
+  {
415
+    $this->init();
416
+    $this->initCopysContextData();
417
+    $this->connectUser('bob', 'toor');
418
+    
419
+    $this->checkPlaylistPickedBy($this->playlists['bob_pub'], $this->users['bux']);
420
+    $this->checkPlaylistNotOwnedBy($this->playlists['bob_pub'], $this->users['bux']);
421
+    $this->deletePlaylist($this->playlists['bob_pub']);
422
+    $this->playlists['bux_bob_pub'] = $this->findOneBy('Playlist', array('name' => 'A travers l\'espace'));
423
+    $this->assertTrue(!is_null($this->playlists['bux_bob_pub']));
424
+    $this->checkPlaylistOwnedBy($this->playlists['bux_bob_pub'], $this->users['bux']);
425
+  }
426
+  
427
+  protected function deletePlaylist($playlist)
428
+  {
429
+    $this->tests_cases->playlistDelete($playlist->getId());
430
+    $this->isResponseRedirection();
431
+    $this->followRedirection();
432
+    $this->isResponseSuccess();
433
+  }
434
+  
371 435
 }

+ 24 - 9
src/Muzich/CoreBundle/Tests/lib/Security/ContextTestCases.php ファイルの表示

@@ -323,6 +323,18 @@ class ContextTestCases
323 323
     );
324 324
   }
325 325
   
326
+  public function playlistAddElementAndCopy($playlist_id, $element_id)
327
+  {
328
+    return $this->getAjaxRequestContentResponse(
329
+      'GET',
330
+      $this->test->generateUrl('playlists_add_element_and_copy', array(
331
+        'playlist_id' => $playlist_id,
332
+        'element_id'  => $element_id,
333
+        '_locale'     => 'fr'
334
+      ))
335
+    );
336
+  }
337
+  
326 338
   public function playlistCreateResponseIs($success, $condition)
327 339
   {
328 340
     $this->playlistCreate(0, 'my_super_playlist');
@@ -383,24 +395,27 @@ class ContextTestCases
383 395
   
384 396
   public function playlistDeleteResponseIs($success, $condition)
385 397
   {
398
+    $this->playlistDelete(0);
399
+    return $this->responseSatisfyConditions(
400
+      $this->test->getClient()->getResponse(), 
401
+      $success, 
402
+      $condition, 
403
+      $this->test->getUser()
404
+    );
405
+  }
406
+  
407
+  public function playlistDelete($playlist_id)
408
+  {
386 409
     $this->test->getClient()->request(
387 410
       'GET', 
388 411
       $this->test->generateUrl('playlist_delete', array(
389
-          'playlist_id' => 0,
390
-          'element_id'  => 0,
412
+          'playlist_id' => $playlist_id,
391 413
           '_locale'     => 'fr'
392 414
         )), 
393 415
       array(), 
394 416
       array(), 
395 417
       array()
396 418
     );
397
-    
398
-    return $this->responseSatisfyConditions(
399
-      $this->test->getClient()->getResponse(), 
400
-      $success, 
401
-      $condition, 
402
-      $this->test->getUser()
403
-    );
404 419
   }
405 420
   
406 421
   public function playlistUnpickResponseIs($success, $condition)