Browse Source

Evolution #783: Scores Element: favoris, Users playlists

Bastien Sevajol 11 years ago
parent
commit
cdb84cbe29

+ 3 - 1
src/Muzich/CoreBundle/Command/RecalculateReputationCommand.php View File

@@ -184,7 +184,9 @@ class RecalculateReputationCommand extends ContainerAwareCommand
184 184
     
185 185
     foreach ($elements as $element)
186 186
     {
187
-      $element->setPoints($this->getElementScore($element));
187
+      $element_score = $this->getElementScore($element);
188
+      $element->setPoints($element_score);
189
+      $output->writeln('<info>Element "'.$element->getName().'": '.$element_score.' score</info>');
188 190
       $em->persist($element);
189 191
     }
190 192
     

+ 4 - 2
src/Muzich/CoreBundle/Controller/ElementController.php View File

@@ -456,11 +456,12 @@ class ElementController extends Controller
456 456
     }
457 457
     
458 458
     // On ajoute un vote a l'élément
459
-    $element->addVoteGood($this->getUser()->getId());
459
+    $element->addVoteGood($this->getUser()->getId(), $this->container->getParameter('reputation_element_point_value'));
460 460
     // Puis on lance les actions propagés par ce vote
461 461
     $event = new EventElement($this->container);
462 462
     $event->onePointAdded($element);
463 463
     
464
+    $this->getDoctrine()->getManager()->persist($element->getOwner());
464 465
     $this->getDoctrine()->getManager()->persist($element);
465 466
     $this->getDoctrine()->getManager()->flush();
466 467
     
@@ -515,11 +516,12 @@ class ElementController extends Controller
515 516
     }
516 517
     
517 518
     // Retrait du vote good
518
-    $element->removeVoteGood($this->getUser()->getId());
519
+    $element->removeVoteGood($this->getUser()->getId(), $this->container->getParameter('reputation_element_point_value'));
519 520
     // Puis on lance les actions propagés par retrait de vote
520 521
     $event = new EventElement($this->container);
521 522
     $event->onePointRemoved($element);
522 523
     
524
+    $this->getDoctrine()->getManager()->persist($element->getOwner());
523 525
     $this->getDoctrine()->getManager()->persist($element);
524 526
     $this->getDoctrine()->getManager()->flush();
525 527
     

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

@@ -65,7 +65,7 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
65 65
     {
66 66
       foreach ($vote_ids as $id)
67 67
       {
68
-        $element->addVoteGood($id);
68
+        $element->addVoteGood($id, $this->container->getParameter('reputation_element_point_value'));
69 69
       }
70 70
     }
71 71
     

+ 4 - 4
src/Muzich/CoreBundle/Entity/Element.php View File

@@ -865,7 +865,7 @@ class Element
865 865
    * 
866 866
    * @param int $user_id 
867 867
    */
868
-  public function addVoteGood($user_id)
868
+  public function addVoteGood($user_id, $score_action)
869 869
   {
870 870
     $votes = $this->getVoteGoodIds();
871 871
     if (!count($votes))
@@ -876,7 +876,7 @@ class Element
876 876
     if (!$this->hasVoteGood($user_id))
877 877
     {
878 878
       $votes[] = (string)$user_id;
879
-      $this->setPoints(count($votes));
879
+      $this->setPoints($this->getPoints()+$score_action);
880 880
     }
881 881
     $this->setVoteGoodIds($votes);
882 882
   }
@@ -886,7 +886,7 @@ class Element
886 886
    * 
887 887
    * @param int $user_id 
888 888
    */
889
-  public function removeVoteGood($user_id)
889
+  public function removeVoteGood($user_id, $score_action)
890 890
   {
891 891
     if (count($votes = $this->getVoteGoodIds()))
892 892
     {
@@ -899,7 +899,7 @@ class Element
899 899
         }
900 900
       }
901 901
       
902
-      $this->setPoints(count($votes_n));
902
+      $this->setPoints($this->getPoints()-$score_action);
903 903
       $this->setVoteGoodIds($votes_n);
904 904
     }
905 905
   }

