Pārlūkot izejas kodu

Playlists: tests fonctionnels:

Bastien Sevajol 11 gadus atpakaļ
vecāks
revīzija
a332449e47

+ 60 - 0
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php Parādīt failu

@@ -209,4 +209,64 @@ class PlaylistControllerTest extends FunctionalTest
209 209
     return $playlist;
210 210
   }
211 211
   
212
+  public function testAutoplayDatas()
213
+  {
214
+    $this->init();
215
+    $this->initReadContextData();
216
+    
217
+    $this->checkPublicPlaylist();
218
+    $this->checkPrivatePlaylist();
219
+    $this->connectUser('bob', 'toor');
220
+    $this->checkPublicPlaylist();
221
+    $this->checkPrivatePlaylist();
222
+    $this->disconnectUser();
223
+    $this->connectUser('bux', 'toor');
224
+    $this->checkPublicPlaylist();
225
+    $this->checkPrivatePlaylist(true);
226
+  }
227
+  
228
+  protected function checkPublicPlaylist()
229
+  {
230
+    $response = $this->tests_cases->playlistAutoplay($this->playlists['bux_1_pub']->getId());
231
+    $this->jsonResponseIsSuccess($response);
232
+  }
233
+  
234
+  protected function checkPrivatePlaylist($success = false)
235
+  {
236
+    $response = $this->tests_cases->playlistAutoplay($this->playlists['bux_2_priv']->getId());
237
+    
238
+    if (!$success)
239
+      $this->jsonResponseIsError($response);
240
+    if ($success)
241
+      $this->jsonResponseIsSuccess($response);
242
+  }
243
+  
244
+  public function testPrompt()
245
+  {
246
+    $this->init();
247
+    $this->initCreateContextData();
248
+    
249
+    $this->setCrawlerWithJsonResponseData($this->tests_cases->playlistPrompt($this->elements['babylon']->getId()));
250
+    $this->checkPlaylistsInPrompt(array());
251
+    
252
+    $this->connectUser('bux', 'toor');
253
+    
254
+    $this->setCrawlerWithJsonResponseData($this->tests_cases->playlistPrompt($this->elements['babylon']->getId()));
255
+    
256
+    $this->checkPlaylistsInPrompt(array(
257
+      $this->playlists['bux_1_pub'],
258
+      $this->playlists['bux_2_priv'],
259
+      $this->playlists['bob_pub'],
260
+    ));
261
+  }
262
+  
263
+  protected function checkPlaylistsInPrompt($playlists)
264
+  {
265
+    $this->assertEquals(count($playlists), $this->crawler->filter('ul.playlists_for_element li.playlist')->count());
266
+    foreach ($playlists as $playlist)
267
+    {
268
+      $this->exist('a:contains("'.$playlist->getName().'")');
269
+    }
270
+  }
271
+  
212 272
 }

+ 26 - 14
src/Muzich/CoreBundle/Tests/lib/Security/ContextTestCases.php Parādīt failu

@@ -437,32 +437,44 @@ class ContextTestCases
437 437
   
438 438
   public function playlistAutoplayResponseIs($success, $condition)
439 439
   {
440
+    $this->playlistAutoplay(0);
440 441
     return $this->ajaxResponseSatisfyConditions(
441
-      $this->getAjaxRequestContentResponse(
442
-        'GET',
443
-        $this->test->generateUrl('playlist_datas_for_autoplay', array(
444
-          'playlist_id' => 0,
445
-          '_locale'     => 'fr'
446
-        ))
447
-      ), 
442
+      $this->test->getClient()->getResponse()->getContent(),
448 443
       $success, 
449 444
       $condition
450 445
     );
451 446
   }
452 447
   
448
+  public function playlistAutoplay($playlist_id)
449
+  {
450
+    return $this->getAjaxRequestContentResponse(
451
+      'GET',
452
+      $this->test->generateUrl('playlist_datas_for_autoplay', array(
453
+        'playlist_id' => $playlist_id,
454
+        '_locale'     => 'fr'
455
+      ))
456
+    );
457
+  }
458
+  
453 459
   public function playlistPromptResponseIs($success, $condition)
454 460
   {
461
+    $this->playlistPrompt(0);
455 462
     return $this->ajaxResponseSatisfyConditions(
456
-      $this->getAjaxRequestContentResponse(
457
-        'GET',
458
-        $this->test->generateUrl('playlists_add_element_prompt', array(
459
-          'element_id' => 0,
460
-          '_locale'    => 'fr'
461
-        ))
462
-      ), 
463
+      $this->test->getClient()->getResponse()->getContent(),
463 464
       $success, 
464 465
       $condition
465 466
     );
466 467
   }
467 468
   
469
+  public function playlistPrompt($element_id)
470
+  {
471
+    return $this->getAjaxRequestContentResponse(
472
+      'GET',
473
+      $this->test->generateUrl('playlists_add_element_prompt', array(
474
+        'element_id' => $element_id,
475
+        '_locale'    => 'fr'
476
+      ))
477
+    );
478
+  }
479
+  
468 480
 }

+ 20 - 0
src/Muzich/CoreBundle/lib/FunctionalTest.php Parādīt failu

@@ -548,4 +548,24 @@ class FunctionalTest extends WebTestCase
548 548
     $this->crawler = $this->client->request('GET', $url);
549 549
   }
550 550
   
551
+  public function jsonResponseIsSuccess($json_response)
552
+  {
553
+    $response = json_decode($json_response, true);
554
+    $this->assertTrue(array_key_exists('status', $response));
555
+    $this->assertEquals('success', $response['status']);
556
+  }
557
+  
558
+  public function jsonResponseIsError($json_response)
559
+  {
560
+    $response = json_decode($json_response, true);
561
+    $this->assertTrue(array_key_exists('status', $response));
562
+    $this->assertEquals('error', $response['status']);
563
+  }
564
+  
565
+  public function setCrawlerWithJsonResponseData($json_response)
566
+  {
567
+    $response = json_decode($json_response, true);
568
+    $this->crawler = new Crawler($response['data']);
569
+  }
570
+  
551 571
 }

+ 1 - 1
src/Muzich/PlaylistBundle/Controller/ShowController.php Parādīt failu

@@ -47,7 +47,7 @@ class ShowController extends Controller
47 47
     
48 48
     $playlist_manager = $this->getPlaylistManager();
49 49
     if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUserOrNullIfVisitor())))
50
-      throw $this->createNotFoundException();
50
+      return $this->jsonNotFoundResponse();
51 51
     
52 52
     $autoplaym = new AutoplayManager($playlist_manager->getPlaylistElements($playlist, $offset), $this->container);
53 53
     

+ 3 - 3
src/Muzich/PlaylistBundle/Resources/views/Show/prompt.html.twig Parādīt failu

@@ -5,11 +5,11 @@
5 5
   </form>
6 6
 </div>
7 7
 
8
-<div class="playlists_for_element">
8
+<div>
9 9
   {% if playlists|length %}
10
-    <ul>
10
+    <ul class="playlists_for_element">
11 11
       {% for playlist in playlists %}
12
-        <li>
12
+        <li class="playlist">
13 13
           <a class="add_element_to_playlist"
14 14
             {% if playlist.owned(app.user) %}
15 15
               href="{{ path('playlists_add_element', {