ModerateControllerTest.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <?php
  2. namespace Muzich\CoreBundle\Tests\Controller;
  3. use Muzich\CoreBundle\lib\FunctionalTest;
  4. use Muzich\CoreBundle\Managers\CommentsManager;
  5. /**
  6. * Test des procédure de modérations
  7. *
  8. *
  9. */
  10. class ModerateControllerTest extends FunctionalTest
  11. {
  12. public function testReportElement()
  13. {
  14. $this->client = self::createClient();
  15. $this->connectUser('paul', 'toor');
  16. $paul = $this->getUser();
  17. $paul_bad_reports_count = $paul->getBadReportCount();
  18. $bux_moderated_element_count = $this->getUser('bux')->getModeratedElementCount();
  19. $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  20. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  21. ;
  22. // Paul signale cet élément comme pas bien
  23. $url = $this->generateUrl('ajax_report_element', array(
  24. 'element_id' => $element_ed->getId(),
  25. 'token' => $paul->getPersonalHash()
  26. ));
  27. $crawler = $this->client->request(
  28. 'GET',
  29. $url,
  30. array(),
  31. array(),
  32. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  33. );
  34. $this->isResponseSuccess();
  35. $response = json_decode($this->client->getResponse()->getContent(), true);
  36. $this->assertEquals($response['status'], 'success');
  37. // On check en base
  38. $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  39. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  40. ;
  41. $this->assertEquals($element_ed->getCountReport(), 1);
  42. $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId()));
  43. // Si il effectue le signalement une deuxième fois sur le même element
  44. // Ca ne doit pas bouger puisqu'il l'a déjà fait
  45. $url = $this->generateUrl('ajax_report_element', array(
  46. 'element_id' => $element_ed->getId(),
  47. 'token' => $paul->getPersonalHash()
  48. ));
  49. $crawler = $this->client->request(
  50. 'GET',
  51. $url,
  52. array(),
  53. array(),
  54. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  55. );
  56. $this->isResponseSuccess();
  57. $response = json_decode($this->client->getResponse()->getContent(), true);
  58. $this->assertEquals($response['status'], 'success');
  59. // On check en base
  60. $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  61. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  62. ;
  63. $this->assertEquals($element_ed->getCountReport(), 1);
  64. $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId()));
  65. // Paul va ausi signaler un autre élément
  66. // Babylon Pression - Des Tasers et des Pauvres
  67. // On check en base
  68. $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  69. ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
  70. ;
  71. $this->assertEquals($element_bab->getCountReport(), 0);
  72. $this->assertEquals($element_bab->getReportIds(), null);
  73. // Si il effectue le signalement une deuxième fois sur le même element
  74. // Ca ne doit pas bouger puisqu'il l'a déjà fait
  75. $url = $this->generateUrl('ajax_report_element', array(
  76. 'element_id' => $element_bab->getId(),
  77. 'token' => $paul->getPersonalHash()
  78. ));
  79. $crawler = $this->client->request(
  80. 'GET',
  81. $url,
  82. array(),
  83. array(),
  84. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  85. );
  86. $this->isResponseSuccess();
  87. $response = json_decode($this->client->getResponse()->getContent(), true);
  88. $this->assertEquals($response['status'], 'success');
  89. // On check en base
  90. $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  91. ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
  92. ;
  93. $this->assertEquals($element_bab->getCountReport(), 1);
  94. $this->assertEquals($element_bab->getReportIds(), array((string)$paul->getId()));
  95. // On passe a joelle
  96. $this->disconnectUser();
  97. // On connecte joelle pour faire le même test sur le même élément
  98. $this->connectUser('joelle', 'toor');
  99. $joelle = $this->getUser();
  100. $joelle_bad_reports_count = $joelle->getBadReportCount();
  101. $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  102. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  103. ;
  104. // Paul signale cet élément comme pas bien
  105. $url = $this->generateUrl('ajax_report_element', array(
  106. 'element_id' => $element_ed->getId(),
  107. 'token' => $joelle->getPersonalHash()
  108. ));
  109. $crawler = $this->client->request(
  110. 'GET',
  111. $url,
  112. array(),
  113. array(),
  114. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  115. );
  116. $this->isResponseSuccess();
  117. $response = json_decode($this->client->getResponse()->getContent(), true);
  118. $this->assertEquals($response['status'], 'success');
  119. // On check en base
  120. $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  121. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  122. ;
  123. $this->assertEquals($element_ed->getCountReport(), 2);
  124. $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
  125. // Si elle effectue le signalement une deuxième fois sur le même element
  126. // Ca ne doit pas bouger puisqu'elle l'a déjà fait
  127. $url = $this->generateUrl('ajax_report_element', array(
  128. 'element_id' => $element_ed->getId(),
  129. 'token' => $joelle->getPersonalHash()
  130. ));
  131. $crawler = $this->client->request(
  132. 'GET',
  133. $url,
  134. array(),
  135. array(),
  136. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  137. );
  138. $this->isResponseSuccess();
  139. $response = json_decode($this->client->getResponse()->getContent(), true);
  140. $this->assertEquals($response['status'], 'success');
  141. // On check en base
  142. $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  143. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  144. ;
  145. $this->assertEquals($element_ed->getCountReport(), 2);
  146. $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
  147. /*
  148. * Maintenant on va aller modérer ça coté modération.
  149. */
  150. // On donne le status d'admin a bob
  151. $output = $this->runCommand(
  152. $this->client,
  153. "fos:user:promote bob ROLE_ADMIN"
  154. );
  155. // On connecte bob
  156. $this->disconnectUser();
  157. $this->connectUser('bob', 'toor');
  158. // Sur la page de modération d'élément on peux voir l'élément dans la liste
  159. $this->crawler = $this->client->request('GET', $this->generateUrl('moderate_elements_index'));
  160. $this->isResponseSuccess();
  161. $this->exist('li#mod_element_'.$element_ed->getId());
  162. $this->exist('li#mod_element_'.$element_bab->getId());
  163. // Première action, effectivement le partage ed cox doit être refusé par la modération
  164. $this->crawler = $this->client->request(
  165. 'GET',
  166. $this->generateUrl('moderate_element_delete', array(
  167. 'element_id' => $element_ed->getId()
  168. )),
  169. array(),
  170. array(),
  171. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  172. );
  173. $this->isResponseSuccess();
  174. $response = json_decode($this->client->getResponse()->getContent(), true);
  175. $this->assertEquals($response['status'], 'success');
  176. $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  177. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  178. ;
  179. $this->assertEquals(true, is_null($element_ed));
  180. // Condéquences, le proprio (bux) vois son compteur d'élément modéré augmenter
  181. $this->assertEquals($bux_moderated_element_count+1, $this->getUser('bux')->getModeratedElementCount());
  182. // Le compteur de mauvai signalemetn de paul n'a pas bougé par contre.
  183. $this->assertEquals($paul_bad_reports_count, $this->getUser('paul')->getBadReportCount());
  184. // Ni celui de joelle
  185. $this->assertEquals($joelle_bad_reports_count, $this->getUser('joelle')->getBadReportCount());
  186. // Deuxième action on considère que l'autre élément n'a pas a être refusé
  187. $this->crawler = $this->client->request(
  188. 'GET',
  189. $this->generateUrl('moderate_element_clean', array(
  190. 'element_id' => $element_bab->getId()
  191. )),
  192. array(),
  193. array(),
  194. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  195. );
  196. $this->isResponseSuccess();
  197. $response = json_decode($this->client->getResponse()->getContent(), true);
  198. $this->assertEquals($response['status'], 'success');
  199. $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  200. ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
  201. ;
  202. $this->assertEquals(false, is_null($element_bab));
  203. $this->assertEquals($element_bab->getCountReport(), 0);
  204. $this->assertEquals($element_bab->getReportIds(), null);
  205. // Condéquences, le proprio (bux) ne vois pas son compteur d'élément modéré augmenter encore
  206. // +1 car c'est pour la modo juste avant
  207. $this->assertEquals($bux_moderated_element_count+1, $this->getUser('bux')->getModeratedElementCount());
  208. // Le compteur de mauvais signalemetn de paul a augmenter d'un
  209. $this->assertEquals($paul_bad_reports_count+1, $this->getUser('paul')->getBadReportCount());
  210. // Celui de joelle non, elle n'a rien a voir avec ce signalement
  211. $this->assertEquals($joelle_bad_reports_count, $this->getUser('joelle')->getBadReportCount());
  212. }
  213. /**
  214. * Test du signalement de commentaires non appropriés
  215. * Puis de leurs modérations
  216. */
  217. public function testCommentAlertAndModerate()
  218. {
  219. // Première chose: dans ce test on a besoin de tester la modération.
  220. // Du coup bux doit être promus admin
  221. $this->client = self::createClient();
  222. $output = $this->runCommand(
  223. $this->client,
  224. "fos:user:promote bux ROLE_ADMIN"
  225. );
  226. /**
  227. * Scénario: joelle signale deux commentaires: un de bux et un de paul
  228. * sur l'élément d'ed cox.
  229. * En moderation
  230. * * un commentaire (bux) est effectivement refusé:
  231. * Le compteur de mauvaise attitude augmente
  232. * * un commentaire (paul) est considéré comme ok, le compteur (faux signalement)
  233. * de joelle s'incrémente de 1.
  234. */
  235. $em = $this->client->getKernel()->getContainer()->get('doctrine')->getEntityManager();
  236. $this->connectUser('joelle', 'toor');
  237. $joelle = $this->getUser();
  238. $joelle_fake_alerts = $joelle->getBadReportCount();
  239. $bux_moderated_element_count = $this->getUser('bux')->getModeratedCommentCount();
  240. $paul_moderated_element_count = $this->getUser('paul')->getModeratedCommentCount();
  241. // On récupère les deux commentaires
  242. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  243. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  244. ;
  245. $cm = new CommentsManager($element->getComments());
  246. $comment_bux = $cm->get(0);
  247. $comment_paul = $cm->get(1);
  248. // En base rien n'a encore été touché
  249. $this->assertEquals(0, $cm->countCommentAlert());
  250. $this->assertEquals(null, $element->getCountCommentReport());
  251. // joelle signale deux éléments
  252. $this->crawler = $this->client->request(
  253. 'GET',
  254. $this->generateUrl('ajax_alert_comment', array(
  255. 'element_id' => $element->getId(),
  256. 'date' => $comment_bux['d'],
  257. 'token' => $joelle->getPersonalHash()
  258. )),
  259. array(),
  260. array(),
  261. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  262. );
  263. $this->isResponseSuccess();
  264. $response = json_decode($this->client->getResponse()->getContent(), true);
  265. $this->assertEquals($response['status'], 'success');
  266. // Les données en bases ont évolués
  267. // On récupère les deux commentaires
  268. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  269. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  270. ;
  271. $cm = new CommentsManager($element->getComments());
  272. $comment_bux = $cm->get(0);
  273. $comment_paul = $cm->get(1);
  274. $this->assertEquals(1, $cm->countCommentAlert());
  275. $this->assertEquals(1, $element->getCountCommentReport());
  276. // deuxième signalement
  277. $this->crawler = $this->client->request(
  278. 'GET',
  279. $this->generateUrl('ajax_alert_comment', array(
  280. 'element_id' => $element->getId(),
  281. 'date' => $comment_paul['d'],
  282. 'token' => $joelle->getPersonalHash()
  283. )),
  284. array(),
  285. array(),
  286. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  287. );
  288. $this->isResponseSuccess();
  289. $response = json_decode($this->client->getResponse()->getContent(), true);
  290. $this->assertEquals($response['status'], 'success');
  291. // Les données en bases ont évolués
  292. // On récupère les deux commentaires
  293. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  294. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  295. ;
  296. $cm = new CommentsManager($element->getComments());
  297. $comment_bux = $cm->get(0);
  298. $comment_paul = $cm->get(1);
  299. $this->assertEquals(2, $cm->countCommentAlert());
  300. $this->assertEquals(2, $element->getCountCommentReport());
  301. /**
  302. * On passe maintenant a la modération
  303. */
  304. $this->disconnectUser();
  305. $this->connectUser('bux', 'toor');
  306. $bux = $this->getUser();
  307. // bux ouvre la page de modération des commentaires
  308. $this->crawler = $this->client->request('GET', $this->generateUrl('moderate_comments_index'));
  309. $this->isResponseSuccess();
  310. // On voit les deux commentaires signalés dans la liste
  311. $this->exist('li.comment:contains("C\'est trop bon hein ?")');
  312. $this->exist('li.comment:contains("C\'est pas mal en effet")');
  313. // Refus de celui de bux
  314. $this->crawler = $this->client->request(
  315. 'GET',
  316. $this->generateUrl('moderate_comment_refuse', array(
  317. 'element_id' => $element->getId(),
  318. 'date' => $comment_bux['d']
  319. )),
  320. array(),
  321. array(),
  322. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  323. );
  324. $this->isResponseSuccess();
  325. $response = json_decode($this->client->getResponse()->getContent(), true);
  326. $this->assertEquals($response['status'], 'success');
  327. // Le compteur de mauvais comportement de bux a été incrémenté
  328. $this->assertEquals($bux_moderated_element_count+1, $this->getUser('bux')->getModeratedCommentCount());
  329. $joelle = $this->getUser('joelle');
  330. // Le compteur de faux signalement de joelle ne bouge pas.
  331. $this->assertEquals($joelle_fake_alerts, $joelle->getBadReportCount());
  332. // la base est a jour
  333. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  334. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  335. ;
  336. $cm = new CommentsManager($element->getComments());
  337. $this->assertEquals(1, $cm->countCommentAlert());
  338. $this->assertEquals(1, $element->getCountCommentReport());
  339. // Clean de celui de paul
  340. $this->crawler = $this->client->request(
  341. 'GET',
  342. $this->generateUrl('moderate_comment_clean', array(
  343. 'element_id' => $element->getId(),
  344. 'date' => $comment_paul['d']
  345. )),
  346. array(),
  347. array(),
  348. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  349. );
  350. $this->isResponseSuccess();
  351. $response = json_decode($this->client->getResponse()->getContent(), true);
  352. $this->assertEquals($response['status'], 'success');
  353. // la base est a jour
  354. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  355. ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
  356. ;
  357. $cm = new CommentsManager($element->getComments());
  358. $this->assertEquals(0, $cm->countCommentAlert());
  359. $this->assertEquals(0, $element->getCountCommentReport());
  360. // Mais comme joelle a signalé un commentaire considéré comme ok par la modération
  361. // joelle vois son compteur de faux signalement incrémenté
  362. $joelle = $this->getUser('joelle');
  363. $this->assertEquals($joelle_fake_alerts+1, $joelle->getBadReportCount());
  364. // Le compteur de mauvais comportement de paul n'a pas bougé
  365. $this->assertEquals($paul_moderated_element_count, $this->getUser('paul')->getModeratedCommentCount());
  366. // Et si on se rend sur la page home, le commentaire de bux a disparu
  367. $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
  368. $this->exist('li.comment:contains("C\'est pas mal en effet")');
  369. $this->notExist('li.comment:contains("C\'est trop bon hein ?")');
  370. }
  371. /**
  372. * Test de la moderation de tag
  373. */
  374. public function testTagModerated()
  375. {
  376. // bux sera admin
  377. $this->client = self::createClient();
  378. $output = $this->runCommand(
  379. $this->client,
  380. "fos:user:promote bux ROLE_ADMIN"
  381. );
  382. $bux = $this->getUser('bux');
  383. $paul = $this->getUser('paul');
  384. $joelle = $this->getUser('joelle');
  385. $paul_moderated_tags_count = $paul->getModeratedTagCount();
  386. $joelle_moderated_tags_count = $joelle->getModeratedTagCount();
  387. $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
  388. $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
  389. // On ajoute quelques tags avec joelle et paul
  390. $this->connectUser('paul', 'toor');
  391. $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'),
  392. array('tag_name' => 'Tag0001'), array(), array(
  393. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  394. ));
  395. $this->isResponseSuccess();
  396. $Tag0001 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0001');
  397. // Avec ce tag il ajoute un élément
  398. /*
  399. * Ajout d'un élément avec succés
  400. */
  401. $this->procedure_add_element(
  402. 'Lelement de tag0001',
  403. 'http://unsite.fr/blaaaaa1',
  404. array($Tag0001->getId()),
  405. null, true
  406. );
  407. $this->isResponseRedirection();
  408. $this->followRedirection();
  409. $this->isResponseSuccess();
  410. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  411. ->findOneByName('Lelement de tag0001')
  412. ;
  413. $this->assertEquals(json_encode(array((int)$Tag0001->getId())), $element->getTagsIdsJson());
  414. $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'),
  415. array('tag_name' => 'Tag0000'), array(), array(
  416. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  417. ));
  418. $this->isResponseSuccess();
  419. $Tag0000 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0000');
  420. // On teste déjà dans d'autre test la présence des champs permettant de montrer qu'il est
  421. // a modérer.
  422. /*
  423. * Ajout d'un élément avec succés
  424. */
  425. $this->procedure_add_element(
  426. 'Lelement de tag0000',
  427. 'http://unsite.fr/blaaaaa0',
  428. array($Tag0000->getId()),
  429. null, true
  430. );
  431. $this->isResponseRedirection();
  432. $this->followRedirection();
  433. $this->isResponseSuccess();
  434. $this->disconnectUser();
  435. $this->connectUser('joelle', 'toor');
  436. $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'),
  437. array('tag_name' => 'Tag0002'), array(), array(
  438. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  439. ));
  440. $this->isResponseSuccess();
  441. $Tag0002 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0002');
  442. /*
  443. * Ajout d'un élément avec succés
  444. */
  445. $this->procedure_add_element(
  446. 'Lelement de tag0002',
  447. 'http://unsite.fr/blaaaaa2',
  448. array($Tag0002->getId()),
  449. null, true
  450. );
  451. $this->isResponseRedirection();
  452. $this->followRedirection();
  453. $this->isResponseSuccess();
  454. $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'),
  455. array('tag_name' => 'Tag0000'), array(), array(
  456. 'HTTP_X-Requested-With' => 'XMLHttpRequest',
  457. ));
  458. $this->isResponseSuccess();
  459. $Tag0000 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0000');
  460. $this->disconnectUser();
  461. $this->connectUser('bux', 'toor');
  462. // On se rend sur la page de moderation des tags
  463. $this->crawler = $this->client->request('GET', $this->generateUrl('MuzichAdminBundle_moderate_tags'));
  464. // On peux voir les tags
  465. $this->exist('li.tag:contains("Tag0000")');
  466. $this->exist('li.tag:contains("Tag0001")');
  467. $this->exist('li.tag:contains("Tag0002")');
  468. /*
  469. * Etapes:
  470. *
  471. * On refuse Tag0000
  472. * => L'élément lié a ce tag ne l'a plus
  473. * => Le ou les users qui l'on demandé sont incrementé
  474. * On accepte Tag0001
  475. * => L'élément lié a ce tag l'a toujours
  476. * On remplace Tag0002 par tribe
  477. * => L'élément lié a ce tag a le nouveau
  478. * => Les users qui l'ont demandé ne sont pas pénalisés
  479. */
  480. // On refuse Tag0000
  481. $this->crawler = $this->client->request(
  482. 'GET',
  483. $this->generateUrl('MuzichAdminBundle_moderate_tags_refuse_tag', array(
  484. 'tag_id' => $Tag0000->getId()
  485. )),
  486. array(),
  487. array(),
  488. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  489. );
  490. $this->isResponseSuccess();
  491. // Le tag n'est plus
  492. $Tag0000 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0000');
  493. $this->assertEquals(true, is_null($Tag0000));
  494. // L'élément ne dois plus l'avoir comme tag
  495. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  496. ->findOneByName('Lelement de tag0000')
  497. ;
  498. $this->assertEquals('[]', $element->getTagsIdsJson());
  499. // les utilisateurs ayant demandé ce tag ont été pénalisés
  500. $this->assertEquals($paul_moderated_tags_count+1, $this->getUser('paul')->getModeratedTagCount());
  501. $this->assertEquals($joelle_moderated_tags_count+1, $this->getUser('joelle')->getModeratedTagCount());
  502. // On accepte Tag0001
  503. $this->crawler = $this->client->request(
  504. 'GET',
  505. $this->generateUrl('MuzichAdminBundle_moderate_tags_accept_tag', array(
  506. 'tag_id' => $Tag0001->getId()
  507. )),
  508. array(),
  509. array(),
  510. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  511. );
  512. $this->isResponseSuccess();
  513. // Le tag est toujours
  514. $Tag0001 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0001');
  515. $this->assertEquals(false, is_null($Tag0001));
  516. // Mais n'est plus "a modérer"
  517. $this->assertEquals(null, $Tag0001->getPrivateids());
  518. // L'élément ne dois plus l'avoir comme tag
  519. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  520. ->findOneByName('Lelement de tag0001')
  521. ;
  522. $this->assertEquals(json_encode(array((int)$Tag0001->getId())), $element->getTagsIdsJson());
  523. // les utilisateurs ayant demandé ne sont pas pénalisés
  524. $this->assertEquals($paul_moderated_tags_count+1, $this->getUser('paul')->getModeratedTagCount());
  525. $this->assertEquals($joelle_moderated_tags_count+1, $this->getUser('joelle')->getModeratedTagCount());
  526. // On remplace le tag Tag0002 par tribe
  527. $this->crawler = $this->client->request(
  528. 'GET',
  529. $this->generateUrl('MuzichAdminBundle_moderate_tags_replace_tag', array(
  530. 'tag_id' => $Tag0002->getId(),
  531. 'tag_new_id' => json_encode(array($tribe->getId()))
  532. )),
  533. array(),
  534. array(),
  535. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  536. );
  537. $this->isResponseSuccess();
  538. // Le tag n'est plus
  539. $Tag0002 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0002');
  540. $this->assertEquals(true, is_null($Tag0002));
  541. // L'élement a tribe comme tag
  542. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  543. ->findOneByName('Lelement de tag0002')
  544. ;
  545. // $this->assertEquals(json_encode(array((int)$tribe->getId())), $element->getTagsIdsJson());
  546. // WARNING;TODO;FIXTHIS: Ce n'est pas normal, en base pas d'enregistrement en plus
  547. // étrange ...
  548. $this->assertEquals(json_encode(array(null,(int)$tribe->getId())), $element->getTagsIdsJson());
  549. // les utilisateurs ayant demandé ne sont pas pénalisés
  550. $this->assertEquals($paul_moderated_tags_count+1, $this->getUser('paul')->getModeratedTagCount());
  551. $this->assertEquals($joelle_moderated_tags_count+1, $this->getUser('joelle')->getModeratedTagCount());
  552. }
  553. }