+ 2 - 33
src/Muzich/CoreBundle/Propagator/EventElement.php View File

@@ -231,45 +231,14 @@ class EventElement extends EventPropagator
231 231
     $this->container->get('doctrine')->getEntityManager()->persist($proposition->getUser());
232 232
   }
233 233
   
234
-  /**
235
-   * Intervien lorsque l'évènement est supprimé.
236
-   * Il doit retirer au propriétaire:
237
-   * * Les points de l'élément
238
-   * * Les points du aux mises en favoris
239
-   * 
240
-   * @param Element $element 
241
-   */
234
+  /** @param Element $element */
242 235
   public function elementRemoved(Element $element)
243 236
   {
244
-    // L'utilisateur n'a plus droits aux points de l'élément.
245 237
     $ur = new UserReputation($element->getOwner());
238
+    
246 239
     $ur->removePoints(
247 240
       $element->getPoints() * $this->container->getParameter('reputation_element_point_value')
248 241
     );
249
-    
250
-    // Ni aux points liés aux mises en favoris
251
-    $fav = $this->container->get('doctrine')->getEntityManager()->createQuery(
252
-      "SELECT COUNT(f) FROM MuzichCoreBundle:UsersElementsFavorites f"
253
-      . " JOIN f.element e"
254
-      . " WHERE e.owner = :uid AND f.user != :uid AND e.id = :eid"
255
-    )->setParameters(array(
256
-      'uid' => $element->getOwner()->getId(),
257
-      'eid' => $element->getId()
258
-    ))
259
-     ->getScalarResult()      
260
-    ;
261
-
262
-    if (count($fav))
263
-    {
264
-      if (count($fav[0]))
265
-      {
266
-        $count_favs = $fav[0][1];
267
-        $ur = new UserReputation($element->getOwner());
268
-        $ur->removePoints(
269
-          $count_favs * $this->container->getParameter('reputation_element_favorite_value')
270
-        );
271
-      }
272
-    }
273 242
   }
274 243
   
275 244
 }

+ 332 - 0
src/Muzich/CoreBundle/Tests/Controller/ScoreTest.php View File

