|
@@ -459,4 +459,136 @@ class ElementControllerTest extends FunctionalTest
|
459
|
459
|
|
460
|
460
|
}
|
461
|
461
|
|
|
462
|
+ /**
|
|
463
|
+ * Procédure de vote
|
|
464
|
+ */
|
|
465
|
+ public function testVote()
|
|
466
|
+ {
|
|
467
|
+ $this->client = self::createClient();
|
|
468
|
+ $this->connectUser('paul', 'toor');
|
|
469
|
+
|
|
470
|
+ $paul = $this->getUser();
|
|
471
|
+ $joelle = $this->getUser('joelle');
|
|
472
|
+ $jean = $this->getUser('jean');
|
|
473
|
+
|
|
474
|
+ // D'après les fixtures, un des élément porte le vote de paul
|
|
475
|
+ $element_soul = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
476
|
+ ->findOneByName('SOULFLY - Prophecy')
|
|
477
|
+ ;
|
|
478
|
+
|
|
479
|
+ // On peut donc voir le lien pour "dé-voter"
|
|
480
|
+ $url_unvote_soul = $this->generateUrl('ajax_element_remove_vote_good', array(
|
|
481
|
+ 'element_id' => $element_soul->getId(),
|
|
482
|
+ 'token' => $paul->getPersonalHash()
|
|
483
|
+ ));
|
|
484
|
+ $this->exist('a.vote[href="'.$url_unvote_soul.'"]');
|
|
485
|
+
|
|
486
|
+ // On contrôle le contenu pour cet element
|
|
487
|
+ $this->assertEquals($element_soul->getPoints(), 1);
|
|
488
|
+
|
|
489
|
+ // Et son id est la
|
|
490
|
+ $this->assertEquals($element_soul->getVoteGoodIds(), array(
|
|
491
|
+ (string)$paul->getId()
|
|
492
|
+ ));
|
|
493
|
+
|
|
494
|
+ // On va voter pour un element a bux
|
|
495
|
+ $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
496
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
497
|
+ ;
|
|
498
|
+
|
|
499
|
+ // Actuellement (fixtures) son score est de 2
|
|
500
|
+ $this->assertEquals($element_ed->getPoints(), 2);
|
|
501
|
+
|
|
502
|
+ // Et ce sont (fixtures) ces deux user qui ont voté
|
|
503
|
+ $this->assertEquals($element_ed->getVoteGoodIds(), array((string)$joelle->getId(), (string)$jean->getId()));
|
|
504
|
+
|
|
505
|
+ // paul va voter egallement
|
|
506
|
+ $crawler = $this->client->request(
|
|
507
|
+ 'GET',
|
|
508
|
+ $this->generateUrl('ajax_element_add_vote_good', array(
|
|
509
|
+ 'element_id' => $element_ed->getId(),
|
|
510
|
+ 'token' => $paul->getPersonalHash()
|
|
511
|
+ )),
|
|
512
|
+ array(),
|
|
513
|
+ array(),
|
|
514
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
515
|
+ );
|
|
516
|
+
|
|
517
|
+ $this->isResponseSuccess();
|
|
518
|
+
|
|
519
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
520
|
+ $this->assertEquals($response['status'], 'success');
|
|
521
|
+
|
|
522
|
+ // On recontrôle l'élément voir si tout a été enregistré
|
|
523
|
+ $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
524
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
525
|
+ ;
|
|
526
|
+
|
|
527
|
+ // Son score est mainteannt de 3
|
|
528
|
+ $this->assertEquals($element_ed->getPoints(), 3);
|
|
529
|
+
|
|
530
|
+ // Et son id est la
|
|
531
|
+ $this->assertEquals($element_ed->getVoteGoodIds(), array(
|
|
532
|
+ (string)$joelle->getId(),
|
|
533
|
+ (string)$jean->getId(),
|
|
534
|
+ (string)$paul->getId()
|
|
535
|
+ ));
|
|
536
|
+
|
|
537
|
+ // Pau retire son vote de soulfy
|
|
538
|
+ $crawler = $this->client->request(
|
|
539
|
+ 'GET',
|
|
540
|
+ $url_unvote_soul,
|
|
541
|
+ array(),
|
|
542
|
+ array(),
|
|
543
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
544
|
+ );
|
|
545
|
+
|
|
546
|
+ $element_soul = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
547
|
+ ->findOneByName('SOULFLY - Prophecy')
|
|
548
|
+ ;
|
|
549
|
+ // On contrôle le contenu pour cet element
|
|
550
|
+ $this->assertEquals($element_soul->getPoints(), 0);
|
|
551
|
+
|
|
552
|
+ // Et son id est la
|
|
553
|
+ $this->assertEquals($element_soul->getVoteGoodIds(), array());
|
|
554
|
+
|
|
555
|
+ // On déconnecte paul, pour faire voter bob sur le partage ed cox
|
|
556
|
+ $this->disconnectUser();
|
|
557
|
+ $this->connectUser('bob', 'toor');
|
|
558
|
+
|
|
559
|
+ $bob = $this->getUser();
|
|
560
|
+ // bob va donc votre pour le partage d'ed cox
|
|
561
|
+ $crawler = $this->client->request(
|
|
562
|
+ 'GET',
|
|
563
|
+ $this->generateUrl('ajax_element_add_vote_good', array(
|
|
564
|
+ 'element_id' => $element_ed->getId(),
|
|
565
|
+ 'token' => $bob->getPersonalHash()
|
|
566
|
+ )),
|
|
567
|
+ array(),
|
|
568
|
+ array(),
|
|
569
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
570
|
+ );
|
|
571
|
+
|
|
572
|
+ $this->isResponseSuccess();
|
|
573
|
+
|
|
574
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
575
|
+ $this->assertEquals($response['status'], 'success');
|
|
576
|
+
|
|
577
|
+ // On recontrôle l'élément voir si tout a été enregistré
|
|
578
|
+ $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
579
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
580
|
+ ;
|
|
581
|
+
|
|
582
|
+ // Son score est mainteannt de 3
|
|
583
|
+ $this->assertEquals($element_ed->getPoints(), 4);
|
|
584
|
+
|
|
585
|
+ // Et son id est la
|
|
586
|
+ $this->assertEquals($element_ed->getVoteGoodIds(), array(
|
|
587
|
+ (string)$joelle->getId(),
|
|
588
|
+ (string)$jean->getId(),
|
|
589
|
+ (string)$paul->getId(),
|
|
590
|
+ (string)$bob->getId()
|
|
591
|
+ ));
|
|
592
|
+ }
|
|
593
|
+
|
462
|
594
|
}
|