Ver código fonte

tests pour event user follow

bastien 12 anos atrás
pai
commit
11f7516a2a

+ 87 - 0
src/Muzich/CoreBundle/Tests/Controller/EventTest.php Ver arquivo

@@ -656,4 +656,91 @@ class EventTest extends FunctionalTest
656 656
     $this->assertEquals($result[0]['ids'], json_encode(array((string)$element->getId())));
657 657
   }
658 658
   
659
+  public function testFollowEvent()
660
+  {
661
+    $this->client = self::createClient();
662
+    $this->connectUser('bux', 'toor');
663
+    
664
+    $bux = $this->getUser();
665
+    $bob = $this->getUser('bob');
666
+    
667
+    // Actuellement il n'y a aucun event d'ouvert pour paul (fixtures)
668
+    $result = $this->getDoctrine()->getEntityManager()
669
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
670
+        WHERE e.user = :uid'
671
+      )
672
+      ->setParameter('uid', $bob->getId())
673
+      ->getArrayResult()
674
+    ;
675
+    $this->assertEquals(count($result), 0);
676
+    
677
+    // On tente de récupérer l'entité FollowUser
678
+    $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
679
+      ->findOneBy(array(
680
+        'follower' => $bux->getId(),
681
+        'followed' => $bob->getId()
682
+      ))
683
+    ;
684
+    
685
+    // Mais celle-ci doit-être innexistante
686
+    $this->assertTrue(is_null($FollowUser));
687
+    
688
+    // On va suivre bob
689
+    $url_follow = $this->generateUrl('follow', array(
690
+      'type' => 'user', 
691
+      'id' => $bob->getId(),
692
+      'token' => $bux->getPersonalHash()
693
+    ));
694
+    
695
+    $this->crawler = $this->client->request('GET', $url_follow);
696
+    
697
+    $this->isResponseRedirection();
698
+    $this->followRedirection();
699
+    $this->isResponseSuccess();
700
+    
701
+    // Désormais bob doit avoir un event
702
+    $result = $this->getDoctrine()->getEntityManager()
703
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
704
+        WHERE e.user = :uid AND e.type = :type'
705
+      )
706
+      ->setParameters(array(
707
+        'uid' => $bob->getId(),
708
+        'type' => Event::TYPE_USER_FOLLOW
709
+      ))
710
+      ->getArrayResult()
711
+    ;
712
+    $this->assertEquals(count($result), 1);
713
+    $this->assertEquals($result[0]['type'], Event::TYPE_USER_FOLLOW);
714
+    $this->assertEquals($result[0]['count'], 1);
715
+    $this->assertEquals($result[0]['ids'], json_encode(array((string)$bux->getId())));
716
+    
717
+    // On va se connecter avec bob
718
+    $this->disconnectUser();
719
+    $this->connectUser('bob', 'toor');
720
+    
721
+    // bob doit pouvoir voir dans la barre de droite l'event
722
+    $this->exist('div#events div.follows a span.new_follows:contains("1")');
723
+    
724
+    // Il y a d'ailleurs un lien pour les afficher
725
+    $url = $this->generateUrl('mynetwork_index', array('event_id' => $result[0]['id']));
726
+    $this->exist('div#events div.follows a[href="'.$url.'"]');
727
+    
728
+    // On se rend sur ce lien
729
+    $this->crawler = $this->client->request('GET', $url);
730
+    $this->isResponseSuccess();
731
+    
732
+    // On peux voir le lien vers bux en class 'new'
733
+    $this->exist('ul#followers_users li.new:contains(\'bux\')');
734
+    
735
+    // L'event n'existe d'ailleurs plus en base
736
+    $result = $this->getDoctrine()->getEntityManager()
737
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
738
+        WHERE e.user = :uid'
739
+      )
740
+      ->setParameter('uid', $bob->getId())
741
+      ->getArrayResult()
742
+    ;
743
+    $this->assertEquals(count($result), 0);
744
+  }
745
+  
659 746
 }

+ 3 - 3
src/Muzich/UserBundle/Resources/views/Info/bar.html.twig Ver arquivo

@@ -48,14 +48,14 @@
48 48
           <a 
49 49
             href="{{ path('mynetwork_index', {'event_id':events[event_const('TYPE_USER_FOLLOW')].id}) }}" 
50 50
             title="{%if events[event_const('TYPE_USER_FOLLOW')].count == 1 %}{{ 'events.new_follows.one'|trans({'%count%':1}, 'users') }}{% else %}{{ 'events.new_follows.yes'|trans({'%count%':events[event_const('TYPE_USER_FOLLOW')].count}, 'users') }}{% endif %}"
51
-            class="view_elements_event"
51
+            class="view_follows_event"
52 52
           >
53 53
             <img src="{{ asset('bundles/muzichcore/img/1333474994_people.png') }}" alt="favoriteds" />
54
-            <span class="new_comments">{{ events[event_const('TYPE_USER_FOLLOW')].count }}</span>
54
+            <span class="new_follows">{{ events[event_const('TYPE_USER_FOLLOW')].count }}</span>
55 55
           </a>
56 56
         {% else %}
57 57
           <img title="{{ 'events.new_follows.no'|trans({}, 'users') }}" src="{{ asset('bundles/muzichcore/img/1333474994_people.png') }}" alt="favoriteds" />
58
-          <span class="new_comments">0</span>
58
+          <span class="new_follows">0</span>
59 59
         {% endif %}
60 60
           
61 61
     </div>