@@ -0,0 +1,332 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Tests\Controller;
4
+
5
+use Muzich\CoreBundle\lib\FunctionalTest;
6
+use Muzich\CoreBundle\Tests\lib\Security\ContextTestCases;
7
+
8
+class ScoreTest extends FunctionalTest
9
+{
10
+  
11
+  protected $scores_reference = array(
12
+    'User' => array(
13
+      "admin"  => 0,
14
+      "bux"    => 22,
15
+      "jean"   => 18,
16
+      "paul"   => 14,
17
+      "bob"    => 1,
18
+      "joelle" => 9
19
+    ),
20
+    'Element' => array(
21
+      "Heretik System Popof - Resistance" => 5, 
22
+      "Dtc che passdrop"                  => 0, 
23
+      "Antropod - Polakatek"              => 0, 
24
+      "KoinkOin - H5N1"                   => 0, 
25
+      "DJ FAB"                            => 6, 
26
+      "Dj antoine"                        => 1, 
27
+      "Acrotek Hardtek G01"               => 1, 
28
+      "All Is Full Of Pain"               => 0, 
29
+      "RE-FUCK (ReVeRB_FBC) mix."         => 1, 
30
+      "CardioT3K - Juggernaut Trap"       => 1, 
31
+      "DUDELDRUM"                         => 1, 
32
+      "Infected Mushroom - Psycho"        => 2, 
33
+      "Infected mushroom - Muse Breaks"   => 1, 
34
+      "Cents Pas - Joëlle"                => 2, 
35
+      "Cents Pas - Joëlle (bis)"          => 2, 
36
+      "UKF Dubstep Mix - August "         => 1, 
37
+      "Dubstep Beatbox"                   => 3, 
38
+      "SOULFLY - Prophecy"                => 1, 
39
+      "AZYD AZYLUM Live au Café Provisoire"             => 3, 
40
+      "Babylon Pression - Des Tasers et des Pauvres"    => 1, 
41
+      "Ed Cox - La fanfare des teuffeurs (Hardcordian)" => 2, 
42
+    )
43
+  );
44
+  
45
+  protected function init()
46
+  {
47
+    $this->client = self::createClient();
48
+    $this->tests_cases = new ContextTestCases($this->client, $this);
49
+  }
50
+  
51
+  protected function checkScores()
52
+  {
53
+    foreach ($this->scores_reference as $object_type => $objects_scores)
54
+    {
55
+      foreach ($objects_scores as $name => $score)
56
+      {
57
+        $this->assertEquals($score, $this->getEntityScore($object_type, $name));
58
+      }
59
+    }
60
+  }
61
+  
62
+  protected function getEntityScore($object_type, $name)
63
+  {
64
+    if ($object_type == 'Element')
65
+    {
66
+      return $this->findOneBy('Element', $name)->getPoints();
67
+    }
68
+    if ($object_type == 'User')
69
+    {
70
+      return $this->findUserByUsername($name)->getReputation();
71
+    }
72
+  }
73
+  
74
+  public function testScores()
75
+  {
76
+    $this->init(); 
77
+    $this->checkScores();
78
+    
79
+    $this->checkAddVoteGood();
80
+    $this->checkRemoveVoteGood();
81
+    
82
+    $this->checkAddToFavorites();
83
+    $this->checkRemoveFromFavorites();
84
+    
85
+    $this->checkWithPlaylists();
86
+    $this->checkTagsPropositions();
87
+    $this->checkFollowing();
88
+    $this->checkDeleteElement();
89
+  }
90
+  
91
+  protected function checkAddVoteGood()
92
+  {
93
+    $this->connectUser('paul');
94
+    
95
+    $response = $this->tests_cases->elementAddGoodPoint(
96
+      $this->findOneBy('Element', "Cents Pas - Joëlle (bis)"),
97
+      $this->findUserByUsername('paul'));
98
+    $this->stringResponseIsSuccess($response);
99
+    
100
+    $this->scores_reference['User']['joelle'] += 1;
101
+    $this->scores_reference['Element']['Cents Pas - Joëlle (bis)'] += 1;
102
+    $this->checkScores();
103
+    
104
+    $this->disconnectUser();
105
+  }
106
+  
107
+  protected function stringResponseIsSuccess($response_string)
108
+  {
109
+    $response_array = json_decode($response_string, true);
110
+    $this->assertEquals('success', $response_array['status']);
111
+  }
112
+  
113
+  protected function checkRemoveVoteGood()
114
+  {
115
+    $this->connectUser('paul');
116
+    
117
+    $response = $this->tests_cases->elementRemoveGoodPoint(
118
+      $this->findOneBy('Element', "Cents Pas - Joëlle (bis)"),
119
+      $this->findUserByUsername('paul'));
120
+    $this->stringResponseIsSuccess($response);
121
+    
122
+    $this->scores_reference['User']['joelle'] -= 1;
123
+    $this->scores_reference['Element']['Cents Pas - Joëlle (bis)'] -= 1;
124
+    $this->checkScores();
125
+    
126
+    $this->disconnectUser();
127
+  }
128
+  
129
+  protected function checkAddToFavorites()
130
+  {
131
+    $this->connectUser('paul');
132
+    
133
+    $response = $this->tests_cases->elementAddToFavorites(
134
+      $this->findOneBy('Element', "Cents Pas - Joëlle (bis)"),
135
+      $this->findUserByUsername('paul'));
136
+    $this->stringResponseIsSuccess($response);
137
+    
138
+    $this->scores_reference['User']['joelle'] += 5;
139
+    $this->scores_reference['Element']['Cents Pas - Joëlle (bis)'] += 5;
140
+    $this->checkScores();
141
+    
142
+    $this->disconnectUser();
143
+  }
144
+  
145
+  protected function checkRemoveFromFavorites()
146
+  {
147
+    $this->connectUser('paul');
148
+    
149
+    $response = $this->tests_cases->elementRemoveFromFavorites(
150
+      $this->findOneBy('Element', "Cents Pas - Joëlle (bis)"),
151
+      $this->findUserByUsername('paul'));
152
+    $this->stringResponseIsSuccess($response);
153
+    
154
+    $this->scores_reference['User']['joelle'] -= 5;
155
+    $this->scores_reference['Element']['Cents Pas - Joëlle (bis)'] -= 5;
156
+    $this->checkScores();
157
+    
158
+    $this->disconnectUser();
159
+  }
160
+  
161
+  protected function checkWithPlaylists()
162
+  {
163
+    $this->connectUser('joelle');
164
+    
165
+    $response = $this->tests_cases->playlistCreate(
166
+      $this->findOneBy('Element', "Babylon Pression - Des Tasers et des Pauvres")->getId(),
167
+      "JoellePlaylist:)");
168
+    $this->stringResponseIsSuccess($response);
169
+    
170
+    $this->scores_reference['User']['bux'] += 1;
171
+    $this->scores_reference['Element']['Babylon Pression - Des Tasers et des Pauvres'] += 1;
172
+    $this->checkScores();
173
+    
174
+    $response = $this->tests_cases->playlistCreate(
175
+      $this->findOneBy('Element', "Babylon Pression - Des Tasers et des Pauvres")->getId(),
176
+      "EncoreUnePlaylistAJoelle)");
177
+    $this->stringResponseIsSuccess($response);
178
+    $this->checkScores();
179
+    
180
+    $response = $this->tests_cases->playlistAddElement(
181
+      $this->findOneBy('Playlist', "JoellePlaylist:)")->getId(),
182
+      $this->findOneBy('Element', "Babylon Pression - Des Tasers et des Pauvres")->getId());
183
+    $this->stringResponseIsSuccess($response);
184
+    $this->checkScores();
185
+    
186
+    $response = $this->tests_cases->playlistAddElement(
187
+      $this->findOneBy('Playlist', "JoellePlaylist:)")->getId(),
188
+      $this->findOneBy('Element', "Ed Cox - La fanfare des teuffeurs (Hardcordian)")->getId());
189
+    $this->stringResponseIsSuccess($response);
190
+    
191
+    $this->scores_reference['User']['bux'] += 1;
192
+    $this->scores_reference['Element']['Ed Cox - La fanfare des teuffeurs (Hardcordian)'] += 1;
193
+    $this->checkScores();
194
+    
195
+    $this->disconnectUser();
196
+    $this->connectUser('paul');
197
+    
198
+    $response = $this->tests_cases->playlistCreate(
199
+      $this->findOneBy('Element', "Babylon Pression - Des Tasers et des Pauvres")->getId(),
200
+      "TrololoPaul");
201
+    $this->stringResponseIsSuccess($response);
202
+    
203
+    $this->scores_reference['User']['bux'] += 1;
204
+    $this->scores_reference['Element']['Babylon Pression - Des Tasers et des Pauvres'] += 1;
205
+    $this->checkScores();
206
+    
207
+    $response = $this->tests_cases->playlistRemoveElement(
208
+      $this->findOneBy('Playlist', "TrololoPaul")->getId(),
209
+      0);
210
+    $this->stringResponseIsSuccess($response);
211
+    
212
+    $this->scores_reference['User']['bux'] -= 1;
213
+    $this->scores_reference['Element']['Babylon Pression - Des Tasers et des Pauvres'] -= 1;
214
+    $this->checkScores();
215
+    
216
+    
217
+    $this->disconnectUser();
218
+  }
219
+  
220
+  protected function checkTagsPropositions()
221
+  {
222
+    $this->connectUser('joelle');
223
+    
224
+    $response = $this->tests_cases->elementProposeTags(
225
+      $this->findOneBy('Element', "Ed Cox - La fanfare des teuffeurs (Hardcordian)"),
226
+      $this->findUserByUsername('joelle'),
227
+      array($this->findOneBy('Tag', "Hardtek")->getId()));
228
+    $this->stringResponseIsSuccess($response);
229
+    $this->checkScores();
230
+    
231
+    $this->disconnectUser();
232
+    $this->connectUser('bux');
233
+            
234
+    $response = $this->tests_cases->elementAcceptTagsProposition(
235
+      $this->findUserByUsername('bux'),
236
+      $this->getLastTagsProposition($this->findOneBy('Element', "Ed Cox - La fanfare des teuffeurs (Hardcordian)")));
237
+    $this->stringResponseIsSuccess($response);
238
+    
239
+    $this->scores_reference['User']['joelle'] += 12;
240
+    $this->checkScores();
241
+    
242
+    $this->disconnectUser();
243
+  }
244
+  
245
+  protected function checkFollowing()
246
+  {
247
+    $this->connectUser('joelle');
248
+    
249
+    $response = $this->tests_cases->followUser(
250
+      $this->findUserByUsername('paul')->getId());
251
+    $this->stringResponseIsSuccess($response);
252
+    
253
+    $this->scores_reference['User']['paul'] += 10;
254
+    $this->checkScores();
255
+    
256
+    $response = $this->tests_cases->followUser(
257
+      $this->findUserByUsername('paul')->getId());
258
+    $this->stringResponseIsSuccess($response);
259
+    
260
+    $this->scores_reference['User']['paul'] -= 10;
261
+    $this->checkScores();
262
+    
263
+    $this->disconnectUser();
264
+  }
265
+  
266
+  protected function checkDeleteElement()
267
+  {
268
+    $this->connectUser('paul');
269
+    
270
+    $response = $this->tests_cases->elementAddGoodPoint(
271
+      $this->findOneBy('Element', "KoinkOin - H5N1"),
272
+      $this->findUserByUsername('paul'));
273
+    $this->stringResponseIsSuccess($response);
274
+    
275
+    $this->scores_reference['User']['bux'] += 1;
276
+    $this->scores_reference['Element']["KoinkOin - H5N1"] += 1;
277
+    $this->checkScores();
278
+    
279
+    $this->disconnectUser();
280
+    $this->connectUser('joelle');
281
+    
282
+    $response = $this->tests_cases->elementAddGoodPoint(
283
+      $this->findOneBy('Element', "KoinkOin - H5N1"),
284
+      $this->findUserByUsername('joelle'));
285
+    $this->stringResponseIsSuccess($response);
286
+    
287
+    $this->scores_reference['User']['bux'] += 1;
288
+    $this->scores_reference['Element']["KoinkOin - H5N1"] += 1;
289
+    $this->checkScores();
290
+    
291
+    $this->disconnectUser();
292
+    
293
+    $this->connectUser('paul');
294
+    
295
+    $response = $this->tests_cases->elementAddToFavorites(
296
+      $this->findOneBy('Element', "KoinkOin - H5N1"),
297
+      $this->findUserByUsername('paul'));
298
+    $this->stringResponseIsSuccess($response);
299
+    
300
+    $this->scores_reference['User']['bux'] += 5;
301
+    $this->scores_reference['Element']["KoinkOin - H5N1"] += 5;
302
+    $this->checkScores();
303
+    
304
+    $this->disconnectUser();
305
+    
306
+    $this->connectUser('jean');
307
+    
308
+    $response = $this->tests_cases->playlistCreate(
309
+      $this->findOneBy('Element', "KoinkOin - H5N1")->getId(),
310
+      "4564564752478942892489)");
311
+    $this->stringResponseIsSuccess($response);
312
+    
313
+    $this->scores_reference['User']['bux'] += 1;
314
+    $this->scores_reference['Element']['KoinkOin - H5N1'] += 1;
315
+    $this->checkScores();
316
+    
317
+    $this->disconnectUser();
318
+    $this->connectUser('bux');
319
+    
320
+    $response = $this->tests_cases->elementDelete(
321
+      $this->findOneBy('Element', "KoinkOin - H5N1"),
322
+      $this->findUserByUsername('bux'));
323
+    $this->stringResponseIsSuccess($response);
324
+    
325
+    $this->scores_reference['User']['bux'] -= 8;
326
+    unset($this->scores_reference['Element']['KoinkOin - H5N1']);
327
+    $this->checkScores();
328
+    
329
+    $this->disconnectUser();
330
+  }
331
+  
332
+}

