|
@@ -788,4 +788,165 @@ class EventTest extends FunctionalTest
|
788
|
788
|
$this->assertEquals(count($result), 0);
|
789
|
789
|
}
|
790
|
790
|
|
|
791
|
+ public function testElementTagsPropositions()
|
|
792
|
+ {
|
|
793
|
+ $this->client = self::createClient();
|
|
794
|
+ $this->connectUser('bux', 'toor');
|
|
795
|
+
|
|
796
|
+ $paul = $this->getUser('paul');
|
|
797
|
+ $bux = $this->getUser('bux');
|
|
798
|
+
|
|
799
|
+ $element_1 = $this->findOneBy('Element', 'Infected Mushroom - Psycho');
|
|
800
|
+ $element_2 = $this->findOneBy('Element', 'CardioT3K - Juggernaut Trap ');
|
|
801
|
+ $tag_1 = $this->findOneBy('Tag', 'Metal');
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+ $this->eventCount($paul, Event::TYPE_TAGS_PROPOSED, 0);
|
|
805
|
+ $this->proposeElementTags($element_1, $bux, array($tag_1->getId()));
|
|
806
|
+ $this->eventCount($paul, Event::TYPE_TAGS_PROPOSED, 1);
|
|
807
|
+ $this->eventHasElementId($paul, Event::TYPE_TAGS_PROPOSED, $element_1->getId());
|
|
808
|
+
|
|
809
|
+ $this->proposeElementTags($element_2, $bux, array($tag_1->getId()));
|
|
810
|
+ $this->eventCount($paul, Event::TYPE_TAGS_PROPOSED, 1);
|
|
811
|
+ $this->eventHasElementId($paul, Event::TYPE_TAGS_PROPOSED, $element_1->getId());
|
|
812
|
+ $event = $this->eventHasElementId($paul, Event::TYPE_TAGS_PROPOSED, $element_2->getId());
|
|
813
|
+
|
|
814
|
+ $this->disconnectUser();
|
|
815
|
+ $this->connectUser('paul', 'toor');
|
|
816
|
+ $this->acceptTagProposition($paul, $this->getElementTagProposition($element_1->getId(), $bux->getId())->getId());
|
|
817
|
+ $this->eventCount($paul, Event::TYPE_TAGS_PROPOSED, 1);
|
|
818
|
+ $this->eventHasNotElementId($paul, Event::TYPE_TAGS_PROPOSED, $element_1->getId());
|
|
819
|
+ $this->eventHasElementId($paul, Event::TYPE_TAGS_PROPOSED, $element_2->getId());
|
|
820
|
+ $this->refuseTagProposition($paul, $element_2->getId());
|
|
821
|
+ $this->eventCount($paul, Event::TYPE_TAGS_PROPOSED, 0);
|
|
822
|
+ }
|
|
823
|
+
|
|
824
|
+ protected function eventCount($user, $type, $count)
|
|
825
|
+ {
|
|
826
|
+ $events = $this->getDoctrine()->getEntityManager()
|
|
827
|
+ ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
|
|
828
|
+ WHERE e.user = :uid AND e.type = :type'
|
|
829
|
+ )
|
|
830
|
+ ->setParameters(array(
|
|
831
|
+ 'uid' => $user->getId(),
|
|
832
|
+ 'type' => $type
|
|
833
|
+ ))
|
|
834
|
+ ->getArrayResult()
|
|
835
|
+ ;
|
|
836
|
+ $this->assertEquals(count($events), $count);
|
|
837
|
+ }
|
|
838
|
+
|
|
839
|
+ protected function proposeElementTags($element, $user, $tags_ids)
|
|
840
|
+ {
|
|
841
|
+ $crawler = $this->client->request(
|
|
842
|
+ 'POST',
|
|
843
|
+ $this->generateUrl('ajax_element_propose_tags_proceed',
|
|
844
|
+ array('element_id' => $element->getId(), 'token' => $user->getPersonalHash())
|
|
845
|
+ ),
|
|
846
|
+ array(
|
|
847
|
+ 'element_tag_proposition_'.$element->getId() => array(
|
|
848
|
+ 'tags' => json_encode($tags_ids)
|
|
849
|
+ )
|
|
850
|
+ ),
|
|
851
|
+ array(),
|
|
852
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
853
|
+ );
|
|
854
|
+
|
|
855
|
+ $this->isResponseSuccess();
|
|
856
|
+
|
|
857
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
858
|
+ $this->assertEquals($response['status'], 'success');
|
|
859
|
+ }
|
|
860
|
+
|
|
861
|
+ protected function eventHasElementId($user, $type, $element_id)
|
|
862
|
+ {
|
|
863
|
+ $events = $this->getDoctrine()->getEntityManager()
|
|
864
|
+ ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
|
|
865
|
+ WHERE e.user = :uid AND e.type = :type AND e.ids LIKE :eid'
|
|
866
|
+ )
|
|
867
|
+ ->setParameters(array(
|
|
868
|
+ 'uid' => $user->getId(),
|
|
869
|
+ 'type' => $type,
|
|
870
|
+ 'eid' => '%"'.$element_id.'"%'
|
|
871
|
+ ))
|
|
872
|
+ ->getArrayResult()
|
|
873
|
+ ;
|
|
874
|
+ $this->assertEquals(count($events), 1);
|
|
875
|
+ return $events[0];
|
|
876
|
+ }
|
|
877
|
+
|
|
878
|
+ protected function eventHasNotElementId($user, $type, $element_id)
|
|
879
|
+ {
|
|
880
|
+ $events = $this->getDoctrine()->getEntityManager()
|
|
881
|
+ ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
|
|
882
|
+ WHERE e.user = :uid AND e.type = :type AND e.ids LIKE :eid'
|
|
883
|
+ )
|
|
884
|
+ ->setParameters(array(
|
|
885
|
+ 'uid' => $user->getId(),
|
|
886
|
+ 'type' => $type,
|
|
887
|
+ 'eid' => '%"'.$element_id.'"%'
|
|
888
|
+ ))
|
|
889
|
+ ->getArrayResult()
|
|
890
|
+ ;
|
|
891
|
+ $this->assertEquals(count($events), 0);
|
|
892
|
+ }
|
|
893
|
+
|
|
894
|
+ protected function acceptTagProposition($user, $proposition_id)
|
|
895
|
+ {
|
|
896
|
+ $crawler = $this->client->request(
|
|
897
|
+ 'POST',
|
|
898
|
+ $this->generateUrl('ajax_element_proposed_tags_accept',
|
|
899
|
+ array(
|
|
900
|
+ 'proposition_id' => $proposition_id,
|
|
901
|
+ 'token' => $user->getPersonalHash()
|
|
902
|
+ )
|
|
903
|
+ ),
|
|
904
|
+ array(),
|
|
905
|
+ array(),
|
|
906
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
907
|
+ );
|
|
908
|
+
|
|
909
|
+ $this->isResponseSuccess();
|
|
910
|
+
|
|
911
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
912
|
+ $this->assertEquals($response['status'], 'success');
|
|
913
|
+ }
|
|
914
|
+
|
|
915
|
+ protected function refuseTagProposition($user, $element_id)
|
|
916
|
+ {
|
|
917
|
+ $crawler = $this->client->request(
|
|
918
|
+ 'POST',
|
|
919
|
+ $this->generateUrl('ajax_element_proposed_tags_refuse',
|
|
920
|
+ array(
|
|
921
|
+ 'element_id' => $element_id,
|
|
922
|
+ 'token' => $user->getPersonalHash()
|
|
923
|
+ )
|
|
924
|
+ ),
|
|
925
|
+ array(),
|
|
926
|
+ array(),
|
|
927
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
928
|
+ );
|
|
929
|
+
|
|
930
|
+ $this->isResponseSuccess();
|
|
931
|
+
|
|
932
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
933
|
+ $this->assertEquals($response['status'], 'success');
|
|
934
|
+ }
|
|
935
|
+
|
|
936
|
+ protected function getElementTagProposition($element_id, $user_id)
|
|
937
|
+ {
|
|
938
|
+ $propositions = $this->getDoctrine()->getEntityManager()
|
|
939
|
+ ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
|
|
940
|
+ .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
|
|
941
|
+ ->setParameters(array(
|
|
942
|
+ 'eid' => $element_id,
|
|
943
|
+ 'uid' => $user_id
|
|
944
|
+ ))
|
|
945
|
+ ->getResult();
|
|
946
|
+ if (count($propositions))
|
|
947
|
+ {
|
|
948
|
+ return $propositions[0];
|
|
949
|
+ }
|
|
950
|
+ }
|
|
951
|
+
|
791
|
952
|
}
|