|
@@ -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
|
}
|