ソースを参照

Ecriture de tests pour la procédure compléte de proposition de tags sur élément.

bastien 12 年 前
コミット
b638f9f8dc
共有2 個のファイルを変更した734 個の追加1 個の削除を含む
  1. 14 1
      src/Muzich/CoreBundle/Controller/ElementController.php
  2. 720 0
      src/Muzich/CoreBundle/Tests/Controller/ElementControllerTest.php

+ 14 - 1
src/Muzich/CoreBundle/Controller/ElementController.php ファイルの表示

@@ -582,9 +582,22 @@ class ElementController extends Controller
582 582
       ));
583 583
     }
584 584
     
585
+    /**
586
+     * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
587
+     * Docrine le voit si on faire une requete directe.
588
+     */
589
+    $user = $this->getUser();
590
+    if ($this->container->getParameter('env') == 'test')
591
+    {
592
+      $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
593
+        $this->container->get('security.context')->getToken()->getUser()->getId(),
594
+        array()
595
+      )->getSingleResult();
596
+    }
597
+    
585 598
     $proposition = new ElementTagsProposition();
586 599
     $proposition->setElement($element);
587
-    $proposition->setUser($this->getUser());
600
+    $proposition->setUser($user);
588 601
     $date = new \DateTime(date('Y-m-d H:i:s'));
589 602
     $proposition->setCreated($date);
590 603
     

+ 720 - 0
src/Muzich/CoreBundle/Tests/Controller/ElementControllerTest.php ファイルの表示

@@ -607,4 +607,724 @@ class ElementControllerTest extends FunctionalTest
607 607
     $this->assertEquals($bux->getReputation(), 23);
608 608
   }
609 609
   
