Browse Source

Evolution #124: Du tessst et encore du test: filtre d'éléments sur page de profils.

bastien 13 years ago
parent
commit
5e86870f69

+ 1 - 8
src/Muzich/CoreBundle/Tests/Controller/FavoriteControllerTest.php View File

@@ -228,14 +228,7 @@ class FavoriteControllerTest extends FunctionalTest
228 228
     $this->connectUser('paul', 'toor');
229 229
     
230 230
     $paul = $this->getUser();
231
-    
232
-    $element_a = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
233
-      ->findOneByName('All Is Full Of Pain')
234
-    ;
235
-    $element_b = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
236
-      ->findOneByName('Heretik System Popof - Resistance')
237
-    ;
238
-    
231
+        
239 232
     $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
240 233
     $tribe_id   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
241 234
     

+ 146 - 0
src/Muzich/CoreBundle/Tests/Controller/HomeControllerTest.php View File

@@ -391,4 +391,150 @@ class HomeControllerTest extends FunctionalTest
391 391
     $this->isResponseNotFound();
392 392
   }
393 393
   
394
+  /**
395
+   * Test de la fonction ajax de récupération de plus d'éléments sur la page
396
+   * de profil
397
+   */
398
+  public function testFilterUserElements()
399
+  {
400
+    $this->client = self::createClient();
401
+    $this->connectUser('paul', 'toor');
402
+    
403
+    $paul = $this->getUser();
404
+    $bux  = $this->getUser('bux');
405
+     
406
+    $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
407
+      ->findOneByName('Hardtek')->getId();
408
+    $hardcore_id   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
409
+      ->findOneByName('Hardcore')->getId();
410
+    $electro_id   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
411
+      ->findOneByName('Electro')->getId();
412
+    $metal_id   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
413
+      ->findOneByName('Metal')->getId();
414
+    
415
+    
416
+    // Ouverture de la page favoris
417
+    $this->crawler = $this->client->request('GET', $this->generateUrl('show_user', array('slug' => $bux->getSlug())));
418
+    
419
+    // On doit voir deux elements pour paul
420
+    $this->exist('span.element_name:contains("Ed Cox - La fanfare des teuffeurs (Hardcordian)")');
421
+    $this->exist('span.element_name:contains("Babylon Pression - Des Tasers et des Pauvres")');
422
+    $this->exist('span.element_name:contains("AZYD AZYLUM Live au Café Provisoire")');
423
+    $this->exist('span.element_name:contains("SOULFLY - Prophecy")');
424
+    $this->exist('span.element_name:contains("KoinkOin - H5N1")');
425
+    $this->exist('span.element_name:contains("Antropod - Polakatek")');
426
+    $this->exist('span.element_name:contains("Dtc che passdrop")');
427
+    $this->exist('span.element_name:contains("Heretik System Popof - Resistance")');
428
+    
429
+    // Récupération de la liste avec la kekete ajax pour Tribe
430
+    $url = $this->generateUrl('show_elements_get', array(
431
+      'type'          => 'user',
432
+      'object_id'     => $bux->getId(),
433
+      'tags_ids_json' => json_encode(array($hardtek_id))
434
+    ));
435
+    $this->crawler = $this->client->request('GET', $url, array(), array(), array(
436
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
437
+    ));
438
+    
439
+    $response_content = json_decode($this->client->getResponse()->getContent(), true);
440
+    $html = $response_content['html'];
441
+    
442
+    $this->assertTrue(strpos($html, 'Ed Cox - La fanfare des teuffeurs (Hardcordian)') === false);
443
+    $this->assertTrue(strpos($html, 'Babylon Pression - Des Tasers et des Pauvres') === false);
444
+    $this->assertTrue(strpos($html, 'AZYD AZYLUM Live au Café Provisoire') === false);
445
+    $this->assertTrue(strpos($html, 'SOULFLY - Prophecy') === false);
446
+    $this->assertTrue(strpos($html, 'KoinkOin - H5N1') !== false);
447
+    $this->assertTrue(strpos($html, 'Antropod - Polakatek') !== false);
448
+    $this->assertTrue(strpos($html, 'Dtc che passdrop') !== false);
449
+    $this->assertTrue(strpos($html, 'Heretik System Popof - Resistance') !== false);
450
+    
451
+    // Récupération de la liste avec la kekete ajax pour Hardtek
452
+    $url = $this->generateUrl('show_elements_get', array(
453
+      'type'          => 'user',
454
+      'object_id'     => $bux->getId(),
455
+      'tags_ids_json' => json_encode(array($metal_id))
456
+    ));
457
+    
458
+    $this->crawler = $this->client->request('GET', $url, array(), array(), array(
459
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
460
+    ));
461
+    
462
+    $this->isResponseSuccess();
463
+    
464
+    $response_content = json_decode($this->client->getResponse()->getContent(), true);
465
+    $html = $response_content['html'];
466
+    
467
+    $this->assertTrue(strpos($html, 'Ed Cox - La fanfare des teuffeurs (Hardcordian)') === false);
468
+    $this->assertTrue(strpos($html, 'Babylon Pression - Des Tasers et des Pauvres') !== false);
469
+    $this->assertTrue(strpos($html, 'AZYD AZYLUM Live au Café Provisoire') !== false);
470
+    $this->assertTrue(strpos($html, 'SOULFLY - Prophecy') !== false);
471
+    $this->assertTrue(strpos($html, 'KoinkOin - H5N1') === false);
472
+    $this->assertTrue(strpos($html, 'Antropod - Polakatek') === false);
473
+    $this->assertTrue(strpos($html, 'Dtc che passdrop') === false);
474
+    $this->assertTrue(strpos($html, 'Heretik System Popof - Resistance') === false);
475
+    
476
+    // Récupération de la liste avec la kekete ajax pour Tribe + Hardtek
477
+    $url = $this->generateUrl('show_elements_get', array(
478
+      'type'          => 'user',
479
+      'object_id'     => $bux->getId(),
480
+      'tags_ids_json' => json_encode(array($hardtek_id, $hardcore_id, $electro_id, $metal_id))
481
+    ));
482
+    
483
+    $this->crawler = $this->client->request('GET', $url, array(), array(), array(
484
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
485
+    ));
486
+    
487
+    $this->isResponseSuccess();
488
+    
489
+    $response_content = json_decode($this->client->getResponse()->getContent(), true);
490
+    $html = $response_content['html'];
491
+    
492
+    $this->assertTrue(strpos($html, 'Ed Cox - La fanfare des teuffeurs (Hardcordian)') !== false);
493
+    $this->assertTrue(strpos($html, 'Babylon Pression - Des Tasers et des Pauvres') !== false);
494
+    $this->assertTrue(strpos($html, 'AZYD AZYLUM Live au Café Provisoire') !== false);
495
+    $this->assertTrue(strpos($html, 'SOULFLY - Prophecy') !== false);
496
+    $this->assertTrue(strpos($html, 'KoinkOin - H5N1') !== false);
497
+    $this->assertTrue(strpos($html, 'Antropod - Polakatek') !== false);
498
+    $this->assertTrue(strpos($html, 'Dtc che passdrop') !== false);
499
+    $this->assertTrue(strpos($html, 'Heretik System Popof - Resistance') !== false);
500
+  }
501
+  
502
+  /**
503
+   * Test de la fonction ajax de récupération de plus d'éléments sur la page
504
+   * de profil
505
+   */
506
+  public function testFilterGroupElements()
507
+  {
508
+    $this->client = self::createClient();
509
+    $this->connectUser('paul', 'toor');
510
+    
511
+    $paul = $this->getUser();
512
+    $group  = $this->getGroup('dudeldrum');
513
+     
514
+    $medieval_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
515
+      ->findOneByName('Medieval')->getId();
516
+    
517
+    // Ouverture de la page favoris
518
+    $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $group->getSlug())));
519
+    
520
+    // On doit voir deux elements pour paul
521
+    $this->exist('span.element_name:contains("DUDELDRUM")');
522
+    
523
+    // Récupération de la liste avec la kekete ajax pour Tribe
524
+    $url = $this->generateUrl('show_elements_get', array(
525
+      'type'          => 'group',
526
+      'object_id'     => $group->getId(),
527
+      'tags_ids_json' => json_encode(array($medieval_id))
528
+    ));
529
+    $this->crawler = $this->client->request('GET', $url, array(), array(), array(
530
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
531
+    ));
532
+    
533
+    $response_content = json_decode($this->client->getResponse()->getContent(), true);
534
+    $html = $response_content['html'];
535
+    
536
+    $this->assertTrue(strpos($html, 'DUDELDRUM') !== false);
537
+    
538
+  }
539
+  
394 540
 }

