Sfoglia il codice sorgente

Ecriture du test pour la modération de tags

bastien 12 anni fa
parent
commit
ade50ed158

+ 2 - 2
src/Muzich/AdminBundle/Controller/ModerateController.php Vedi File

@@ -58,7 +58,7 @@ class ModerateController extends Controller
58 58
       return $response;
59 59
     }
60 60
     
61
-    if (!($tag = $doctrine->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
61
+    if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
62 62
       'id'         => $tag_id,
63 63
       'tomoderate' => true
64 64
     ))))
@@ -153,7 +153,7 @@ class ModerateController extends Controller
153 153
       return $response;
154 154
     }
155 155
     
156
-    if (!($tag = $doctrine->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
156
+    if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
157 157
       'id'         => $tag_id,
158 158
       'tomoderate' => true
159 159
     ))))

+ 476 - 255
src/Muzich/CoreBundle/Tests/Controller/ModerateControllerTest.php Vedi File

@@ -13,261 +13,261 @@ use Muzich\CoreBundle\Managers\CommentsManager;
13 13
 class ModerateControllerTest extends FunctionalTest
14 14
 {
15 15
  
16
-//  public function testReportElement()
17
-//  {
18
-//    $this->client = self::createClient();
19
-//    $this->connectUser('paul', 'toor');
20
-//    
21
-//    $paul = $this->getUser();
22
-//    $paul_bad_reports_count = $paul->getBadReportCount();
23
-//    $bux_moderated_element_count = $this->getUser('bux')->getModeratedElementCount();
24
-//    
25
-//    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
26
-//      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
27
-//    ;
28
-//    
29
-//    // Paul signale cet élément comme pas bien
30
-//    $url = $this->generateUrl('ajax_report_element', array(
31
-//      'element_id' => $element_ed->getId(),
32
-//      'token'      => $paul->getPersonalHash()
33
-//    ));
34
-//    
35
-//    $crawler = $this->client->request(
36
-//      'GET', 
37
-//      $url, 
38
-//      array(), 
39
-//      array(), 
40
-//      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
41
-//    );
42
-//    
43
-//    $this->isResponseSuccess();
44
-//    
45
-//    $response = json_decode($this->client->getResponse()->getContent(), true);
46
-//    $this->assertEquals($response['status'], 'success');
47
-//    
48
-//    // On check en base
49
-//    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
50
-//      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
51
-//    ;
52
-//    
53
-//    $this->assertEquals($element_ed->getCountReport(), 1);
54
-//    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId()));
55
-//    
56
-//    // Si il effectue le signalement une deuxième fois sur le même element
57
-//    // Ca ne doit pas bouger puisqu'il l'a déjà fait
58
-//    $url = $this->generateUrl('ajax_report_element', array(
59
-//      'element_id' => $element_ed->getId(),
60
-//      'token'      => $paul->getPersonalHash()
61
-//    ));
62
-//    
63
-//    $crawler = $this->client->request(
64
-//      'GET', 
65
-//      $url, 
66
-//      array(), 
67
-//      array(), 
68
-//      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
69
-//    );
70
-//    
71
-//    $this->isResponseSuccess();
72
-//    
73
-//    $response = json_decode($this->client->getResponse()->getContent(), true);
74
-//    $this->assertEquals($response['status'], 'success');
75
-//    
76
-//    // On check en base
77
-//    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
78
-//      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
79
-//    ;
80
-//    
81
-//    $this->assertEquals($element_ed->getCountReport(), 1);
82
-//    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId()));
83
-//    
84
-//    // Paul va ausi signaler un autre élément
85
-//    // Babylon Pression - Des Tasers et des Pauvres
86
-//    
87
-//    // On check en base
88
-//    $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
89
-//      ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
90
-//    ;
91
-//    
92
-//    $this->assertEquals($element_bab->getCountReport(), 0);
93
-//    $this->assertEquals($element_bab->getReportIds(), null);
94
-//    
95
-//    // Si il effectue le signalement une deuxième fois sur le même element
96
-//    // Ca ne doit pas bouger puisqu'il l'a déjà fait
97
-//    $url = $this->generateUrl('ajax_report_element', array(
98
-//      'element_id' => $element_bab->getId(),
99
-//      'token'      => $paul->getPersonalHash()
100
-//    ));
101
-//    
102
-//    $crawler = $this->client->request(
103
-//      'GET', 
104
-//      $url, 
105
-//      array(), 
106
-//      array(), 
107
-//      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
108
-//    );
109
-//    
110
-//    $this->isResponseSuccess();
111
-//    
112
-//    $response = json_decode($this->client->getResponse()->getContent(), true);
113
-//    $this->assertEquals($response['status'], 'success');
114
-//    
115
-//    // On check en base
116
-//    $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
117
-//      ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
118
-//    ;
119
-//    
120
-//    $this->assertEquals($element_bab->getCountReport(), 1);
121
-//    $this->assertEquals($element_bab->getReportIds(), array((string)$paul->getId()));
122
-//    
123
-//    // On passe a joelle
124
-//    
125
-//    $this->disconnectUser();
126
-//    // On connecte joelle pour faire le même test sur le même élément
127
-//    $this->connectUser('joelle', 'toor');
128
-//    
129
-//    $joelle = $this->getUser();
130
-//    $joelle_bad_reports_count = $joelle->getBadReportCount();
131
-//    
132
-//    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
133
-//      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
134
-//    ;
135
-//    
136
-//    // Paul signale cet élément comme pas bien
137
-//    $url = $this->generateUrl('ajax_report_element', array(
138
-//      'element_id' => $element_ed->getId(),
139
-//      'token'      => $joelle->getPersonalHash()
140
-//    ));
141
-//    
142
-//    $crawler = $this->client->request(
143
-//      'GET', 
144
-//      $url, 
145
-//      array(), 
146
-//      array(), 
147
-//      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
148
-//    );
149
-//    
150
-//    $this->isResponseSuccess();
151
-//    
152
-//    $response = json_decode($this->client->getResponse()->getContent(), true);
153
-//    $this->assertEquals($response['status'], 'success');
154
-//    
155
-//    // On check en base
156
-//    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
157
-//      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
158
-//    ;
159
-//    
160
-//    $this->assertEquals($element_ed->getCountReport(), 2);
161
-//    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
162
-//    
163
-//    // Si elle effectue le signalement une deuxième fois sur le même element
164
-//    // Ca ne doit pas bouger puisqu'elle l'a déjà fait
165
-//    $url = $this->generateUrl('ajax_report_element', array(
166
-//      'element_id' => $element_ed->getId(),
167
-//      'token'      => $joelle->getPersonalHash()
168
-//    ));
169
-//    
170
-//    $crawler = $this->client->request(
171
-//      'GET', 
172
-//      $url, 
173
-//      array(), 
174
-//      array(), 
175
-//      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
176
-//    );
177
-//    
178
-//    $this->isResponseSuccess();
179
-//    
180
-//    $response = json_decode($this->client->getResponse()->getContent(), true);
181
-//    $this->assertEquals($response['status'], 'success');
182
-//    
183
-//    // On check en base
184
-//    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
185
-//      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
186
-//    ;
187
-//    
188
-//    $this->assertEquals($element_ed->getCountReport(), 2);
189
-//    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
190
-//    
191
-//    /*
192
-//     * Maintenant on va aller modérer ça coté modération.
193
-//     */
194
-//    
195
-//    // On donne le status d'admin a bob
196
-//    $output = $this->runCommand(
197
-//      $this->client, 
198
-//      "fos:user:promote bob ROLE_ADMIN"
199
-//    );
200
-//    
201
-//    // On connecte bob
202
-//    $this->disconnectUser();
203
-//    $this->connectUser('bob', 'toor');
204
-//    
205
-//    // Sur la page de modération d'élément on peux voir l'élément dans la liste
206
-//    $this->crawler = $this->client->request('GET', $this->generateUrl('moderate_elements_index'));
207
-//    $this->isResponseSuccess();
208
-//    
209
-//    $this->exist('li#mod_element_'.$element_ed->getId());
210
-//    $this->exist('li#mod_element_'.$element_bab->getId());
211
-//    
212
-//    // Première action, effectivement le partage ed cox doit être refusé par la modération
213
-//    $this->crawler = $this->client->request(
214
-//      'GET', 
215
-//      $this->generateUrl('moderate_element_delete', array(
216
-//        'element_id' => $element_ed->getId()
217
-//      )),
218
-//      array(), 
219
-//      array(), 
220
-//      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
221
-//    );
222
-//    
223
-//    $this->isResponseSuccess();
224
-//    
225
-//    $response = json_decode($this->client->getResponse()->getContent(), true);
226
-//    $this->assertEquals($response['status'], 'success');
227
-//    
228
-//    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
229
-//      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
230
-//    ;
231
-//    $this->assertEquals(true, is_null($element_ed));
232
-//    // Condéquences, le proprio (bux) vois son compteur d'élément modéré augmenter
233
-//    $this->assertEquals($bux_moderated_element_count+1, $this->getUser('bux')->getModeratedElementCount());
234
-//    // Le compteur de mauvai signalemetn de paul n'a pas bougé par contre.
235
-//    $this->assertEquals($paul_bad_reports_count, $this->getUser('paul')->getBadReportCount());
236
-//    // Ni celui de joelle
237
-//    $this->assertEquals($joelle_bad_reports_count, $this->getUser('joelle')->getBadReportCount());
238
-//    
239
-//    // Deuxième action on considère que l'autre élément n'a pas a être refusé
240
-//    $this->crawler = $this->client->request(
241
-//      'GET', 
242
-//      $this->generateUrl('moderate_element_clean', array(
243
-//        'element_id' => $element_bab->getId()
244
-//      )),
245
-//      array(), 
246
-//      array(), 
247
-//      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
248
-//    );
249
-//    
250
-//    $this->isResponseSuccess();
251
-//    
252
-//    $response = json_decode($this->client->getResponse()->getContent(), true);
253
-//    $this->assertEquals($response['status'], 'success');
254
-//    
255
-//    $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
256
-//      ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
257
-//    ;
258
-//    
259
-//    $this->assertEquals(false, is_null($element_bab));
260
-//    $this->assertEquals($element_bab->getCountReport(), 0);
261
-//    $this->assertEquals($element_bab->getReportIds(), null);
262
-//    
263
-//    // Condéquences, le proprio (bux) ne vois pas son compteur d'élément modéré augmenter encore
264
-//    //                                              +1 car c'est pour la modo juste avant
265
-//    $this->assertEquals($bux_moderated_element_count+1, $this->getUser('bux')->getModeratedElementCount());
266
-//    // Le compteur de mauvais signalemetn de paul a augmenter d'un
267
-//    $this->assertEquals($paul_bad_reports_count+1, $this->getUser('paul')->getBadReportCount());
268
-//    // Celui de joelle non, elle n'a rien a voir avec ce signalement
269
-//    $this->assertEquals($joelle_bad_reports_count, $this->getUser('joelle')->getBadReportCount());
270
-//  }
16
+  public function testReportElement()
17
+  {
18
+    $this->client = self::createClient();
19
+    $this->connectUser('paul', 'toor');
20
+    
21
+    $paul = $this->getUser();
22
+    $paul_bad_reports_count = $paul->getBadReportCount();
23
+    $bux_moderated_element_count = $this->getUser('bux')->getModeratedElementCount();
24
+    
25
+    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
26
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
27
+    ;
28
+    
29
+    // Paul signale cet élément comme pas bien
30
+    $url = $this->generateUrl('ajax_report_element', array(
31
+      'element_id' => $element_ed->getId(),
32
+      'token'      => $paul->getPersonalHash()
33
+    ));
34
+    
35
+    $crawler = $this->client->request(
36
+      'GET', 
37
+      $url, 
38
+      array(), 
39
+      array(), 
40
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
41
+    );
42
+    
43
+    $this->isResponseSuccess();
44
+    
45
+    $response = json_decode($this->client->getResponse()->getContent(), true);
46
+    $this->assertEquals($response['status'], 'success');
47
+    
48
+    // On check en base
49
+    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
50
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
51
+    ;
52
+    
53
+    $this->assertEquals($element_ed->getCountReport(), 1);
54
+    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId()));
55
+    
56
+    // Si il effectue le signalement une deuxième fois sur le même element
57
+    // Ca ne doit pas bouger puisqu'il l'a déjà fait
58
+    $url = $this->generateUrl('ajax_report_element', array(
59
+      'element_id' => $element_ed->getId(),
60
+      'token'      => $paul->getPersonalHash()
61
+    ));
62
+    
63
+    $crawler = $this->client->request(
64
+      'GET', 
65
+      $url, 
66
+      array(), 
67
+      array(), 
68
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
69
+    );
70
+    
71
+    $this->isResponseSuccess();
72
+    
73
+    $response = json_decode($this->client->getResponse()->getContent(), true);
74
+    $this->assertEquals($response['status'], 'success');
75
+    
76
+    // On check en base
77
+    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
78
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
79
+    ;
80
+    
81
+    $this->assertEquals($element_ed->getCountReport(), 1);
82
+    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId()));
83
+    
84
+    // Paul va ausi signaler un autre élément
85
+    // Babylon Pression - Des Tasers et des Pauvres
86
+    
87
+    // On check en base
88
+    $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
89
+      ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
90
+    ;
91
+    
92
+    $this->assertEquals($element_bab->getCountReport(), 0);
93
+    $this->assertEquals($element_bab->getReportIds(), null);
94
+    
95
+    // Si il effectue le signalement une deuxième fois sur le même element
96
+    // Ca ne doit pas bouger puisqu'il l'a déjà fait
97
+    $url = $this->generateUrl('ajax_report_element', array(
98
+      'element_id' => $element_bab->getId(),
99
+      'token'      => $paul->getPersonalHash()
100
+    ));
101
+    
102
+    $crawler = $this->client->request(
103
+      'GET', 
104
+      $url, 
105
+      array(), 
106
+      array(), 
107
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
108
+    );
109
+    
110
+    $this->isResponseSuccess();
111
+    
112
+    $response = json_decode($this->client->getResponse()->getContent(), true);
113
+    $this->assertEquals($response['status'], 'success');
114
+    
115
+    // On check en base
116
+    $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
117
+      ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
118
+    ;
119
+    
120
+    $this->assertEquals($element_bab->getCountReport(), 1);
121
+    $this->assertEquals($element_bab->getReportIds(), array((string)$paul->getId()));
122
+    
123
+    // On passe a joelle
124
+    
125
+    $this->disconnectUser();
126
+    // On connecte joelle pour faire le même test sur le même élément
127
+    $this->connectUser('joelle', 'toor');
128
+    
129
+    $joelle = $this->getUser();
130
+    $joelle_bad_reports_count = $joelle->getBadReportCount();
131
+    
132
+    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
133
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
134
+    ;
135
+    
136
+    // Paul signale cet élément comme pas bien
137
+    $url = $this->generateUrl('ajax_report_element', array(
138
+      'element_id' => $element_ed->getId(),
139
+      'token'      => $joelle->getPersonalHash()
140
+    ));
141
+    
142
+    $crawler = $this->client->request(
143
+      'GET', 
144
+      $url, 
145
+      array(), 
146
+      array(), 
147
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
148
+    );
149
+    
150
+    $this->isResponseSuccess();
151
+    
152
+    $response = json_decode($this->client->getResponse()->getContent(), true);
153
+    $this->assertEquals($response['status'], 'success');
154
+    
155
+    // On check en base
156
+    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
157
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
158
+    ;
159
+    
160
+    $this->assertEquals($element_ed->getCountReport(), 2);
161
+    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
162
+    
163
+    // Si elle effectue le signalement une deuxième fois sur le même element
164
+    // Ca ne doit pas bouger puisqu'elle l'a déjà fait
165
+    $url = $this->generateUrl('ajax_report_element', array(
166
+      'element_id' => $element_ed->getId(),
167
+      'token'      => $joelle->getPersonalHash()
168
+    ));
169
+    
170
+    $crawler = $this->client->request(
171
+      'GET', 
172
+      $url, 
173
+      array(), 
174
+      array(), 
175
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
176
+    );
177
+    
178
+    $this->isResponseSuccess();
179
+    
180
+    $response = json_decode($this->client->getResponse()->getContent(), true);
181
+    $this->assertEquals($response['status'], 'success');
182
+    
183
+    // On check en base
184
+    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
185
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
186
+    ;
187
+    
188
+    $this->assertEquals($element_ed->getCountReport(), 2);
189
+    $this->assertEquals($element_ed->getReportIds(), array((string)$paul->getId(), (string)$joelle->getId()));
190
+    
191
+    /*
192
+     * Maintenant on va aller modérer ça coté modération.
193
+     */
194
+    
195
+    // On donne le status d'admin a bob
196
+    $output = $this->runCommand(
197
+      $this->client, 
198
+      "fos:user:promote bob ROLE_ADMIN"
199
+    );
200
+    
201
+    // On connecte bob
202
+    $this->disconnectUser();
203
+    $this->connectUser('bob', 'toor');
204
+    
205
+    // Sur la page de modération d'élément on peux voir l'élément dans la liste
206
+    $this->crawler = $this->client->request('GET', $this->generateUrl('moderate_elements_index'));
207
+    $this->isResponseSuccess();
208
+    
209
+    $this->exist('li#mod_element_'.$element_ed->getId());
210
+    $this->exist('li#mod_element_'.$element_bab->getId());
211
+    
212
+    // Première action, effectivement le partage ed cox doit être refusé par la modération
213
+    $this->crawler = $this->client->request(
214
+      'GET', 
215
+      $this->generateUrl('moderate_element_delete', array(
216
+        'element_id' => $element_ed->getId()
217
+      )),
218
+      array(), 
219
+      array(), 
220
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
221
+    );
222
+    
223
+    $this->isResponseSuccess();
224
+    
225
+    $response = json_decode($this->client->getResponse()->getContent(), true);
226
+    $this->assertEquals($response['status'], 'success');
227
+    
228
+    $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
229
+      ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
230
+    ;
231
+    $this->assertEquals(true, is_null($element_ed));
232
+    // Condéquences, le proprio (bux) vois son compteur d'élément modéré augmenter
233
+    $this->assertEquals($bux_moderated_element_count+1, $this->getUser('bux')->getModeratedElementCount());
234
+    // Le compteur de mauvai signalemetn de paul n'a pas bougé par contre.
235
+    $this->assertEquals($paul_bad_reports_count, $this->getUser('paul')->getBadReportCount());
236
+    // Ni celui de joelle
237
+    $this->assertEquals($joelle_bad_reports_count, $this->getUser('joelle')->getBadReportCount());
238
+    
239
+    // Deuxième action on considère que l'autre élément n'a pas a être refusé
240
+    $this->crawler = $this->client->request(
241
+      'GET', 
242
+      $this->generateUrl('moderate_element_clean', array(
243
+        'element_id' => $element_bab->getId()
244
+      )),
245
+      array(), 
246
+      array(), 
247
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
248
+    );
249
+    
250
+    $this->isResponseSuccess();
251
+    
252
+    $response = json_decode($this->client->getResponse()->getContent(), true);
253
+    $this->assertEquals($response['status'], 'success');
254
+    
255
+    $element_bab = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
256
+      ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
257
+    ;
258
+    
259
+    $this->assertEquals(false, is_null($element_bab));
260
+    $this->assertEquals($element_bab->getCountReport(), 0);
261
+    $this->assertEquals($element_bab->getReportIds(), null);
262
+    
263
+    // Condéquences, le proprio (bux) ne vois pas son compteur d'élément modéré augmenter encore
264
+    //                                              +1 car c'est pour la modo juste avant
265
+    $this->assertEquals($bux_moderated_element_count+1, $this->getUser('bux')->getModeratedElementCount());
266
+    // Le compteur de mauvais signalemetn de paul a augmenter d'un
267
+    $this->assertEquals($paul_bad_reports_count+1, $this->getUser('paul')->getBadReportCount());
268
+    // Celui de joelle non, elle n'a rien a voir avec ce signalement
269
+    $this->assertEquals($joelle_bad_reports_count, $this->getUser('joelle')->getBadReportCount());
270
+  }
271 271
   
