|
@@ -734,5 +734,122 @@ class HomeControllerTest extends FunctionalTest
|
734
|
734
|
|
735
|
735
|
}
|
736
|
736
|
|
|
737
|
+ public function testAddedElementToGroup()
|
|
738
|
+ {
|
|
739
|
+ $this->client = self::createClient();
|
|
740
|
+ $this->connectUser('bob', 'toor');
|
|
741
|
+ // bob administre le groupe fans de psytrance
|
|
742
|
+ $bob = $this->getUser();
|
|
743
|
+
|
|
744
|
+ $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
|
|
745
|
+ $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
|
|
746
|
+ $psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Psytrance');
|
|
747
|
+
|
|
748
|
+ $fan_de_psy = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
|
|
749
|
+
|
|
750
|
+ // On envoie d'abord un élément sans tags associé
|
|
751
|
+ // On ne devra pas avoir de proposition de groupe
|
|
752
|
+ $url = $this->generateUrl('element_add');
|
|
753
|
+
|
|
754
|
+ $extract = $this->crawler->filter('input[name="element_add[_token]"]')
|
|
755
|
+ ->extract(array('value'));
|
|
756
|
+ $csrf = $extract[0];
|
|
757
|
+
|
|
758
|
+ $crawler = $this->client->request(
|
|
759
|
+ 'POST',
|
|
760
|
+ $url,
|
|
761
|
+ array(
|
|
762
|
+ 'element_add' => array(
|
|
763
|
+ '_token' => $csrf,
|
|
764
|
+ 'name' => 'Musique 1976824673',
|
|
765
|
+ 'url' => 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
766
|
+ 'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
|
|
767
|
+ )
|
|
768
|
+
|
|
769
|
+ ),
|
|
770
|
+ array(),
|
|
771
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
772
|
+ );
|
|
773
|
+
|
|
774
|
+ $this->isResponseSuccess();
|
|
775
|
+
|
|
776
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
777
|
+ $this->assertEquals($response['status'], 'success');
|
|
778
|
+ $this->assertEquals($response['groups'], array());
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
782
|
+ ->findOneByName('Musique 1976824673')
|
|
783
|
+ ;
|
|
784
|
+ $this->assertTrue(!is_null($element));
|
|
785
|
+
|
|
786
|
+ // Maintenant on ajout un élément qui a comme tag psytrance
|
|
787
|
+ $url = $this->generateUrl('element_add');
|
|
788
|
+
|
|
789
|
+ $extract = $this->crawler->filter('input[name="element_add[_token]"]')
|
|
790
|
+ ->extract(array('value'));
|
|
791
|
+ $csrf = $extract[0];
|
|
792
|
+
|
|
793
|
+ $crawler = $this->client->request(
|
|
794
|
+ 'POST',
|
|
795
|
+ $url,
|
|
796
|
+ array(
|
|
797
|
+ 'element_add' => array(
|
|
798
|
+ '_token' => $csrf,
|
|
799
|
+ 'name' => 'Musique 4gbz65g4afa',
|
|
800
|
+ 'url' => 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
801
|
+ 'tags' => json_encode(array($psytrance->getId()))
|
|
802
|
+ )
|
|
803
|
+
|
|
804
|
+ ),
|
|
805
|
+ array(),
|
|
806
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
807
|
+ );
|
|
808
|
+
|
|
809
|
+ $this->isResponseSuccess();
|
|
810
|
+
|
|
811
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
812
|
+ ->findOneByName('Musique 4gbz65g4afa')
|
|
813
|
+ ;
|
|
814
|
+ $this->assertTrue(!is_null($element));
|
|
815
|
+
|
|
816
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
817
|
+
|
|
818
|
+ $this->assertEquals($response['status'], 'success');
|
|
819
|
+ $this->assertEquals($response['groups'], array(
|
|
820
|
+ array(
|
|
821
|
+ 'name' => $fan_de_psy->getName(),
|
|
822
|
+ 'id' => $fan_de_psy->getId(),
|
|
823
|
+ 'url' => $this->generateUrl('ajax_set_element_group', array(
|
|
824
|
+ 'token' => $this->getUser()->getPersonalHash(),
|
|
825
|
+ 'element_id' => $element->getId(),
|
|
826
|
+ 'group_id' => $fan_de_psy->getId()
|
|
827
|
+ ))
|
|
828
|
+ )
|
|
829
|
+ ));
|
|
830
|
+
|
|
831
|
+ // Du coup on effectue la diffusion de l'élément dans le groupe
|
|
832
|
+ $crawler = $this->client->request(
|
|
833
|
+ 'POST',
|
|
834
|
+ $this->generateUrl('ajax_set_element_group', array(
|
|
835
|
+ 'element_id' => $element->getId(),
|
|
836
|
+ 'group_id' => $fan_de_psy->getId(),
|
|
837
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
838
|
+ )),
|
|
839
|
+ array(),
|
|
840
|
+ array(),
|
|
841
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
842
|
+ );
|
|
843
|
+
|
|
844
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
845
|
+ ->findOneBy(array(
|
|
846
|
+ 'name' => 'Musique 4gbz65g4afa',
|
|
847
|
+ 'group' => $fan_de_psy->getId()
|
|
848
|
+ ))
|
|
849
|
+ ;
|
|
850
|
+ $this->assertTrue(!is_null($element));
|
|
851
|
+
|
|
852
|
+ }
|
|
853
|
+
|
737
|
854
|
|
738
|
855
|
}
|