Quellcode durchsuchen

Evolution #788: Ajouter un élément a sa playlist

Bastien Sevajol vor 11 Jahren
Ursprung
Commit
764c830192

+ 61 - 3
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php Datei anzeigen

@@ -7,6 +7,7 @@ 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 9
 use Muzich\CoreBundle\lib\Collection\ElementCollectionManager;
10
+use Muzich\CoreBundle\Entity\Playlist;
10 11
 
11 12
 class PlaylistControllerTest extends FunctionalTest
12 13
 {
@@ -156,12 +157,22 @@ class PlaylistControllerTest extends FunctionalTest
156 157
     }
157 158
   }
158 159
   
159
-  protected function checkPlaylistElements($playlist, $elements)
160
+  protected function checkPlaylistElements(Playlist $playlist, $elements, $exists = true, $check_count = true)
160 161
   {
161
-    $this->assertEquals(count($elements), $this->crawler->filter('li.playlist_element')->count());
162
+    $this->goToPage($this->generateUrl('playlist', array(
163
+      'playlist_id' => $playlist->getId(),
164
+      'user_slug'   => $playlist->getOwner()->getSlug()
165
+    )));
166
+    
167
+    if ($check_count)
168
+      $this->assertEquals(count($elements), $this->crawler->filter('li.playlist_element')->count());
169
+    
162 170
     foreach ($elements as $element)
163 171
     {
164
-      $this->exist('a[data-id="'.$element->getId().'"]');
172
+      if ($exists)
173
+        $this->exist('a[data-id="'.$element->getId().'"]');
174
+      if (!$exists)
175
+        $this->notExist('a[data-id="'.$element->getId().'"]');
165 176
     }
166 177
   }
167 178
   
@@ -517,4 +528,51 @@ class PlaylistControllerTest extends FunctionalTest
517 528
     $this->assertTrue(!is_null($playlist_in_database));
518 529
   }
519 530
   
531
+  public function testAddPrivateLinks()
532
+  {
533
+    $this->init();
534
+    $this->initReadContextData();
535
+    $this->connectUser('bux', 'toor');
536
+    
537
+    $this->goToPage($this->generateUrl('playlist', array('user_slug' => $this->users['bux']->getSlug(), 'playlist_id' => $this->playlists['bux_1_pub']->getId())));
538
+    $this->exist('div.private_links form');
539
+    $this->exist('a.open_playlist_private_links');
540
+    
541
+    $this->addSomePrivateLinks($this->playlists['bux_1_pub'], $private_links = array(
542
+      'https://soundcloud.com/st-tetik/read-only-memories-g-noush',
543
+      'https://soundcloud.com/triby/triby-extrait-next-liveset',
544
+      'http://blog.bux.fr'
545
+    ));
546
+    $elements = $this->checkElementExistanceAndPresenceInPlaylistWithUrls($private_links, $this->playlists['bux_1_pub']);
547
+    
548
+    $this->checkPlaylistElements($this->playlists['bux_1_pub'], $elements, true, false);
549
+    
550
+    $this->disconnectUser();
551
+    $this->connectUser('paul', 'toor');
552
+    
553
+    $this->checkPlaylistElements($this->playlists['bux_1_pub'], $elements, false, false);
554
+  }
555
+  
556
+  protected function addSomePrivateLinks(Playlist $playlist, $links)
557
+  {
558
+    $this->tests_cases->playlistAddPrivateLinks($playlist, $links);
559
+    $this->isResponseRedirection();
560
+  }
561
+  
562
+  protected function checkElementExistanceAndPresenceInPlaylistWithUrls($urls_to_check, Playlist $playlist)
563
+  {
564
+    $elements = array();
565
+    foreach ($urls_to_check as $url_to_check)
566
+    {
567
+      $element_to_check = $this->findOneBy('Element', array('url' => $url_to_check));
568
+      $this->assertTrue(!is_null($element_to_check));
569
+      $elements[] = $element_to_check;
570
+      $playlist_to_check = $this->findOneBy('Playlist', array('id' => $playlist->getId()));
571
+      $this->assertTrue(!is_null($playlist_to_check));
572
+      $this->assertTrue($playlist_to_check->haveElement($element_to_check));
573
+    }
574
+    
575
+    return $elements;
576
+  }
577
+  
520 578
 }

+ 0 - 6
src/Muzich/CoreBundle/Tests/Controller/ScoreTest.php Datei anzeigen

@@ -104,12 +104,6 @@ class ScoreTest extends FunctionalTest
104 104
     $this->disconnectUser();
105 105
   }
106 106
   
107
-  protected function stringResponseIsSuccess($response_string)
108
-  {
109
-    $response_array = json_decode($response_string, true);
110
-    $this->assertEquals('success', $response_array['status']);
111
-  }
112
-  
113 107
   protected function checkRemoveVoteGood()
114 108
   {
115 109
     $this->connectUser('paul');

+ 16 - 3
src/Muzich/CoreBundle/Tests/lib/Security/ContextTestCases.php Datei anzeigen

@@ -419,10 +419,7 @@ class ContextTestCases
419 419
   
420 420
   public function playlistDeleteResponseIs($success, $condition)
421 421
   {
422
-    
423
-    
424 422
     $this->playlistDelete(0);
425
-    
426 423
     return $this->responseSatisfyConditions(
427 424
       $this->test->getClient()->getResponse(), 
428 425
       $success, 
@@ -559,6 +556,22 @@ class ContextTestCases
559 556
     );
560 557
   }
561 558
   
559
+  public function playlistAddPrivateLinks(Playlist $playlist, $links)
560
+  {
561
+    return $this->getAjaxRequestContentResponse(
562
+      'POST',
563
+      $this->test->generateUrl('playlist_add_private_links', array(
564
+        'playlist_id' => $playlist->getId(),
565
+        '_token'     => $this->test->getToken()
566
+      )),
567
+      array(
568
+        'playlist_private_links_form' => array(
569
+          'links' => implode("\n", $links)
570
+        )
571
+      )
572
+    );
573
+  }
574
+  
562 575
   public function elementAddGoodPoint(Element $element, User $user)
563 576
   {
564 577
     return $this->getAjaxRequestContentResponse(

+ 6 - 0
src/Muzich/CoreBundle/lib/FunctionalTest.php Datei anzeigen

@@ -598,4 +598,10 @@ class FunctionalTest extends WebTestCase
598 598
     return $propositions[0];
599 599
   }
600 600
   
601
+  protected function stringResponseIsSuccess($response_string)
602
+  {
603
+    $response_array = json_decode($response_string, true);
604
+    $this->assertEquals('success', $response_array['status']);
605
+  }
606
+  
601 607
 }