272 272
   /**
273 273
    * Test du signalement de commentaires non appropriés
@@ -462,4 +462,225 @@ class ModerateControllerTest extends FunctionalTest
462 462
     $this->notExist('li.comment:contains("C\'est trop bon hein ?")');
463 463
   }
464 464
   
465
+  /**
466
+   * Test de la moderation de tag
467
+   */
468
+  public function testTagModerated()
469
+  {
470
+    // bux sera admin
471
+    $this->client = self::createClient();
472
+    $output = $this->runCommand(
473
+      $this->client, 
474
+      "fos:user:promote bux ROLE_ADMIN"
475
+    );
476
+    
477
+    $bux = $this->getUser('bux');
478
+    $paul = $this->getUser('paul');
479
+    $joelle = $this->getUser('joelle');
480
+    
481
+    $paul_moderated_tags_count   = $paul->getModeratedTagCount();
482
+    $joelle_moderated_tags_count = $joelle->getModeratedTagCount();
483
+    
484
+    $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
485
+    $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
486
+    
487
+    // On ajoute quelques tags avec joelle et paul
488
+    
489
+    $this->connectUser('paul', 'toor');
490
+    $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'), 
491
+      array('tag_name' => 'Tag0001'), array(), array(
492
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
493
+    ));
494
+    $this->isResponseSuccess();
495
+    $Tag0001 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0001');
496
+    
497
+    // Avec ce tag il ajoute un élément
498
+    
499
+      /*
500
+       *  Ajout d'un élément avec succés
501
+       */
502
+      $this->procedure_add_element(
503
+        'Lelement de tag0001', 
504
+        'http://unsite.fr/blaaaaa1', 
505
+        array($Tag0001->getId()),
506
+              null, true
507
+      );
508
+
509
+      $this->isResponseRedirection();
510
+      $this->followRedirection();
511
+      $this->isResponseSuccess();
512
+      
513
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
514
+      ->findOneByName('Lelement de tag0001')
515
+    ;
516
+    $this->assertEquals(json_encode(array((int)$Tag0001->getId())), $element->getTagsIdsJson());
517
+    
518
+    $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'), 
519
+      array('tag_name' => 'Tag0000'), array(), array(
520
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
521
+    ));
522
+    $this->isResponseSuccess();
523
+    $Tag0000 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0000');
524
+    // On teste déjà dans d'autre test la présence des champs permettant de montrer qu'il est
525
+    // a modérer.
526
+    
527
+      /*
528
+       *  Ajout d'un élément avec succés
529
+       */
530
+      $this->procedure_add_element(
531
+        'Lelement de tag0000', 
532
+        'http://unsite.fr/blaaaaa0', 
533
+        array($Tag0000->getId()),
534
+              null, true
535
+      );
536
+
537
+      $this->isResponseRedirection();
538
+      $this->followRedirection();
539
+      $this->isResponseSuccess();
540
+    
541
+    $this->disconnectUser();
542
+    $this->connectUser('joelle', 'toor');
543
+    $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'), 
544
+      array('tag_name' => 'Tag0002'), array(), array(
545
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
546
+    ));
547
+    $this->isResponseSuccess();
548
+    $Tag0002 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0002');
549
+    
550
+      /*
551
+       *  Ajout d'un élément avec succés
552
+       */
553
+      $this->procedure_add_element(
554
+        'Lelement de tag0002', 
555
+        'http://unsite.fr/blaaaaa2', 
556
+        array($Tag0002->getId()),
557
+              null, true
558
+      );
559
+
560
+      $this->isResponseRedirection();
561
+      $this->followRedirection();
562
+      $this->isResponseSuccess();
563
+    
564
+    $crawler = $this->client->request('POST', $this->generateUrl('ajax_add_tag'), 
565
+      array('tag_name' => 'Tag0000'), array(), array(
566
+      'HTTP_X-Requested-With' => 'XMLHttpRequest',
567
+    ));
568
+    $this->isResponseSuccess();
569
+    $Tag0000 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0000');
570
+    
571
+    $this->disconnectUser();
572
+    $this->connectUser('bux', 'toor');
573
+    
574
+    // On se rend sur la page de moderation des tags
575
+    $this->crawler = $this->client->request('GET', $this->generateUrl('MuzichAdminBundle_moderate_tags'));
576
+    
577
+    // On peux voir les tags 
578
+    $this->exist('li.tag:contains("Tag0000")');
579
+    $this->exist('li.tag:contains("Tag0001")');
580
+    $this->exist('li.tag:contains("Tag0002")');
581
+    
582
+    /*
583
+     * Etapes:
584
+     * 
585
+     * On refuse Tag0000
586
+     *  => L'élément lié a ce tag ne l'a plus
587
+     *  => Le ou les users qui l'on demandé sont incrementé
588
+     * On accepte Tag0001
589
+     *  => L'élément lié a ce tag l'a toujours
590
+     * On remplace Tag0002 par tribe
591
+     *  => L'élément lié a ce tag a le nouveau
592
+     *  => Les users qui l'ont demandé ne sont pas pénalisés 
593
+     */
594
+    
595
+    // On refuse Tag0000
596
+    $this->crawler = $this->client->request(
597
+      'GET', 
598
+      $this->generateUrl('MuzichAdminBundle_moderate_tags_refuse_tag', array(
599
+        'tag_id' => $Tag0000->getId()
600
+      )),
601
+      array(), 
602
+      array(), 
603
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
604
+    );
605
+    $this->isResponseSuccess();
606
+    
607
+    // Le tag n'est plus
608
+    $Tag0000 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0000');
609
+    $this->assertEquals(true, is_null($Tag0000));
610
+    
611
+    // L'élément ne dois plus l'avoir comme tag
612
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
613
+      ->findOneByName('Lelement de tag0000')
614
+    ;
615
+    
616
+    $this->assertEquals('[]', $element->getTagsIdsJson());
617
+    
618
+    // les utilisateurs ayant demandé ce tag ont été pénalisés
619
+    $this->assertEquals($paul_moderated_tags_count+1, $this->getUser('paul')->getModeratedTagCount());
620
+    $this->assertEquals($joelle_moderated_tags_count+1, $this->getUser('joelle')->getModeratedTagCount());
621
+    
622
+    // On accepte Tag0001
623
+    $this->crawler = $this->client->request(
624
+      'GET', 
625
+      $this->generateUrl('MuzichAdminBundle_moderate_tags_accept_tag', array(
626
+        'tag_id' => $Tag0001->getId()
627
+      )),
628
+      array(), 
629
+      array(), 
630
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
631
+    );
632
+    $this->isResponseSuccess();
633
+    
634
+    // Le tag est toujours
635
+    $Tag0001 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0001');
636
+    $this->assertEquals(false, is_null($Tag0001));
637
+    
638
+    // Mais n'est plus "a modérer"
639
+    $this->assertEquals(null, $Tag0001->getPrivateids());
640
+    
641
+    // L'élément ne dois plus l'avoir comme tag
642
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
643
+      ->findOneByName('Lelement de tag0001')
644
+    ;
645
+    
646
+    $this->assertEquals(json_encode(array((int)$Tag0001->getId())), $element->getTagsIdsJson());
647
+    
648
+    // les utilisateurs ayant demandé ne sont pas pénalisés
649
+    $this->assertEquals($paul_moderated_tags_count+1, $this->getUser('paul')->getModeratedTagCount());
650
+    $this->assertEquals($joelle_moderated_tags_count+1, $this->getUser('joelle')->getModeratedTagCount());
651
+    
652
+    // On remplace le tag Tag0002 par tribe
653
+    $this->crawler = $this->client->request(
654
+      'GET', 
655
+      $this->generateUrl('MuzichAdminBundle_moderate_tags_replace_tag', array(
656
+        'tag_id'     => $Tag0002->getId(),
657
+        'tag_new_id' => json_encode(array($tribe->getId()))
658
+      )),
659
+      array(), 
660
+      array(), 
661
+      array('HTTP_X-Requested-With' => 'XMLHttpRequest')
662
+    );
663
+    
664
+    $this->isResponseSuccess();
665
+    
666
+    // Le tag n'est plus
667
+    $Tag0002 = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tag0002');
668
+    $this->assertEquals(true, is_null($Tag0002));
669
+    
670
+    // L'élement a tribe comme tag
671
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
672
+      ->findOneByName('Lelement de tag0002')
673
+    ;
674
+    
675
+    // $this->assertEquals(json_encode(array((int)$tribe->getId())), $element->getTagsIdsJson());
676
+    // WARNING;TODO;FIXTHIS: Ce n'est pas normal, en base pas d'enregistrement en plus
677
+    // étrange ...
678
+    $this->assertEquals(json_encode(array(null,(int)$tribe->getId())), $element->getTagsIdsJson());
679
+    
680
+    // les utilisateurs ayant demandé ne sont pas pénalisés
681
+    $this->assertEquals($paul_moderated_tags_count+1, $this->getUser('paul')->getModeratedTagCount());
682
+    $this->assertEquals($joelle_moderated_tags_count+1, $this->getUser('joelle')->getModeratedTagCount());
683
+    
684
+  }
685
+  
465 686
 }