+ 101 - 8
src/Muzich/CoreBundle/Tests/lib/Security/ContextTestCases.php View File

@@ -6,6 +6,10 @@ use Muzich\CoreBundle\lib\Test\Client;
6 6
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
7 7
 use Muzich\CoreBundle\Security\Context as SecurityContext;
8 8
 use Symfony\Component\DomCrawler\Crawler;
9
+use Muzich\CoreBundle\Entity\Element;
10
+use Muzich\CoreBundle\Entity\User;
11
+use Muzich\CoreBundle\Entity\Playlist;
12
+use Muzich\CoreBundle\Entity\ElementTagsProposition;
9 13
 
10 14
 class ContextTestCases
11 15
 {
@@ -222,19 +226,24 @@ class ContextTestCases
222 226
   public function followUserResponseIs($success, $condition)
223 227
   {
224 228
     return $this->ajaxResponseSatisfyConditions(
225
-      $this->getAjaxRequestContentResponse(
226
-        'GET',
227
-        $this->test->generateUrl('follow', array(
228
-          'type' => 'user', 
229
-          'id' => 0,
230
-          'token' => 'notoken'
231
-        ))
232
-      ), 
229
+      $this->followUser(0), 
233 230
       $success, 
234 231
       $condition
235 232
     );
236 233
   }
237 234
   
235
+  public function followUser($user_id)
236
+  {
237
+    return $this->getAjaxRequestContentResponse(
238
+      'GET',
239
+      $this->test->generateUrl('follow', array(
240
+        'type'  => 'user', 
241
+        'id'    => $user_id,
242
+        'token' => $this->test->getUser()->getPersonalHash($user_id)
243
+      ))
244
+    );
245
+  }
246
+  
238 247
   public function getFavoritesTagsResponseIs($success, $condition)
239 248
   {
240 249
     return $this->ajaxResponseSatisfyConditions(
@@ -380,6 +389,8 @@ class ContextTestCases
380 389
       array(), 
381 390
       array('HTTP_X-Requested-With' => 'XMLHttpRequest')
382 391
     );
392
+    
393
+    return $this->test->getClient()->getResponse()->getContent();
383 394
   }
384 395
 
385 396
 
@@ -539,4 +550,86 @@ class ContextTestCases
539 550
     );