610
+  /**
611
+   * Test des procédure concernants al proposition de tags sur un élément
612
+   * 
613
+   * On test ici: 
614
+   * * Proposition de tags
615
+   * * La consultation de ces propositions
616
+   * * L'acceptation
617
+   */
618
+  public function testTagsPropositionAccept()
619
+  {
620
+    $this->client = self::createClient();
621
+    $this->connectUser('paul', 'toor');
622
+    
623
+    $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
624
+    $tribe   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
625
+    $tsouzoumi = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tsouzoumi');
626
+    $soug = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Soug');
627
+    $metal = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Metal');
628
+    
629
+    $paul = $this->getUser();
630
+    $bux = $this->getUser('bux');
631
+    $joelle = $this->getUser('joelle');
632
+    
633
+    $points_pour_tags_add = $this->getContainer()->getParameter('reputation_element_tags_element_prop_value');
634
+    $points_joelle = $joelle->getReputation();
635
+    $points_bux    = $bux->getReputation();
636
+    $points_paul  = $paul->getReputation();
637
+    
638
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
639
+      ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
640
+    ;
641
+    
642
+    // Pas de proposition en base pur cet élément
643
+    $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
644
+      ->findOneByElement($element->getId())
645
+    ;
646
+    
647
+    $this->assertEquals(0, count($propositions));
648
+    
649
+    // Pas d'événement pour bux
650
+    $events = $this->getDoctrine()->getEntityManager()
651
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
652
+        WHERE e.user = :uid AND e.type = :type'
653
+      )
654
+      ->setParameters(array(
655
+        'uid' => $bux->getId(),
656
+        'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
657
+      ))
658
+      ->getArrayResult()
659
+    ;
660
+    $this->assertEquals(count($events), 0);
661
+    
662
+    // On teste la récupération du formulaire au moin une fois
663
+    $crawler = $this->client->request(
664
+      'GET',
665
+      $this->generateUrl('ajax_element_propose_tags_open', 
666
+        array('element_id' => $element->getId())
667
+      ), 
668
+      array(), 
669
+      array(), 
670
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
671
+    );
672
+    
673
+    $this->isResponseSuccess();
674
+    
675
+    $response = json_decode($this->client->getResponse()->getContent(), true);
676
+    $this->assertEquals($response['status'], 'success');
677
+    $this->assertEquals($response['form_name'], 'element_tag_proposition_'.$element->getId());
678
+    $this->assertTrue(strpos($response['html'], 'class="tag_proposition"') !== false);
679
+    
680
+    // paul propose une serie de tags
681
+    $crawler = $this->client->request(
682
+      'POST', 
683
+      $this->generateUrl('ajax_element_propose_tags_proceed', 
684
+        array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
685
+      ), 
686
+      array(
687
+        'element_tag_proposition_'.$element->getId() => array(
688
+          'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
689
+        )
690
+      ), 
691
+      array(), 
692
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
693
+    );
694
+    
695
+    $this->isResponseSuccess();
696
+    
697
+    $response = json_decode($this->client->getResponse()->getContent(), true);
698
+    $this->assertEquals($response['status'], 'success');
699
+    
700
+    // On a maintenant la proposition en base
701
+    $propositions = $this->getDoctrine()->getEntityManager()
702
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
703
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
704
+      ->setParameters(array(
705
+        'eid' => $element->getId(),
706
+        'uid'    => $paul->getId()
707
+      ))
708
+      ->getResult()
709
+    ;
710
+    
711
+    $this->assertEquals(1, count($propositions));
712
+    $proposition_paul = $propositions[0];
713
+    
714
+    // Les tags sont aussi en base
715
+    foreach ($propositions[0]->getTags() as $tag)
716
+    {
717
+      if (in_array($tag->getId(), array($hardtek->getId(), $tribe->getId())))
718
+      {
719
+        $this->assertTrue(true);
720
+      }
721
+      else
722
+      {
723
+        $this->assertTrue(false);
724
+      }
725
+    }
726
+    
727
+    // Il y a maintenant un event pour bux
728
+    $events = $this->getDoctrine()->getEntityManager()
729
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
730
+        WHERE e.user = :uid AND e.type = :type'
731
+      )
732
+      ->setParameters(array(
733
+        'uid' => $bux->getId(),
734
+        'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
735
+      ))
736
+      ->getArrayResult()
737
+    ;
738
+    $this->assertEquals(count($events), 1);
739
+    $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
740
+    // 
741
+    $this->assertEquals($events[0]['count'], 1);
742
+    $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
743
+    
744
+    // si il propose un liste vide de tags, c'est refusé bien entendu
745
+    $crawler = $this->client->request(
746
+      'POST', 
747
+      $this->generateUrl('ajax_element_propose_tags_proceed', 
748
+        array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
749
+      ), 
750
+      array(
751
+        'element_tag_proposition_'.$element->getId() => array(
752
+          'tags' => json_encode(array())
753
+        )
754
+      ), 
755
+      array(), 
756
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
757
+    );
758
+    
759
+    $this->isResponseSuccess();
760
+    
761
+    $response = json_decode($this->client->getResponse()->getContent(), true);
762
+    $this->assertEquals($response['status'], 'error');
763
+    
764
+    /*
765
+     *  joelle va aussi proposer des tags sur cet élément
766
+     */
767
+    $this->disconnectUser();
768
+    $this->connectUser('joelle', 'toor');
769
+    
770
+    $joelle = $this->getUser();
771
+    
772
+    // joelle propose une serie de tags
773
+    $crawler = $this->client->request(
774
+      'POST', 
775
+      $this->generateUrl('ajax_element_propose_tags_proceed', 
776
+        array('element_id' => $element->getId(), 'token' => $joelle->getPersonalHash())
777
+      ), 
778
+      array(
779
+        'element_tag_proposition_'.$element->getId() => array(
780
+          'tags' => json_encode(array($tsouzoumi->getId(), $soug->getId(), $metal->getId()))
781
+        )
782
+      ), 
783
+      array(), 
784
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
785
+    );
786
+    
787
+    $this->isResponseSuccess();
788
+    
789
+    $response = json_decode($this->client->getResponse()->getContent(), true);
790
+    $this->assertEquals($response['status'], 'success');
791
+    
792
+    // On a maintenant la proposition en base
793
+    $propositions = $this->getDoctrine()->getEntityManager()
794
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
795
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
796
+      ->setParameters(array(
797
+        'eid' => $element->getId(),
798
+        'uid'    => $joelle->getId()
799
+      ))
800
+      ->getResult()
801
+    ;
802
+    
803
+    $this->assertEquals(1, count($propositions));
804
+    $proposition_joelle = $propositions[0];
805
+    
806
+    // Les tags sont aussi en base
807
+    foreach ($propositions[0]->getTags() as $tag)
808
+    {
809
+      if (in_array($tag->getId(), array($tsouzoumi->getId(), $soug->getId(), $metal->getId())))
810
+      {
811
+        $this->assertTrue(true);
812
+      }
813
+      else
814
+      {
815
+        $this->assertTrue(false);
816
+      }
817
+    }
818
+    
819
+    // avec la propsoition de joelle le nombre d'event n'a pas bougé (le compteur compte les éléments)
820
+    $events = $this->getDoctrine()->getEntityManager()
821
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
822
+        WHERE e.user = :uid AND e.type = :type'
823
+      )
824
+      ->setParameters(array(
825
+        'uid' => $bux->getId(),
826
+        'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
827
+      ))
828
+      ->getArrayResult()
829
+    ;
830
+    $this->assertEquals(count($events), 1);
831
+    $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
832
+    // 
833
+    $this->assertEquals($events[0]['count'], 1);
834
+    $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
835
+    
836
+    /*
837
+     *  C'est au tour de bux d'aller voir ces proposition
838
+     */
839
+    
840
+    $this->disconnectUser();
841
+    $this->connectUser('bux', 'toor');
842
+    
843
+    $bux = $this->getUser();
844
+    
845
+    // Il peut voir le lien vers l'ouverture des propositions
846
+    $url = $this->generateUrl('ajax_element_proposed_tags_view', array('element_id' => $element->getId()));
847
+    $this->exist('a[href="'.$url.'"]');
848
+    
849
+    // On récupére ces propositions
850
+    $crawler = $this->client->request(
851
+      'GET',
852
+      $url, 
853
+      array(), 
854
+      array(), 
855
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
856
+    );
857
+    
858
+    $this->isResponseSuccess();
859
+    
860
+    $response = json_decode($this->client->getResponse()->getContent(), true);
861
+    $this->assertEquals($response['status'], 'success');
862
+    
863
+    $url_accept_paul = $this->generateUrl('ajax_element_proposed_tags_accept', array(
864
+      'proposition_id' => $proposition_paul->getId(),
865
+      'token'          => $bux->getPersonalHash()
866
+    ));
867
+    $url_accept_joelle = $this->generateUrl('ajax_element_proposed_tags_accept', array(
868
+      'proposition_id' => $proposition_joelle->getId(),
869
+      'token'          => $bux->getPersonalHash()
870
+    ));
871
+    $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_paul.'"') !== false);
872
+    $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_joelle.'"') !== false);
873
+    $url_refuse = $this->generateUrl('ajax_element_proposed_tags_refuse', array(
874
+      'element_id' => $element->getId(),
875
+      'token'      => $bux->getPersonalHash()
876
+    ));
877
+    
878
+    // On accepete la poposition de joelle
879
+    $crawler = $this->client->request(
880
+      'GET',
881
+      $url_accept_joelle, 
882
+      array(), 
883
+      array(), 
884
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
885
+    );
886
+    
887
+    $this->isResponseSuccess();
888
+    
889
+    $response = json_decode($this->client->getResponse()->getContent(), true);
890
+    $this->assertEquals($response['status'], 'success');
891
+    
892
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
893
+      ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
894
+    ;
895
+    // Les tags de l'élément ont bien été mis a jour
896
+    foreach (json_decode($element->getTagsIdsJson(), true) as $id)
897
+    {
898
+      if (in_array($id, array($metal->getId(), $soug->getId(), $tsouzoumi->getId())))
899
+      {
900
+        $this->assertTrue(true);
901
+      }
902
+      else
903
+      {
904
+        $this->assertTrue(false);
905
+      }
906
+    }
907
+    $ids = json_decode($element->getTagsIdsJson(), true);
908
+    foreach (array($metal->getId(), $soug->getId(), $tsouzoumi->getId()) as $id)
909
+    {
910
+      if (in_array($id, $ids))
911
+      {
912
+        $this->assertTrue(true);
913
+      }
914
+      else
915
+      {
916
+        $this->assertTrue(false);
917
+      }
918
+    }
919
+        
920
+    // La proposition de joelle a disparu
921
+    $propositions = $this->getDoctrine()->getEntityManager()
922
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
923
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
924
+      ->setParameters(array(
925
+        'eid' => $element->getId(),
926
+        'uid'    => $joelle->getId()
927
+      ))
928
+      ->getResult()
929
+    ;
930
+    $this->assertEquals(0, count($propositions));
931
+    
932
+    // celle de paul aussi 
933
+    $propositions = $this->getDoctrine()->getEntityManager()
934
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
935
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
936
+      ->setParameters(array(
937
+        'eid' => $element->getId(),
938
+        'uid'    => $paul->getId()
939
+      ))
940
+      ->getResult()
941
+    ;
942
+    $this->assertEquals(0, count($propositions));
943
+    
944
+    // Mais on a un event en archive pour joelle
945
+    $archives = $this->getDoctrine()->getEntityManager()
946
+      ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
947
+        .' WHERE a.user = :uid AND a.type = :type')
948
+      ->setParameters(array(
949
+        'uid'    => $joelle->getId(),
950
+        'type'    => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
951
+      ))
952
+      ->getResult()
953
+    ;
954
+    $this->assertEquals(1, count($archives));
955
+    $this->assertEquals(1, $archives[0]->getCount());
956
+    
957
+    // paul lui n'a pas d'archives
958
+    $archives = $this->getDoctrine()->getEntityManager()
959
+      ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
960
+        .' WHERE a.user = :uid AND a.type = :type')
961
+      ->setParameters(array(
962
+        'uid'    => $paul->getId(),
963
+        'type'    => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
964
+      ))
965
+      ->getResult()
966
+    ;
967
+    $this->assertEquals(0, count($archives));
968
+       
969
+    // contrôle de l'évolution des points
970
+    $bux = $this->getUser('bux');
971
+    $joelle = $this->getUser('joelle');
972
+    $paul = $this->getUser('paul');
973
+    
974
+    $this->assertEquals($points_bux, $bux->getReputation());
975
+    $this->assertEquals($points_joelle + $points_pour_tags_add, $joelle->getReputation());
976
+    $this->assertEquals($points_paul, $paul->getReputation());
977
+    
978
+  }
979
+  
980
+  /**
981
+   * Test des procédure concernants al proposition de tags sur un élément
982
+   * 
983
+   * On test ici: 
984
+   * * Proposition de tags
985
+   * * La consultation de ces propositions
986
+   * * Le refus
987
+   */
988
+  public function testTagsPropositionRefuse()
989
+  {
990
+    $this->client = self::createClient();
991
+    $this->connectUser('paul', 'toor');
992
+    
993
+    $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
994
+    $tribe   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
995
+    $tsouzoumi = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tsouzoumi');
996
+    $soug = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Soug');
997
+    $metal = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Metal');
998
+    
999
+    $paul = $this->getUser();
1000
+    $bux = $this->getUser('bux');
1001
+    $joelle = $this->getUser('joelle');
1002
+    
1003
+    $points_pour_tags_add = $this->getContainer()->getParameter('reputation_element_tags_element_prop_value');
1004
+    $points_joelle = $joelle->getReputation();
1005
+    $points_bux    = $bux->getReputation();
1006
+    $points_paul  = $paul->getReputation();
1007
+    
1008
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
1009
+      ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
1010
+    ;
1011
+    
1012
+    // Pas de proposition en base pur cet élément
1013
+    $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
1014
+      ->findOneByElement($element->getId())
1015
+    ;
1016
+    
1017
+    $this->assertEquals(0, count($propositions));
1018
+    
1019
+    // Pas d'événement pour bux
1020
+    $events = $this->getDoctrine()->getEntityManager()
1021
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
1022
+        WHERE e.user = :uid AND e.type = :type'
1023
+      )
1024
+      ->setParameters(array(
1025
+        'uid' => $bux->getId(),
1026
+        'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
1027
+      ))
1028
+      ->getArrayResult()
1029
+    ;
1030
+    $this->assertEquals(count($events), 0);
1031
+    
1032
+    // On teste la récupération du formulaire au moin une fois
1033
+    $crawler = $this->client->request(
1034
+      'GET',
1035
+      $this->generateUrl('ajax_element_propose_tags_open', 
1036
+        array('element_id' => $element->getId())
1037
+      ), 
1038
+      array(), 
1039
+      array(), 
1040
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
1041
+    );
1042
+    
1043
+    $this->isResponseSuccess();
1044
+    
1045
+    $response = json_decode($this->client->getResponse()->getContent(), true);
1046
+    $this->assertEquals($response['status'], 'success');
1047
+    $this->assertEquals($response['form_name'], 'element_tag_proposition_'.$element->getId());
1048
+    $this->assertTrue(strpos($response['html'], 'class="tag_proposition"') !== false);
1049
+    
1050
+    // paul propose une serie de tags
1051
+    $crawler = $this->client->request(
1052
+      'POST', 
1053
+      $this->generateUrl('ajax_element_propose_tags_proceed', 
1054
+        array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
1055
+      ), 
1056
+      array(
1057
+        'element_tag_proposition_'.$element->getId() => array(
1058
+          'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
1059
+        )
1060
+      ), 
1061
+      array(), 
1062
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
1063
+    );
1064
+    
1065
+    $this->isResponseSuccess();
1066
+    
1067
+    $response = json_decode($this->client->getResponse()->getContent(), true);
1068
+    $this->assertEquals($response['status'], 'success');
1069
+    
1070
+    // On a maintenant la proposition en base
1071
+    $propositions = $this->getDoctrine()->getEntityManager()
1072
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
1073
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
1074
+      ->setParameters(array(
1075
+        'eid' => $element->getId(),
1076
+        'uid'    => $paul->getId()
1077
+      ))
1078
+      ->getResult()
1079
+    ;
1080
+    
1081
+    $this->assertEquals(1, count($propositions));
1082
+    $proposition_paul = $propositions[0];
1083
+    
1084
+    // Les tags sont aussi en base
1085
+    foreach ($propositions[0]->getTags() as $tag)
1086
+    {
1087
+      if (in_array($tag->getId(), array($hardtek->getId(), $tribe->getId())))
1088
+      {
1089
+        $this->assertTrue(true);
1090
+      }
1091
+      else
1092
+      {
1093
+        $this->assertTrue(false);
1094
+      }
1095
+    }
1096
+    
1097
+    // Il y a maintenant un event pour bux
1098
+    $events = $this->getDoctrine()->getEntityManager()
1099
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
1100
+        WHERE e.user = :uid AND e.type = :type'
1101
+      )
1102
+      ->setParameters(array(
1103
+        'uid' => $bux->getId(),
1104
+        'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
1105
+      ))
1106
+      ->getArrayResult()
1107
+    ;
1108
+    $this->assertEquals(count($events), 1);
1109
+    $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
1110
+    // 
1111
+    $this->assertEquals($events[0]['count'], 1);
1112
+    $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
1113
+    
1114
+    // si il propose un liste vide de tags, c'est refusé bien entendu
1115
+    $crawler = $this->client->request(
1116
+      'POST', 
1117
+      $this->generateUrl('ajax_element_propose_tags_proceed', 
1118
+        array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
1119
+      ), 
1120
+      array(
1121
+        'element_tag_proposition_'.$element->getId() => array(
1122
+          'tags' => json_encode(array())
1123
+        )
1124
+      ), 
1125
+      array(), 
1126
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
1127
+    );
1128
+    
1129
+    $this->isResponseSuccess();
1130
+    
1131
+    $response = json_decode($this->client->getResponse()->getContent(), true);
1132
+    $this->assertEquals($response['status'], 'error');
1133
+    
1134
+    /*
1135
+     *  joelle va aussi proposer des tags sur cet élément
1136
+     */
1137
+    $this->disconnectUser();
1138
+    $this->connectUser('joelle', 'toor');
1139
+    
1140
+    $joelle = $this->getUser();
1141
+    
1142
+    // joelle propose une serie de tags
1143
+    $crawler = $this->client->request(
1144
+      'POST', 
1145
+      $this->generateUrl('ajax_element_propose_tags_proceed', 
1146
+        array('element_id' => $element->getId(), 'token' => $joelle->getPersonalHash())
1147
+      ), 
1148
+      array(
1149
+        'element_tag_proposition_'.$element->getId() => array(
1150
+          'tags' => json_encode(array($tsouzoumi->getId(), $soug->getId(), $metal->getId()))
1151
+        )
1152
+      ), 
1153
+      array(), 
1154
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
1155
+    );
1156
+    
1157
+    $this->isResponseSuccess();
1158
+    
1159
+    $response = json_decode($this->client->getResponse()->getContent(), true);
1160
+    $this->assertEquals($response['status'], 'success');
1161
+    
1162
+    // On a maintenant la proposition en base
1163
+    $propositions = $this->getDoctrine()->getEntityManager()
1164
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
1165
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
1166
+      ->setParameters(array(
1167
+        'eid' => $element->getId(),
1168
+        'uid'    => $joelle->getId()
1169
+      ))
1170
+      ->getResult()
1171
+    ;
1172
+    
1173
+    $this->assertEquals(1, count($propositions));
1174
+    $proposition_joelle = $propositions[0];
1175
+    
1176
+    // Les tags sont aussi en base
1177
+    foreach ($propositions[0]->getTags() as $tag)
1178
+    {
1179
+      if (in_array($tag->getId(), array($tsouzoumi->getId(), $soug->getId(), $metal->getId())))
1180
+      {
1181
+        $this->assertTrue(true);
1182
+      }
1183
+      else
1184
+      {
1185
+        $this->assertTrue(false);
1186
+      }
1187
+    }
1188
+    
1189
+    // avec la propsoition de joelle le nombre d'event n'a pas bougé (le compteur compte les éléments)
1190
+    $events = $this->getDoctrine()->getEntityManager()
1191
+      ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
1192
+        WHERE e.user = :uid AND e.type = :type'
1193
+      )
1194
+      ->setParameters(array(
1195
+        'uid' => $bux->getId(),
1196
+        'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
1197
+      ))
1198
+      ->getArrayResult()
1199
+    ;
1200
+    $this->assertEquals(count($events), 1);
1201
+    $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
1202
+    // 
1203
+    $this->assertEquals($events[0]['count'], 1);
1204
+    $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
1205
+    
1206
+    /*
1207
+     *  C'est au tour de bux d'aller voir ces proposition
1208
+     */
1209
+    
1210
+    $this->disconnectUser();
1211
+    $this->connectUser('bux', 'toor');
1212
+    
1213
+    $bux = $this->getUser();
1214
+    
1215
+    // Il peut voir le lien vers l'ouverture des propositions
1216
+    $url = $this->generateUrl('ajax_element_proposed_tags_view', array('element_id' => $element->getId()));
1217
+    $this->exist('a[href="'.$url.'"]');
1218
+    
1219
+    // On récupére ces propositions
1220
+    $crawler = $this->client->request(
1221
+      'GET',
1222
+      $url, 
1223
+      array(), 
1224
+      array(), 
1225
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
1226
+    );
1227
+    
1228
+    $this->isResponseSuccess();
1229
+    
1230
+    $response = json_decode($this->client->getResponse()->getContent(), true);
1231
+    $this->assertEquals($response['status'], 'success');
1232
+    
1233
+    $url_accept_paul = $this->generateUrl('ajax_element_proposed_tags_accept', array(
1234
+      'proposition_id' => $proposition_paul->getId(),
1235
+      'token'          => $bux->getPersonalHash()
1236
+    ));
1237
+    $url_accept_joelle = $this->generateUrl('ajax_element_proposed_tags_accept', array(
1238
+      'proposition_id' => $proposition_joelle->getId(),
1239
+      'token'          => $bux->getPersonalHash()
1240
+    ));
1241
+    $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_paul.'"') !== false);
1242
+    $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_joelle.'"') !== false);
1243
+    $url_refuse = $this->generateUrl('ajax_element_proposed_tags_refuse', array(
1244
+      'element_id' => $element->getId(),
1245
+      'token'      => $bux->getPersonalHash()
1246
+    ));
1247
+    
1248
+    // On accepete la poposition de joelle
1249
+    $crawler = $this->client->request(
1250
+      'GET',
1251
+      $url_refuse, 
1252
+      array(), 
1253
+      array(), 
1254
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
1255
+    );
1256
+    
1257
+    $this->isResponseSuccess();
1258
+    
1259
+    $response = json_decode($this->client->getResponse()->getContent(), true);
1260
+    $this->assertEquals($response['status'], 'success');
1261
+    
1262
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
1263
+      ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
1264
+    ;
1265
+    // Les tags de l'élément n'ont pas bougés
1266
+    $this->assertEquals(
1267
+      json_encode(array($metal->getId())),
1268
+      $element->getTagsIdsJson()
1269
+    );
1270
+    
1271
+    // La proposition de joelle a disparu
1272
+    $propositions = $this->getDoctrine()->getEntityManager()
1273
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
1274
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
1275
+      ->setParameters(array(
1276
+        'eid' => $element->getId(),
1277
+        'uid'    => $joelle->getId()
1278
+      ))
1279
+      ->getResult()
1280
+    ;
1281
+    $this->assertEquals(0, count($propositions));
1282
+    
1283
+    // celle de paul aussi 
1284
+    $propositions = $this->getDoctrine()->getEntityManager()
1285
+      ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
1286
+        .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
1287
+      ->setParameters(array(
1288
+        'eid' => $element->getId(),
1289
+        'uid'    => $paul->getId()
1290
+      ))
1291
+      ->getResult()
1292
+    ;
1293
+    $this->assertEquals(0, count($propositions));
1294
+    
1295
+    // Et on as pas d'archive pour joelle
1296
+    $archives = $this->getDoctrine()->getEntityManager()
1297
+      ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
1298
+        .' WHERE a.user = :uid AND a.type = :type')
1299
+      ->setParameters(array(
1300
+        'uid'    => $joelle->getId(),
1301
+        'type'    => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
1302
+      ))
1303
+      ->getResult()
1304
+    ;
1305
+    $this->assertEquals(0, count($archives));
1306
+    
1307
+    // paul lui n'a pas d'archives non plus
1308
+    $archives = $this->getDoctrine()->getEntityManager()
1309
+      ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
1310
+        .' WHERE a.user = :uid AND a.type = :type')
1311
+      ->setParameters(array(
1312
+        'uid'    => $paul->getId(),
1313
+        'type'    => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
1314
+      ))
1315
+      ->getResult()
1316
+    ;
1317
+    $this->assertEquals(0, count($archives));
1318
+       
1319
+    // contrôle de l'évolution des points
1320
+    $bux = $this->getUser('bux');
1321
+    $joelle = $this->getUser('joelle');
1322
+    $paul = $this->getUser('paul');
1323
+    
1324
+    $this->assertEquals($points_bux, $bux->getReputation());
1325
+    $this->assertEquals($points_joelle, $joelle->getReputation());
1326
+    $this->assertEquals($points_paul, $paul->getReputation());
1327
+    
1328
+  }
1329
+  
610 1330
 }