+ 30 - 4
src/Muzich/CoreBundle/lib/FunctionalTest.php View File

@@ -20,11 +20,18 @@ class FunctionalTest extends WebTestCase
20 20
    */
21 21
   protected $crawler;
22 22
   
23
-  protected function outputDebug()
23
+  protected function outputDebug($content = null)
24 24
   {
25 25
     unlink('/home/bux/.debug/out.html');
26 26
     $monfichier = fopen('/home/bux/.debug/out.html', 'a+');
27
-    fwrite($monfichier, $this->client->getResponse()->getContent());
27
+    if (!$content)
28
+    {
29
+      fwrite($monfichier, $this->client->getResponse()->getContent());
30
+    }
31
+    else
32
+    {
33
+      fwrite($monfichier, $content);
34
+    }
28 35
   }
29 36
   
30 37
   /**
@@ -32,9 +39,28 @@ class FunctionalTest extends WebTestCase
32 39
    * 
33 40
    * @return \Muzich\CoreBundle\Entity\User 
34 41
    */
35
-  protected function getUser()
42
+  protected function getUser($username = null)
43
+  {
44
+    if (!$username)
45
+    {
46
+      return $this->client->getContainer()->get('security.context')->getToken()->getUser();
47
+    }
48
+    else
49
+    {
50
+      return $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
51
+        ->findOneByUsername($username)
52
+      ;
53
+    }
54
+  }
55
+  
56
+  /**
57
+   * @return \Muzich\CoreBundle\Entity\Group
58
+   */
59
+  protected function getGroup($slug)
36 60
   {
37
-    return $this->client->getContainer()->get('security.context')->getToken()->getUser();
61
+    return $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
62
+      ->findOneBySlug($slug)->getSingleResult()
63
+    ;
38 64
   }
39 65
   
40 66
   protected function connectUser($login, $password)