Browse Source

Evolution #149: Notation

bastien 13 years ago
parent
commit
3b3502dd22

+ 21 - 6
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementData.php View File

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
     $element = new Element();
44
     $element = new Element();
45
     $element->setName(ucfirst($name));
45
     $element->setName(ucfirst($name));
61
       $element->addTag($tag);
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
     $element->setComments($comments);
72
     $element->setComments($comments);
65
     
73
     
66
     $this->entity_manager->persist($element);
74
     $this->entity_manager->persist($element);
193
     $this->createElement('beatbox_1', 'Dubstep Beatbox', 
201
     $this->createElement('beatbox_1', 'Dubstep Beatbox', 
194
       'http://www.dailymotion.com/video/xm5omz_dubstep-beatbox_creation', 
202
       'http://www.dailymotion.com/video/xm5omz_dubstep-beatbox_creation', 
195
       $this->getArrayOfTag(array('dubstep', 'beatbox')),
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
     $this->createElement('soulfly_1', 'SOULFLY - Prophecy', 
209
     $this->createElement('soulfly_1', 'SOULFLY - Prophecy', 
200
       'http://www.youtube.com/watch?v=zCc_jLctZkA', 
210
       'http://www.youtube.com/watch?v=zCc_jLctZkA', 
201
       $this->getArrayOfTag(array('metal')),
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
     $cm = new CommentsManager();
217
     $cm = new CommentsManager();
211
       'http://www.youtube.com/watch?v=8AXhRXAt2E4', 
223
       'http://www.youtube.com/watch?v=8AXhRXAt2E4', 
212
       $this->getArrayOfTag(array('metal')),
224
       $this->getArrayOfTag(array('metal')),
213
       'youtube.com', $bux, null, $this->dateD(182),
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
     $cm = new CommentsManager();
230
     $cm = new CommentsManager();
233
       'http://www.youtube.com/watch?v=XWkbaHxRvds&feature=related', 
246
       'http://www.youtube.com/watch?v=XWkbaHxRvds&feature=related', 
234
       $this->getArrayOfTag(array('metal', 'hardcore')),
247
       $this->getArrayOfTag(array('metal', 'hardcore')),
235
       'youtube.com', $bux, null, $this->dateD(181),
248
       'youtube.com', $bux, null, $this->dateD(181),
236
-      $cm->get()
249
+      $cm->get(),
250
+      array($bob->getId())
237
     );
251
     );
238
     
252
     
239
     $cm = new CommentsManager();
253
     $cm = new CommentsManager();
244
       'http://www.youtube.com/watch?v=Lk1gnh-JCDs&feature=related', 
258
       'http://www.youtube.com/watch?v=Lk1gnh-JCDs&feature=related', 
245
       $this->getArrayOfTag(array('electro')),
259
       $this->getArrayOfTag(array('electro')),
246
       'youtube.com', $bux, null, $this->dateD(180),
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 View File

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
 }