Browse Source

tests pour Evolution #146

bastien 13 years ago
parent
commit
e1aa842df2
1 changed files with 133 additions and 0 deletions
  1. 133 0
      src/Muzich/CoreBundle/Tests/Controller/ElementControllerTest.php

+ 133 - 0
src/Muzich/CoreBundle/Tests/Controller/ElementControllerTest.php View File

@@ -326,4 +326,137 @@ class ElementControllerTest extends FunctionalTest
326 326
     $this->assertTrue(is_null($element));
327 327
   }
328 328
   
329
+  public function testReportElement()
330
+  {
331
+    $this->client = self::createClient();
332
+    $this->connectUser('paul', 'toor');
333
+    
334
+    $paul = $this->getUser();
335
+    
336
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
337
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
338
+    ;
339
+    
340
+    // Paul signale cet élément comme pas bien
341
+    $url = $this->generateUrl('ajax_report_element', array(
342
+      'element_id' => $element->getId(),
343
+      'token'      => $paul->getPersonalHash()
344
+    ));
345
+    
346
+    $crawler = $this->client->request(
347
+      'GET', 
348
+      $url, 
349
+      array(), 
350
+      array(), 
351
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
352
+    );
353
+    
354
+    $this->isResponseSuccess();
355
+    
356
+    $response = json_decode($this->client->getResponse()->getContent(), true);
357
+    $this->assertEquals($response['status'], 'success');
358
+    
359
+    // On check en base
360
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
361
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
362
+    ;
363
+    
364
+    $this->assertEquals($element->getCountReport(), 1);
365
+    $this->assertEquals($element->getReportIds(), array((string)$paul->getId()));
366
+    
367
+    // Si il effectue le signalement une deuxième fois sur le même element
368
+    // Ca ne doit pas bouger puisqu'il l'a déjà fait
369
+    $url = $this->generateUrl('ajax_report_element', array(
370
+      'element_id' => $element->getId(),
371
+      'token'      => $paul->getPersonalHash()
372
+    ));
373
+    
374
+    $crawler = $this->client->request(
375
+      'GET', 
376
+      $url, 
377
+      array(), 
378
+      array(), 
379
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
380
+    );
381
+    
382
+    $this->isResponseSuccess();
383
+    
384
+    $response = json_decode($this->client->getResponse()->getContent(), true);
385
+    $this->assertEquals($response['status'], 'success');
386
+    
387
+    // On check en base
388
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
389
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
390
+    ;
391
+    
392
+    $this->assertEquals($element->getCountReport(), 1);
393
+    $this->assertEquals($element->getReportIds(), array((string)$paul->getId()));
394
+    
395
+    $this->disconnectUser();
396
+    // On connecte joelle pour faire le même test sur le même élément
397
+    $this->connectUser('joelle', 'toor');
398
+    
399
+    $joelle = $this->getUser();
400
+    
401
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
402
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
403
+    ;
404
+    
405
+    // Paul signale cet élément comme pas bien
406
+    $url = $this->generateUrl('ajax_report_element', array(
407
+      'element_id' => $element->getId(),
408
+      'token'      => $joelle->getPersonalHash()
409
+    ));
410
+    
411
+    $crawler = $this->client->request(
412
+      'GET', 
413
+      $url, 
414
+      array(), 
415
+      array(), 
416
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
417
+    );
418
+    
419
+    $this->isResponseSuccess();
420
+    
421
+    $response = json_decode($this->client->getResponse()->getContent(), true);
422
+    $this->assertEquals($response['status'], 'success');
423
+    
424
+    // On check en base
425
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
426
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
427
+    ;
428
+    
429
+    $this->assertEquals($element->getCountReport(), 2);
430
+    $this->assertEquals($element->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
431
+    
432
+    // Si il effectue le signalement une deuxième fois sur le même element
433
+    // Ca ne doit pas bouger puisqu'il l'a déjà fait
434
+    $url = $this->generateUrl('ajax_report_element', array(
435
+      'element_id' => $element->getId(),
436
+      'token'      => $joelle->getPersonalHash()
437
+    ));
438
+    
439
+    $crawler = $this->client->request(
440
+      'GET', 
441
+      $url, 
442
+      array(), 
443
+      array(), 
444
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
445
+    );
446
+    
447
+    $this->isResponseSuccess();
448
+    
449
+    $response = json_decode($this->client->getResponse()->getContent(), true);
450
+    $this->assertEquals($response['status'], 'success');
451
+    
452
+    // On check en base
453
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
454
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
455
+    ;
456
+    
457
+    $this->assertEquals($element->getCountReport(), 2);
458
+    $this->assertEquals($element->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
459
+    
460
+  }
461
+  
329 462
 }