|
@@ -207,4 +207,186 @@ class CommentControllerTest extends FunctionalTest
|
207
|
207
|
$this->assertEquals($response['status'], 'error');
|
208
|
208
|
}
|
209
|
209
|
|
|
210
|
+ /**
|
|
211
|
+ * Test du signalement de commentaires non appropriés
|
|
212
|
+ * Puis de leurs modérations
|
|
213
|
+ */
|
|
214
|
+ public function testAlertAndModerate()
|
|
215
|
+ {
|
|
216
|
+ // Première chose: dans ce test on a besoin de tester la modération.
|
|
217
|
+ // Du coup bux doit être promus admin
|
|
218
|
+ $this->client = self::createClient();
|
|
219
|
+ $output = $this->runCommand(
|
|
220
|
+ $this->client,
|
|
221
|
+ "fos:user:promote bux ROLE_ADMIN"
|
|
222
|
+ );
|
|
223
|
+
|
|
224
|
+ /**
|
|
225
|
+ * Scénario: joelle signale deux commentaires: un de bux et un de paul
|
|
226
|
+ * sur l'élément d'ed cox.
|
|
227
|
+ * En moderation
|
|
228
|
+ * * un commentaire (bux) est effectivement refusé:
|
|
229
|
+ * (TODO dans le code) Le compteur de mauvaise attitude augmente
|
|
230
|
+ * * un commentaire (paul) est considéré comme ok, le compteur (faux signalement)
|
|
231
|
+ * de joelle s'incrémente de 1.
|
|
232
|
+ */
|
|
233
|
+
|
|
234
|
+ $em = $this->client->getKernel()->getContainer()->get('doctrine')->getEntityManager();
|
|
235
|
+ $this->connectUser('joelle', 'toor');
|
|
236
|
+ $joelle = $this->getUser();
|
|
237
|
+ $joelle_fake_alerts = $joelle->getBadReportCount();
|
|
238
|
+
|
|
239
|
+ // On récupère les deux commentaires
|
|
240
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
241
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
242
|
+ ;
|
|
243
|
+ $cm = new CommentsManager($element->getComments());
|
|
244
|
+ $comment_bux = $cm->get(0);
|
|
245
|
+ $comment_paul = $cm->get(1);
|
|
246
|
+
|
|
247
|
+ // En base rien n'a encore été touché
|
|
248
|
+ $this->assertEquals(0, $cm->countCommentAlert());
|
|
249
|
+ $this->assertEquals(null, $element->getCountCommentReport());
|
|
250
|
+
|
|
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
|
+
|
|
264
|
+ $this->isResponseSuccess();
|
|
265
|
+
|
|
266
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
267
|
+ $this->assertEquals($response['status'], 'success');
|
|
268
|
+
|
|
269
|
+ // Les données en bases ont évolués
|
|
270
|
+ // On récupère les deux commentaires
|
|
271
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
272
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
273
|
+ ;
|
|
274
|
+ $cm = new CommentsManager($element->getComments());
|
|
275
|
+ $comment_bux = $cm->get(0);
|
|
276
|
+ $comment_paul = $cm->get(1);
|
|
277
|
+
|
|
278
|
+ $this->assertEquals(1, $cm->countCommentAlert());
|
|
279
|
+ $this->assertEquals(1, $element->getCountCommentReport());
|
|
280
|
+
|
|
281
|
+ // deuxième signalement
|
|
282
|
+ $this->crawler = $this->client->request(
|
|
283
|
+ 'GET',
|
|
284
|
+ $this->generateUrl('ajax_alert_comment', array(
|
|
285
|
+ 'element_id' => $element->getId(),
|
|
286
|
+ 'date' => $comment_paul['d'],
|
|
287
|
+ 'token' => $joelle->getPersonalHash()
|
|
288
|
+ )),
|
|
289
|
+ array(),
|
|
290
|
+ array(),
|
|
291
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
292
|
+ );
|
|
293
|
+
|
|
294
|
+ $this->isResponseSuccess();
|
|
295
|
+
|
|
296
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
297
|
+ $this->assertEquals($response['status'], 'success');
|
|
298
|
+
|
|
299
|
+ // Les données en bases ont évolués
|
|
300
|
+ // On récupère les deux commentaires
|
|
301
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
302
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
303
|
+ ;
|
|
304
|
+ $cm = new CommentsManager($element->getComments());
|
|
305
|
+ $comment_bux = $cm->get(0);
|
|
306
|
+ $comment_paul = $cm->get(1);
|
|
307
|
+
|
|
308
|
+ $this->assertEquals(2, $cm->countCommentAlert());
|
|
309
|
+ $this->assertEquals(2, $element->getCountCommentReport());
|
|
310
|
+
|
|
311
|
+ /**
|
|
312
|
+ * On passe maintenant a la modération
|
|
313
|
+ */
|
|
314
|
+
|
|
315
|
+ $this->disconnectUser();
|
|
316
|
+ $this->connectUser('bux', 'toor');
|
|
317
|
+ $bux = $this->getUser();
|
|
318
|
+
|
|
319
|
+ // bux ouvre la page de modération des commentaires
|
|
320
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('moderate_comments_index'));
|
|
321
|
+
|
|
322
|
+ // On voit les deux commentaires signalés dans la liste
|
|
323
|
+ $this->exist('li.comment:contains("C\'est trop bon hein ?")');
|
|
324
|
+ $this->exist('li.comment:contains("C\'est pas mal en effet")');
|
|
325
|
+
|
|
326
|
+ // Refus de celui de bux
|
|
327
|
+ $this->crawler = $this->client->request(
|
|
328
|
+ 'GET',
|
|
329
|
+ $this->generateUrl('moderate_comment_refuse', array(
|
|
330
|
+ 'element_id' => $element->getId(),
|
|
331
|
+ 'date' => $comment_bux['d']
|
|
332
|
+ )),
|
|
333
|
+ array(),
|
|
334
|
+ array(),
|
|
335
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
336
|
+ );
|
|
337
|
+
|
|
338
|
+ $this->isResponseSuccess();
|
|
339
|
+
|
|
340
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
341
|
+ $this->assertEquals($response['status'], 'success');
|
|
342
|
+
|
|
343
|
+ // TODO: check du compteur de mauvais comportements de bux
|
|
344
|
+
|
|
345
|
+ // la base est a jour
|
|
346
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
347
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
348
|
+ ;
|
|
349
|
+ $cm = new CommentsManager($element->getComments());
|
|
350
|
+
|
|
351
|
+ $this->assertEquals(1, $cm->countCommentAlert());
|
|
352
|
+ $this->assertEquals(1, $element->getCountCommentReport());
|
|
353
|
+
|
|
354
|
+ // Clean de celui de paul
|
|
355
|
+ $this->crawler = $this->client->request(
|
|
356
|
+ 'GET',
|
|
357
|
+ $this->generateUrl('moderate_comment_clean', array(
|
|
358
|
+ 'element_id' => $element->getId(),
|
|
359
|
+ 'date' => $comment_paul['d']
|
|
360
|
+ )),
|
|
361
|
+ array(),
|
|
362
|
+ array(),
|
|
363
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
364
|
+ );
|
|
365
|
+
|
|
366
|
+ $this->isResponseSuccess();
|
|
367
|
+
|
|
368
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
369
|
+ $this->assertEquals($response['status'], 'success');
|
|
370
|
+
|
|
371
|
+ // la base est a jour
|
|
372
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
373
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
374
|
+ ;
|
|
375
|
+ $cm = new CommentsManager($element->getComments());
|
|
376
|
+
|
|
377
|
+ $this->assertEquals(0, $cm->countCommentAlert());
|
|
378
|
+ $this->assertEquals(0, $element->getCountCommentReport());
|
|
379
|
+
|
|
380
|
+ // Mais comme joelle a signalé un commentaire considéré comme ok par la modération
|
|
381
|
+ // joelle vois son compteur de faux signalement incrémenté
|
|
382
|
+ $joelle = $this->getUser('joelle');
|
|
383
|
+ $this->assertEquals($joelle_fake_alerts+1, $joelle->getBadReportCount());
|
|
384
|
+
|
|
385
|
+ // Et si on se rend sur la page home, le commentaire de bux a disparu
|
|
386
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
|
|
387
|
+
|
|
388
|
+ $this->exist('li.comment:contains("C\'est pas mal en effet")');
|
|
389
|
+ $this->notExist('li.comment:contains("C\'est trop bon hein ?")');
|
|
390
|
+ }
|
|
391
|
+
|
210
|
392
|
}
|