MynetworkControllerTest.php 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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->connectUser('bux', 'toor');
  17. $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
  18. $this->clickOnLink($link);
  19. $this->isResponseSuccess();
  20. // Récupération des entités
  21. $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('jean');
  22. $paul = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('paul');
  23. $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
  24. $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
  25. $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
  26. $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $jean->getSlug())).'"]');
  27. $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $paul->getSlug())).'"]');
  28. $this->exist('ul#followers_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
  29. $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())).'"]');
  30. $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Fans_de_psytrance->getSlug())).'"]');
  31. }
  32. /**
  33. * Test de la recherche
  34. */
  35. public function testSearch()
  36. {
  37. $this->connectUser('bux', 'toor');
  38. $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
  39. $this->clickOnLink($link);
  40. $this->isResponseSuccess();
  41. $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_search').'"]');
  42. $this->clickOnLink($link);
  43. $this->isResponseSuccess();
  44. $this->exist('form[action="'.($url = $this->generateUrl('mynetwork_search')).'"]');
  45. $this->exist('form[action="'.$url.'"] input[id="form_string"]');
  46. $this->exist('form[action="'.$url.'"] input[type="submit"]');
  47. $bob = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bob');
  48. // On va rechercher l'utilisateur bob
  49. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  50. $form['form[string]'] = 'bob';
  51. $this->submit($form);
  52. $this->isResponseSuccess();
  53. // On trouve bob
  54. $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $bob->getSlug())).'"]');
  55. $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
  56. $Le_groupe_de_joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Le groupe de joelle');
  57. // On va maintenant rechercher le groupe de joelle
  58. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  59. $form['form[string]'] = 'joelle';
  60. $this->submit($form);
  61. $this->isResponseSuccess();
  62. // On trouve joelle mais aussi son groupe (il y a joelle dans le nom)
  63. $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
  64. $this->exist('ul#search_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Le_groupe_de_joelle->getSlug())).'"]');
  65. }
  66. /**
  67. * Test de l'action 'suivre' et 'ne plus suivre' sur un user
  68. */
  69. public function testUserFollow()
  70. {
  71. // Connection de bob
  72. $this->connectUser('bob', 'toor');
  73. // Récupération des entités (bob ne les suit pas)
  74. $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bux');
  75. // On tente de récupérer l'entité FollowUser
  76. $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
  77. ->findOneBy(array(
  78. 'follower' => $this->getUser()->getId(),
  79. 'followed' => $bux->getId()
  80. ))
  81. ;
  82. // Mais celle-ci doit-être innexistante
  83. $this->assertTrue(is_null($FollowUser));
  84. // Ouverture de la page d'un user (bux)
  85. $this->crawler = $this->client->request('GET', $this->generateUrl('show_user', array('slug' => $bux->getSlug())));
  86. $this->isResponseSuccess();
  87. $url_follow = $this->generateUrl('follow', array(
  88. 'type' => 'user',
  89. 'id' => $bux->getId(),
  90. 'token' => $this->getUser()->getPersonalHash()
  91. ));
  92. // On lance l'action de suivre
  93. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  94. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  95. $this->clickOnLink($link);
  96. $this->isResponseRedirection();
  97. $this->followRedirection();
  98. $this->isResponseSuccess();
  99. $this->exist('a.following[href="'.$url_follow.'"]');
  100. // On tente de récupérer l'entité FollowUser
  101. $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
  102. ->findOneBy(array(
  103. 'follower' => $this->getUser()->getId(),
  104. 'followed' => $bux->getId()
  105. ))
  106. ;
  107. // Celle-ci doit exister maintenant
  108. $this->assertTrue(!is_null($FollowUser));
  109. // On lance l'action de ne plus suivre
  110. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  111. $this->clickOnLink($link);
  112. $this->isResponseRedirection();
  113. $this->followRedirection();
  114. $this->isResponseSuccess();
  115. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  116. // On tente de récupérer l'entité FollowUser
  117. $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
  118. ->findOneBy(array(
  119. 'follower' => $this->getUser()->getId(),
  120. 'followed' => $bux->getId()
  121. ))
  122. ;
  123. // Celle-ci ne doit plus exister maintenant
  124. $this->assertTrue(is_null($FollowUser));
  125. }
  126. /**
  127. * Test de l'action 'suivre' et 'ne plus suivre' sur un groupe
  128. */
  129. public function testGroupFollow()
  130. {
  131. // Connection de bob
  132. $this->connectUser('bob', 'toor');
  133. // Récupération des entités (bob ne les suit pas)
  134. $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
  135. // On tente de récupérer l'entité FollowUser
  136. $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
  137. ->findOneBy(array(
  138. 'follower' => $this->getUser()->getId(),
  139. 'group' => $DUDELDRUM->getId()
  140. ))
  141. ;
  142. // Mais celle-ci doit-être innexistante
  143. $this->assertTrue(is_null($FollowGroup));
  144. // Ouverture de la page d'un user (bux)
  145. $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())));
  146. $this->isResponseSuccess();
  147. $url_follow = $this->generateUrl('follow', array(
  148. 'type' => 'group',
  149. 'id' => $DUDELDRUM->getId(),
  150. 'token' => $this->getUser()->getPersonalHash()
  151. ));
  152. // On lance l'action de suivre
  153. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  154. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  155. $this->clickOnLink($link);
  156. $this->isResponseRedirection();
  157. $this->followRedirection();
  158. $this->isResponseSuccess();
  159. $this->exist('a.following[href="'.$url_follow.'"]');
  160. // On tente de récupérer l'entité FollowUser
  161. $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
  162. ->findOneBy(array(
  163. 'follower' => $this->getUser()->getId(),
  164. 'group' => $DUDELDRUM->getId()
  165. ))
  166. ;
  167. // Celle-ci doit exister maintenant
  168. $this->assertTrue(!is_null($FollowGroup));
  169. // On lance l'action de ne plus suivre
  170. $link = $this->selectLink('a[href="'.$url_follow.'"]');
  171. $this->clickOnLink($link);
  172. $this->isResponseRedirection();
  173. $this->followRedirection();
  174. $this->isResponseSuccess();
  175. $this->exist('a.notfollowing[href="'.$url_follow.'"]');
  176. // On tente de récupérer l'entité FollowUser
  177. $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
  178. ->findOneBy(array(
  179. 'follower' => $this->getUser()->getId(),
  180. 'group' => $DUDELDRUM->getId()
  181. ))
  182. ;
  183. // Celle-ci ne doit plus exister maintenant
  184. $this->assertTrue(is_null($FollowGroup));
  185. }
  186. }