MynetworkControllerTest.php 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. namespace Muzich\CoreBundle\Tests\Controller;
  3. use Muzich\CoreBundle\lib\FunctionalTest;
  4. class MynetworkControllerTest extends FunctionalTest
  5. {
  6. /**
  7. * Test de l'affichage de la page "mon réseau"
  8. */
  9. public function testMyNetwork()
  10. {
  11. /**
  12. * Avec l'utilisateur 'bux' , qui d'après les fixtures suis: jean, paul,
  13. * les groupes DUDELDRUM et Fans de psytrance
  14. * et est suivis par joelle
  15. */
  16. $this->client = self::createClient();
  17. $this->connectUser('bux', 'toor');
  18. $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
  19. $this->clickOnLink($link);
  20. $this->isResponseSuccess();
  21. // Récupération des entités
  22. $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('jean');
  23. $paul = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('paul');
  24. $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
  25. $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
  26. $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
  27. $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $jean->getSlug())).'"]');
  28. $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $paul->getSlug())).'"]');
  29. $this->exist('ul#followers_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
  30. $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())).'"]');
  31. $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Fans_de_psytrance->getSlug())).'"]');
  32. }
  33. /**
  34. * Test de la recherche
  35. */
  36. public function testSearch()
  37. {
  38. $this->client = self::createClient();
  39. $this->connectUser('bux', 'toor');
  40. $this->exist('form[action="'.($url = $this->generateUrl('global_search')).'"]');
  41. $this->exist('form[action="'.$url.'"] input[id="form_string"]');
  42. $this->exist('form[action="'.$url.'"] input[type="submit"]');
  43. $bob = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bob');
  44. // On va rechercher l'utilisateur bob
  45. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  46. $form['form[string]'] = 'bob';
  47. $this->submit($form);
  48. $this->isResponseSuccess();
  49. // On trouve bob
  50. $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $bob->getSlug())).'"]');
  51. $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
  52. $Le_groupe_de_joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Le groupe de joelle');
  53. // On va maintenant rechercher le groupe de joelle
  54. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  55. $form['form[string]'] = 'joelle';
  56. $this->submit($form);
  57. $this->isResponseSuccess();
  58. // On trouve joelle mais aussi son groupe (il y a joelle dans le nom)
  59. $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
  60. $this->exist('ul#search_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Le_groupe_de_joelle->getSlug())).'"]');
  61. // On cherche des éléments
  62. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  63. $form['form[string]'] = 'har';
  64. $this->submit($form);
  65. $this->isResponseSuccess();
  66. $this->exist('span.element_name:contains("Ed Cox - La fanfare des teuffeurs (Hardcordian)")');
  67. $this->exist('span.element_name:contains("Acrotek Hardtek G01")');
  68. // On cherche des éléments en jouant avec le principe de découpe (' ', ',' '-' ...)
  69. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  70. $form['form[string]'] = 'azyd babylon cox';
  71. $this->submit($form);
  72. $this->isResponseSuccess();
  73. $this->exist('span.element_name:contains("Ed Cox - La fanfare des teuffeurs (Hardcordian)")');
  74. $this->exist('span.element_name:contains("Babylon Pression - Des Tasers et des Pauvres")');
  75. $this->exist('span.element_name:contains("AZYD AZYLUM Live au Café Provisoire")');
  76. }
  77. /**
  78. * Test de l'action 'suivre' et 'ne plus suivre' sur un user
  79. */
  80. public function testUserFollow()
  81. {
  82. $this->client = self::createClient();
  83. // Connection de bob
  84. $this->connectUser('bob', 'toor');
  85. // Récupération des entités (bob ne les suit pas)
  86. $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bux');
  87. // On tente de récupérer l'entité FollowUser
  88. $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
  89. ->findOneBy(array(
  90. 'follower' => $this->getUser()->getId(),
  91. 'followed' => $bux->getId()
  92. ))
  93. ;
  94. // Mais celle-ci doit-être innexistante
  95. $this->assertTrue(is_null($FollowUser));
  96. // Ouverture de la page d'un user (bux)
  97. $this->crawler = $this->client->request('GET', $this->generateUrl('show_user', array('slug' => $bux->getSlug())));
  98. $this->isResponseSuccess();
  99. // Controle de l'évolution du score de bux
  100. $bux = $this->getUser('bux');
  101. $this->assertEquals($bux->getReputation(), 22);
  102. $url_follow = $this->generateUrl('follow', array(
  103. 'type' => 'user',
  104. 'id' => $bux->getId(),
  105. 'token' => $this->getUser()->getPersonalHash()
  106. ));
  107. // On lance l'action de suivre
  108. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  109. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  110. $this->clickOnLink($link);
  111. $this->isResponseRedirection();
  112. $this->followRedirection();
  113. $this->isResponseSuccess();
  114. $this->exist('a.following[href="'.$url_follow.'"]');
  115. // On tente de récupérer l'entité FollowUser
  116. $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
  117. ->findOneBy(array(
  118. 'follower' => $this->getUser()->getId(),
  119. 'followed' => $bux->getId()
  120. ))
  121. ;
  122. // Celle-ci doit exister maintenant
  123. $this->assertTrue(!is_null($FollowUser));
  124. // Controle de l'évolution du score de bux
  125. $bux = $this->getUser('bux');
  126. $this->assertEquals($bux->getReputation(), 32);
  127. // On lance l'action de ne plus suivre
  128. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  129. $this->clickOnLink($link);
  130. $this->isResponseRedirection();
  131. $this->followRedirection();
  132. $this->isResponseSuccess();
  133. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  134. // On tente de récupérer l'entité FollowUser
  135. $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
  136. ->findOneBy(array(
  137. 'follower' => $this->getUser()->getId(),
  138. 'followed' => $bux->getId()
  139. ))
  140. ;
  141. // Celle-ci ne doit plus exister maintenant
  142. $this->assertTrue(is_null($FollowUser));
  143. // Controle de l'évolution du score de bux
  144. $bux = $this->getUser('bux');
  145. $this->assertEquals($bux->getReputation(), 22);
  146. }
  147. /**
  148. * Test de l'action 'suivre' et 'ne plus suivre' sur un groupe
  149. */
  150. public function testGroupFollow()
  151. {
  152. $this->client = self::createClient();
  153. // Connection de bob
  154. $this->connectUser('bob', 'toor');
  155. // Récupération des entités (bob ne les suit pas)
  156. $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
  157. // On tente de récupérer l'entité FollowUser
  158. $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
  159. ->findOneBy(array(
  160. 'follower' => $this->getUser()->getId(),
  161. 'group' => $DUDELDRUM->getId()
  162. ))
  163. ;
  164. // Mais celle-ci doit-être innexistante
  165. $this->assertTrue(is_null($FollowGroup));
  166. // Ouverture de la page d'un user (bux)
  167. $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())));
  168. $this->isResponseSuccess();
  169. $url_follow = $this->generateUrl('follow', array(
  170. 'type' => 'group',
  171. 'id' => $DUDELDRUM->getId(),
  172. 'token' => $this->getUser()->getPersonalHash()
  173. ));
  174. // On lance l'action de suivre
  175. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  176. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  177. $this->clickOnLink($link);
  178. $this->isResponseRedirection();
  179. $this->followRedirection();
  180. $this->isResponseSuccess();
  181. $this->exist('a.following[href="'.$url_follow.'"]');
  182. // On tente de récupérer l'entité FollowUser
  183. $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
  184. ->findOneBy(array(
  185. 'follower' => $this->getUser()->getId(),
  186. 'group' => $DUDELDRUM->getId()
  187. ))
  188. ;
  189. // Celle-ci doit exister maintenant
  190. $this->assertTrue(!is_null($FollowGroup));
  191. // On lance l'action de ne plus suivre
  192. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  193. $this->clickOnLink($link);
  194. $this->isResponseRedirection();
  195. $this->followRedirection();
  196. $this->isResponseSuccess();
  197. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  198. // On tente de récupérer l'entité FollowUser
  199. $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
  200. ->findOneBy(array(
  201. 'follower' => $this->getUser()->getId(),
  202. 'group' => $DUDELDRUM->getId()
  203. ))
  204. ;
  205. // Celle-ci ne doit plus exister maintenant
  206. $this->assertTrue(is_null($FollowGroup));
  207. }
  208. }