540 551
   }
541 552
   
553
+  public function elementAddGoodPoint(Element $element, User $user)
554
+  {
555
+    return $this->getAjaxRequestContentResponse(
556
+      'GET',
557
+      $this->test->generateUrl('ajax_element_add_vote_good', array(
558
+        'element_id' => $element->getId(),
559
+        'token'      => $user->getPersonalHash($element->getId()),
560
+        '_locale'    => 'fr'
561
+      ))
562
+    );
563
+  }
564
+  
565
+  public function elementRemoveGoodPoint(Element $element, User $user)
566
+  {
567
+    return $this->getAjaxRequestContentResponse(
568
+      'GET',
569
+      $this->test->generateUrl('ajax_element_remove_vote_good', array(
570
+        'element_id' => $element->getId(),
571
+        'token'      => $user->getPersonalHash($element->getId()),
572
+        '_locale'    => 'fr'
573
+      ))
574
+    );
575
+  }
576
+  
577
+  public function elementAddToFavorites(Element $element, User $user)
578
+  {
579
+    return $this->getAjaxRequestContentResponse(
580
+      'GET',
581
+      $this->test->generateUrl('favorite_add', array(
582
+        'id'    => $element->getId(),
583
+        'token' => $user->getPersonalHash($element->getId())
584
+      ))
585
+    );
586
+  }
587
+  
588
+  public function elementRemoveFromFavorites(Element $element, User $user)
589
+  {
590
+    return $this->getAjaxRequestContentResponse(
591
+      'GET',
592
+      $this->test->generateUrl('favorite_remove', array(
593
+        'id'    => $element->getId(),
594
+        'token' => $user->getPersonalHash($element->getId())
595
+      ))
596
+    );
597
+  }
598
+  
599
+  public function elementProposeTags(Element $element, User $user, $tags_ids)
600
+  {
601
+    return $this->getAjaxRequestContentResponse(
602
+      'POST',
603
+      $this->test->generateUrl('ajax_element_propose_tags_proceed', 
604
+        array('element_id' => $element->getId(), 'token' => $user->getPersonalHash())
605
+      ), 
606
+      array(
607
+        'element_tag_proposition_'.$element->getId() => array(
608
+          'tags' => json_encode($tags_ids)
609
+        )
610
+      )
611
+    );
612
+  }
613
+  
614
+  public function elementAcceptTagsProposition(User $user, ElementTagsProposition $proposition)
615
+  {
616
+    return $this->getAjaxRequestContentResponse(
617
+      'GET',
618
+      $this->test->generateUrl('ajax_element_proposed_tags_accept', array(
619
+        'proposition_id' => $proposition->getId(),
620
+        'token'          => $user->getPersonalHash($proposition->getId())
621
+      ))
622
+    );
623
+  }
624
+  
625
+  public function elementDelete(Element $element, User $user)
626
+  {
627
+    return $this->getAjaxRequestContentResponse(
628
+      'GET',
629
+      $this->test->generateUrl('element_remove', array(
630
+        'element_id' => $element->getId(), 'token' => $user->getPersonalHash($element->getId())
631
+      ))
632
+    );
633
+  }
634
+  
542 635
 }

