bastien пре 13 година
родитељ
комит
3b3502dd22

+ 21 - 6
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementData.php Прегледај датотеку

@@ -39,7 +39,7 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
39 39
   /**
40 40
    *  
41 41
    */
42
-  protected function createElement($reference_id, $name, $url, $tags, $type, $owner, $group = null, $date = null, $comments = null)
42
+  protected function createElement($reference_id, $name, $url, $tags, $type, $owner, $group = null, $date = null, $comments = null, $vote_ids = array())
43 43
   {    
44 44
     $element = new Element();
45 45
     $element->setName(ucfirst($name));
@@ -61,6 +61,14 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
61 61
       $element->addTag($tag);
62 62
     }
63 63
     
64
+    if (count($vote_ids))
65
+    {
66
+      foreach ($vote_ids as $id)
67
+      {
68
+        $element->addVoteGood($id);
69
+      }
70
+    }
71
+    
64 72
     $element->setComments($comments);
65 73
     
66 74
     $this->entity_manager->persist($element);
@@ -193,13 +201,17 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
193 201
     $this->createElement('beatbox_1', 'Dubstep Beatbox', 
194 202
       'http://www.dailymotion.com/video/xm5omz_dubstep-beatbox_creation', 
195 203
       $this->getArrayOfTag(array('dubstep', 'beatbox')),
196
-      'dailymotion.com', $joelle, null, $this->dateD(184)
204
+      'dailymotion.com', $joelle, null, $this->dateD(184),
205
+      null,
206
+      array($bux->getId(), $jean->getId(), $bux->getId())
197 207
     );
198 208
     
199 209
     $this->createElement('soulfly_1', 'SOULFLY - Prophecy', 
200 210
       'http://www.youtube.com/watch?v=zCc_jLctZkA', 
201 211
       $this->getArrayOfTag(array('metal')),
202
-      'youtube.com', $bux, null, $this->dateD(183)
212
+      'youtube.com', $bux, null, $this->dateD(183),
213
+      null,
214
+      array($paul->getId())
203 215
     );
204 216
     
205 217
     $cm = new CommentsManager();
@@ -211,7 +223,8 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
211 223
       'http://www.youtube.com/watch?v=8AXhRXAt2E4', 
212 224
       $this->getArrayOfTag(array('metal')),
213 225
       'youtube.com', $bux, null, $this->dateD(182),
214
-      $cm->get()
226
+      $cm->get(),
227
+      array($bob->getId(), $jean->getId(), $joelle->getId())
215 228
     );
216 229
     
217 230
     $cm = new CommentsManager();
@@ -233,7 +246,8 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
233 246
       'http://www.youtube.com/watch?v=XWkbaHxRvds&feature=related', 
234 247
       $this->getArrayOfTag(array('metal', 'hardcore')),
235 248
       'youtube.com', $bux, null, $this->dateD(181),
236
-      $cm->get()
249
+      $cm->get(),
250
+      array($bob->getId())
237 251
     );
238 252
     
239 253
     $cm = new CommentsManager();
@@ -244,7 +258,8 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
244 258
       'http://www.youtube.com/watch?v=Lk1gnh-JCDs&feature=related', 
245 259
       $this->getArrayOfTag(array('electro')),
246 260
       'youtube.com', $bux, null, $this->dateD(180),
247
-      $cm->get()
261
+      $cm->get(),
262
+      array($joelle->getId(), $jean->getId())
248 263
     );
249 264
     
250 265
 

+ 132 - 0
src/Muzich/CoreBundle/Tests/Controller/ElementControllerTest.php Прегледај датотеку

@@ -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
 }