Parcourir la source

Playlists tests: pick and unpick

Bastien Sevajol il y a 11 ans
Parent
révision
abedb8711d

+ 11 - 8
src/Muzich/CoreBundle/Repository/PlaylistRepository.php Voir le fichier

@@ -51,17 +51,20 @@ class PlaylistRepository extends EntityRepository
51 51
   }
52 52
   
53 53
   public function getUserPublicPlaylistsOrOwnedOrPickedQueryBuilder(User $viewed_user, User $current_user = null)
54
-  {
55
-    if (!$current_user)
54
+  {    
55
+    if ($current_user)
56 56
     {
57
-      return $this->getUserPublicPlaylistsOrOwnedQueryBuilder($viewed_user, $current_user);
57
+      if ($viewed_user->getId() == $current_user->getId())
58
+      {
59
+        return $this->getUserPublicPlaylistsOrOwnedQueryBuilder($viewed_user, $current_user)
60
+          ->leftJoin('p.user_playlists_pickeds', 'pickers')
61
+          ->orWhere('pickers.user = :picker_id')
62
+          ->setParameter('picker_id', $current_user->getId())
63
+        ;
64
+      }
58 65
     }
59 66
     
60
-    return $this->getUserPublicPlaylistsOrOwnedQueryBuilder($viewed_user, $current_user)
61
-      ->leftJoin('p.user_playlists_pickeds', 'pickers')
62
-      ->orWhere('pickers.user = :picker_id')
63
-      ->setParameter('picker_id', $current_user->getId())
64
-    ;
67
+    return $this->getUserPublicPlaylistsOrOwnedQueryBuilder($viewed_user, $current_user);
65 68
   }
66 69
   
67 70
   public function findOnePlaylistOwned($playlist_id, User $user)

+ 28 - 0
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php Voir le fichier

@@ -432,4 +432,32 @@ class PlaylistControllerTest extends FunctionalTest
432 432
     $this->isResponseSuccess();
433 433
   }
434 434
   
435
+  public function testPickAndUnpick()
436
+  {
437
+    $this->init();
438
+    $this->initReadContextData();
439
+    $this->users['jean'] = $this->findUserByUsername('jean');
440
+    $this->connectUser('jean', 'toor');
441
+    
442
+    $this->checkReadPlaylists($this->users['jean'], array());
443
+    $this->pickPlaylist($this->playlists['bob_pub']);
444
+    $this->checkReadPlaylists($this->users['jean'], array($this->playlists['bob_pub']));
445
+    $this->unPickPlaylist($this->playlists['bob_pub']);
446
+    $this->checkReadPlaylists($this->users['jean'], array());
447
+  }
448
+  
449
+  protected function pickPlaylist($playlist)
450
+  {
451
+    $response = $this->tests_cases->playlistPick($playlist->getId());
452
+    $this->jsonResponseIsSuccess($response);
453
+  }
454
+  
455
+  protected function unPickPlaylist($playlist)
456
+  {
457
+    $this->tests_cases->playlistUnPick($playlist->getId());
458
+    $this->isResponseRedirection();
459
+    $this->followRedirection();
460
+    $this->isResponseSuccess();
461
+  }
462
+  
435 463
 }

+ 26 - 16
src/Muzich/CoreBundle/Tests/lib/Security/ContextTestCases.php Voir le fichier

@@ -420,34 +420,44 @@ class ContextTestCases
420 420
   
421 421
   public function playlistUnpickResponseIs($success, $condition)
422 422
   {
423
-    return $this->ajaxResponseSatisfyConditions(
424
-      $this->getAjaxRequestContentResponse(
425
-        'GET',
426
-        $this->test->generateUrl('playlist_unpick', array(
427
-          'playlist_id' => 0,
428
-          '_locale'     => 'fr'
429
-        ))
430
-      ), 
423
+    $this->playlistUnPick(0);
424
+    return $this->responseSatisfyConditions(
425
+      $this->test->getClient()->getResponse(), 
431 426
       $success, 
432
-      $condition
427
+      $condition, 
428
+      $this->test->getUser()
433 429
     );
434 430
   }
435 431
   
432
+  public function playlistUnPick($playlist_id)
433
+  {
434
+    $this->test->goToPage($this->test->generateUrl('playlist_unpick', array(
435
+      'playlist_id' => $playlist_id,
436
+      '_locale'     => 'fr'
437
+    )));
438
+  }
439
+  
436 440
   public function playlistPickResponseIs($success, $condition)
437 441
   {
442
+    $this->playlistPick(0);
438 443
     return $this->ajaxResponseSatisfyConditions(
439
-      $this->getAjaxRequestContentResponse(
440
-        'GET',
441
-        $this->test->generateUrl('playlist_pick', array(
442
-          'playlist_id' => 0,
443
-          '_locale'     => 'fr'
444
-        ))
445
-      ), 
444
+      $this->test->getClient()->getResponse()->getContent(), 
446 445
       $success, 
447 446
       $condition
448 447
     );
449 448
   }
450 449
   
450
+  public function playlistPick($playlist_id)
451
+  {
452
+    return $this->getAjaxRequestContentResponse(
453
+      'GET',
454
+      $this->test->generateUrl('playlist_pick', array(
455
+        'playlist_id' => $playlist_id,
456
+        '_locale'     => 'fr'
457
+      ))
458
+    );
459
+  }
460
+  
451 461
   public function playlistShowResponseIs($success, $condition)
452 462
   {
453 463
     $this->playlistShow('bux', 0);

+ 1 - 1
src/Muzich/PlaylistBundle/Controller/EditController.php Voir le fichier

@@ -114,7 +114,7 @@ class EditController extends Controller
114 114
   public function unpickAction($playlist_id)
115 115
   {
116 116
     if (($uncondition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_PLAYLIST_UNPICK)) !== false)
117
-      return $this->jsonResponseError($uncondition);
117
+      throw $this->createNotFoundException();
118 118
     
119 119
     $playlist_manager = $this->getPlaylistManager();
120 120