+ 18 - 1
src/Muzich/CoreBundle/lib/FunctionalTest.php View File

@@ -9,6 +9,7 @@ use Symfony\Component\DomCrawler\Crawler;
9 9
 use Symfony\Bundle\FrameworkBundle\Console\Application;
10 10
 use Symfony\Component\Console\Input\StringInput;
11 11
 use Symfony\Component\Console\Output\StreamOutput;
12
+use Muzich\CoreBundle\Entity\Element;
12 13
 
13 14
 class FunctionalTest extends WebTestCase
14 15
 {
@@ -88,7 +89,7 @@ class FunctionalTest extends WebTestCase
88 89
     ;
89 90
   }
90 91
   
91
-  protected function connectUser($login, $password, $client = null, $success = true)
92
+  protected function connectUser($login, $password = 'toor', $client = null, $success = true)
92 93
   {
93 94
     if (!$client)
94 95
     {
@@ -581,4 +582,20 @@ class FunctionalTest extends WebTestCase
581 582
     return $this->getContainer()->get('form.csrf_provider')->generateCsrfToken($intention);
582 583
   }
583 584
   
585
+  public function getLastTagsProposition(Element $element)
586
+  {
587
+    $propositions = $this->getDoctrine()->getManager()
588
+      ->createQuery('SELECT p FROM MuzichCoreBundle:ElementTagsProposition p'
589
+        .' WHERE p.element = :eid ORDER BY p.id DESC')
590
+      ->setMaxResults(1)
591
+      ->setParameters(array(
592
+        'eid' => $element->getId()
593
+      ))
594
+      ->getResult()
595
+    ;
596
+    
597
+    $this->assertEquals(1, count($propositions));
598
+    return $propositions[0];
599
+  }
600
+  
584 601
 }

+ 2 - 0
src/Muzich/FavoriteBundle/Controller/FavoriteController.php View File

@@ -74,6 +74,7 @@ class FavoriteController extends Controller
74 74
     if ($this->getRequest()->isXmlHttpRequest())
75 75
     {
76 76
       return $this->jsonResponse(array(
77
+        'status'        => 'success',
77 78
         'favorite'      => true,
78 79
         'link_new_url'  => $this->generateUrl('favorite_remove', array(
79 80
             'id'    => $id,
@@ -138,6 +139,7 @@ class FavoriteController extends Controller
138 139
     if ($this->getRequest()->isXmlHttpRequest())
139 140
     {
140 141
       return $this->jsonResponse(array(
142
+        'status'        => 'success',
141 143
         'favorite'      => true,
142 144
         'link_new_url'  => $this->generateUrl('favorite_add', array(
143 145
             'id'    => $id,