ShowControllerTest.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. namespace Muzich\CoreBundle\Tests\Controller;
  3. use Muzich\CoreBundle\lib\FunctionalTest;
  4. use Muzich\CoreBundle\Entity\FollowUser;
  5. use Muzich\CoreBundle\Entity\FollowGroup;
  6. class ShowControllerTest extends FunctionalTest
  7. {
  8. public function testViewMoreOnProfile()
  9. {
  10. $this->client = self::createClient();
  11. $this->connectUser('bux', 'toor');
  12. $bux = $this->getUser();
  13. $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
  14. $tribe_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
  15. // En premier lieux on va devoir ajouter des éléments.
  16. $this->addElementAjax('PoPElement 1', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
  17. $this->addElementAjax('PoPElement 2', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
  18. $this->addElementAjax('PoPElement 3', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
  19. $this->addElementAjax('PoPElement 4', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
  20. // D'après les fixtures on aura 2 éléments en plus des 10 (paramétre) de la page
  21. // Ouverture de la page profil
  22. $this->crawler = $this->client->request('GET', $this->generateUrl('show_user', array('slug' => $bux->getSlug())));
  23. $this->isResponseSuccess();
  24. $this->exist('span.element_name:contains("PoPElement 4")');
  25. $this->exist('span.element_name:contains("PoPElement 3")');
  26. $this->exist('span.element_name:contains("PoPElement 2")');
  27. $this->exist('span.element_name:contains("PoPElement 1")');
  28. $this->exist('span.element_name:contains("Ed Cox - La fanfare des teuffeurs (Hardcordian)")');
  29. $this->exist('span.element_name:contains("Babylon Pression - Des Tasers et des Pauvres")');
  30. $this->exist('span.element_name:contains("AZYD AZYLUM Live au Café Provisoire")');
  31. $this->exist('span.element_name:contains("SOULFLY - Prophecy")');
  32. $this->exist('span.element_name:contains("KoinkOin - H5N1")');
  33. $this->exist('span.element_name:contains("Antropod - Polakatek")');
  34. $this->notExist('span.element_name:contains("Dtc che passdrop")');
  35. $this->notExist('span.element_name:contains("Heretik System Popof - Resistance")');
  36. // L'élément de référence est celui en bas de la liste
  37. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  38. ->findOneByName('Antropod - Polakatek')
  39. ;
  40. $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
  41. ->getElementsTags($bux->getId(), $bux->getId())
  42. ;
  43. $ids = array();
  44. foreach ($tags as $tag)
  45. {
  46. $ids[] = $tag->getId();
  47. }
  48. // On fait la demande pour en voir plus
  49. $url = $this->generateUrl('show_elements_get', array(
  50. 'type' => 'user',
  51. 'object_id' => $bux->getId(),
  52. 'tags_ids_json' => json_encode($ids),
  53. 'id_limit' => $element->getId()
  54. ));
  55. $crawler = $this->client->request(
  56. 'GET',
  57. $url,
  58. array(),
  59. array(),
  60. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  61. );
  62. $response = json_decode($this->client->getResponse()->getContent(), true);
  63. $this->assertEquals($response['status'], 'success');
  64. $this->assertTrue(strpos($response['html'], 'Dtc che passdrop') !== false);
  65. $this->assertTrue(strpos($response['html'], 'Heretik System Popof - Resistance') !== false);
  66. }
  67. public function testViewMoreOnGroup()
  68. {
  69. $this->client = self::createClient();
  70. $this->connectUser('bux', 'toor');
  71. $bux = $this->getUser();
  72. $fan_de_psy = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
  73. $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
  74. $tribe_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
  75. // En premier lieux on va devoir ajouter des éléments.
  76. $this->addElementAjax('PsyElement 1', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  77. $this->addElementAjax('PsyElement 2', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  78. $this->addElementAjax('PsyElement 3', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  79. $this->addElementAjax('PsyElement 4', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  80. $this->addElementAjax('PsyElement 5', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  81. $this->addElementAjax('PsyElement 6', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  82. $this->addElementAjax('PsyElement 7', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  83. $this->addElementAjax('PsyElement 8', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  84. $this->addElementAjax('PsyElement 9', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  85. $this->addElementAjax('PsyElement 10', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)), $fan_de_psy->getSlug());
  86. // D'après les fixtures on aura 2 éléments en plus des 10 (paramétre) de la page
  87. // Ouverture de la page profil
  88. $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $fan_de_psy->getSlug())));
  89. $this->isResponseSuccess();
  90. $this->exist('span.element_name:contains("PsyElement 10")');
  91. $this->exist('span.element_name:contains("PsyElement 9")');
  92. $this->exist('span.element_name:contains("PsyElement 8")');
  93. $this->exist('span.element_name:contains("PsyElement 7")');
  94. $this->exist('span.element_name:contains("PsyElement 6")');
  95. $this->exist('span.element_name:contains("PsyElement 5")');
  96. $this->exist('span.element_name:contains("PsyElement 4")');
  97. $this->exist('span.element_name:contains("PsyElement 3")');
  98. $this->exist('span.element_name:contains("PsyElement 5")');
  99. $this->exist('span.element_name:contains("PsyElement 1")');
  100. $this->notExist('span.element_name:contains("Infected mushroom - Muse Breaks")');
  101. $this->notExist('span.element_name:contains("Infected Mushroom - Psycho")');
  102. // L'élément de référence est celui en bas de la liste, donc le premier ajouté
  103. // la haut (vuq ue l'on en a ajouté 10)
  104. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  105. ->findOneByName('PsyElement 1')
  106. ;
  107. $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
  108. ->getElementsTags($fan_de_psy->getId(), $bux->getId())
  109. ;
  110. $ids = array();
  111. foreach ($tags as $tag)
  112. {
  113. $ids[] = $tag->getId();
  114. }
  115. // On fait la demande pour en voir plus
  116. $url = $this->generateUrl('show_elements_get', array(
  117. 'type' => 'group',
  118. 'object_id' => $fan_de_psy->getId(),
  119. 'tags_ids_json' => json_encode($ids),
  120. 'id_limit' => $element->getId()
  121. ));
  122. $crawler = $this->client->request(
  123. 'GET',
  124. $url,
  125. array(),
  126. array(),
  127. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  128. );
  129. $response = json_decode($this->client->getResponse()->getContent(), true);
  130. $this->assertEquals($response['status'], 'success');
  131. $this->assertTrue(strpos($response['html'], 'Infected mushroom - Muse Breaks') !== false);
  132. $this->assertTrue(strpos($response['html'], 'Infected Mushroom - Psycho') !== false);
  133. }
  134. /**
  135. * Contrôle de l'affichage des informations x partages x suiveur ...
  136. */
  137. public function testInfosUser()
  138. {
  139. $this->client = self::createClient();
  140. $this->connectUser('bux', 'toor');
  141. $bux = $this->getUser();
  142. $paul = $this->getUser('paul');
  143. $joelle = $this->getUser('joelle');
  144. // $translator = new Translator('fr', new MessageSelector());
  145. // $translator->trans($id, $parameters, $domain, $locale);
  146. // On va sur la page profil de paul
  147. $this->crawler = $this->client->request('GET',
  148. $this->generateUrl('show_user', array('slug' => $paul->getSlug()))
  149. );
  150. $this->isResponseSuccess();
  151. // D'après les fixtures
  152. $this->exist('p.show_info:contains("'.
  153. $this->getContainer()->get('translator')->trans('show.user.elements.count', array(
  154. '%count_owned%' => 4,
  155. '%count_favorited%' => 0,
  156. '%count_favorited_users%' => 0
  157. ), 'elements')
  158. .'")');
  159. $this->exist('p.show_info:contains("'.
  160. $this->getContainer()->get('translator')->trans('show.user.followers.one_count', array(
  161. '%count%' => 1,
  162. '%name%' => $paul->getName()
  163. ), 'elements')
  164. .'")');
  165. // On supprime le fait que bux suivent paul
  166. $follow = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
  167. ->findOneBy(array(
  168. 'follower' => $bux->getId(),
  169. 'followed' => $paul->getId()
  170. ))
  171. ;
  172. $this->getDoctrine()->getEntityManager()->remove($follow);
  173. $this->getDoctrine()->getEntityManager()->flush();
  174. // On rafraichie la page
  175. $this->crawler = $this->client->request('GET',
  176. $this->generateUrl('show_user', array('slug' => $paul->getSlug()))
  177. );
  178. $this->isResponseSuccess();
  179. // D'après les fixtures
  180. $this->exist('p.show_info:contains("'.
  181. $this->getContainer()->get('translator')->trans('show.user.elements.count', array(
  182. '%count_owned%' => 4,
  183. '%count_favorited%' => 0,
  184. '%count_favorited_users%' => 0
  185. ), 'elements')
  186. .'")');
  187. $this->exist('p.show_info:contains("'.
  188. $this->getContainer()->get('translator')->trans('show.user.followers.zero_count', array(
  189. '%name%' => $paul->getName()
  190. ), 'elements')
  191. .'")');
  192. // bux met en favoris un élément
  193. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  194. ->findOneByName('Infected Mushroom - Psycho')
  195. ;
  196. $url = $this->generateUrl('favorite_add', array(
  197. 'id' => $element->getId(),
  198. 'token' => $bux->getPersonalHash()
  199. ));
  200. $crawler = $this->client->request('GET', $url, array(), array(), array(
  201. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  202. ));
  203. $this->isResponseSuccess();
  204. // On contrôle la présence du favoris
  205. $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
  206. ->findOneBy(array(
  207. 'user' => $bux->getId(),
  208. 'element' => $element->getId()
  209. ));
  210. $this->assertTrue(!is_null($fav));
  211. // On rafraichie la page
  212. $this->crawler = $this->client->request('GET',
  213. $this->generateUrl('show_user', array('slug' => $paul->getSlug()))
  214. );
  215. $this->isResponseSuccess();
  216. // D'après les fixtures
  217. $this->exist('p.show_info:contains("'.
  218. $this->getContainer()->get('translator')->trans('show.user.elements.count', array(
  219. '%count_owned%' => 4,
  220. '%count_favorited%' => 1,
  221. '%count_favorited_users%' => 1
  222. ), 'elements')
  223. .'")');
  224. $this->exist('p.show_info:contains("'.
  225. $this->getContainer()->get('translator')->trans('show.user.followers.zero_count', array(
  226. '%name%' => $paul->getName()
  227. ), 'elements')
  228. .'")');
  229. // bux met en favoris un autre élément
  230. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  231. ->findOneByName('CardioT3K - Juggernaut Trap')
  232. ;
  233. $url = $this->generateUrl('favorite_add', array(
  234. 'id' => $element->getId(),
  235. 'token' => $bux->getPersonalHash()
  236. ));
  237. $crawler = $this->client->request('GET', $url, array(), array(), array(
  238. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  239. ));
  240. $this->isResponseSuccess();
  241. // On contrôle la présence du favoris
  242. $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
  243. ->findOneBy(array(
  244. 'user' => $bux->getId(),
  245. 'element' => $element->getId()
  246. ));
  247. $this->assertTrue(!is_null($fav));
  248. // On rafraichie la page
  249. $this->crawler = $this->client->request('GET',
  250. $this->generateUrl('show_user', array('slug' => $paul->getSlug()))
  251. );
  252. $this->isResponseSuccess();
  253. // D'après les fixtures
  254. $this->exist('p.show_info:contains("'.
  255. $this->getContainer()->get('translator')->trans('show.user.elements.count', array(
  256. '%count_owned%' => 4,
  257. '%count_favorited%' => 2,
  258. '%count_favorited_users%' => 1
  259. ), 'elements')
  260. .'")');
  261. $this->exist('p.show_info:contains("'.
  262. $this->getContainer()->get('translator')->trans('show.user.followers.zero_count', array(
  263. '%name%' => $paul->getName()
  264. ), 'elements')
  265. .'")');
  266. // joelle va mette un de ces deux elements en favoris
  267. $this->disconnectUser();
  268. $this->connectUser('joelle', 'toor');
  269. // joelle met en favoris un de ces élément
  270. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  271. ->findOneByName('CardioT3K - Juggernaut Trap')
  272. ;
  273. $url = $this->generateUrl('favorite_add', array(
  274. 'id' => $element->getId(),
  275. 'token' => $joelle->getPersonalHash()
  276. ));
  277. $crawler = $this->client->request('GET', $url, array(), array(), array(
  278. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  279. ));
  280. $this->isResponseSuccess();
  281. // On contrôle la présence du favoris
  282. $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
  283. ->findOneBy(array(
  284. 'user' => $joelle->getId(),
  285. 'element' => $element->getId()
  286. ));
  287. $this->assertTrue(!is_null($fav));
  288. // On rafraichie la page
  289. $this->crawler = $this->client->request('GET',
  290. $this->generateUrl('show_user', array('slug' => $paul->getSlug()))
  291. );
  292. $this->isResponseSuccess();
  293. // D'après les fixtures
  294. $this->exist('p.show_info:contains("'.
  295. $this->getContainer()->get('translator')->trans('show.user.elements.count', array(
  296. '%count_owned%' => 4,
  297. '%count_favorited%' => 2,
  298. '%count_favorited_users%' => 2
  299. ), 'elements')
  300. .'")');
  301. $this->exist('p.show_info:contains("'.
  302. $this->getContainer()->get('translator')->trans('show.user.followers.zero_count', array(
  303. '%name%' => $paul->getName()
  304. ), 'elements')
  305. .'")');
  306. // joelle met en favoris un autre élément
  307. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  308. ->findOneByName('RE-FUCK (ReVeRB_FBC) mix.')
  309. ;
  310. $url = $this->generateUrl('favorite_add', array(
  311. 'id' => $element->getId(),
  312. 'token' => $joelle->getPersonalHash()
  313. ));
  314. $crawler = $this->client->request('GET', $url, array(), array(), array(
  315. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  316. ));
  317. $this->isResponseSuccess();
  318. // On contrôle la présence du favoris
  319. $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
  320. ->findOneBy(array(
  321. 'user' => $joelle->getId(),
  322. 'element' => $element->getId()
  323. ));
  324. $this->assertTrue(!is_null($fav));
  325. // On rafraichie la page
  326. $this->crawler = $this->client->request('GET',
  327. $this->generateUrl('show_user', array('slug' => $paul->getSlug()))
  328. );
  329. $this->isResponseSuccess();
  330. // D'après les fixtures
  331. $this->exist('p.show_info:contains("'.
  332. $this->getContainer()->get('translator')->trans('show.user.elements.count', array(
  333. '%count_owned%' => 4,
  334. '%count_favorited%' => 3,
  335. '%count_favorited_users%' => 2
  336. ), 'elements')
  337. .'")');
  338. $this->exist('p.show_info:contains("'.
  339. $this->getContainer()->get('translator')->trans('show.user.followers.zero_count', array(
  340. '%name%' => $paul->getName()
  341. ), 'elements')
  342. .'")');
  343. }
  344. }