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