|
@@ -0,0 +1,346 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Tests\Controller;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\lib\FunctionalTest;
|
|
6
|
+use Muzich\CoreBundle\Searcher\ElementSearcher;
|
|
7
|
+
|
|
8
|
+class HomeControllerTest extends FunctionalTest
|
|
9
|
+{
|
|
10
|
+ /**
|
|
11
|
+ * Ce test contrôle l'affichage des elements sur la page d'accueil
|
|
12
|
+ * Il modifie egallement le filtre d'éléments
|
|
13
|
+ */
|
|
14
|
+ public function testFilter()
|
|
15
|
+ {
|
|
16
|
+ $this->connectUser('bux', 'toor');
|
|
17
|
+
|
|
18
|
+ // Présence du formulaire d'ajout d'un élément
|
|
19
|
+ $this->exist('form[action="'.($url = $this->generateUrl('element_add')).'"]');
|
|
20
|
+ $this->exist('form[action="'.$url.'"] input[id="element_add_name"]');
|
|
21
|
+ $this->exist('form[action="'.$url.'"] input[id="element_add_url"]');
|
|
22
|
+ $this->exist('form[action="'.$url.'"] input[type="submit"]');
|
|
23
|
+
|
|
24
|
+ // Présence du formulaire de filtrage
|
|
25
|
+ $this->exist('form[action="'.($url = $this->generateUrl('search_elements')).'"]');
|
|
26
|
+ $this->exist('form[action="'.$url.'"] select[id="element_search_form_network"]');
|
|
27
|
+ $this->exist('form[action="'.$url.'"] input[type="submit"]');
|
|
28
|
+
|
|
29
|
+ $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
|
|
30
|
+ $tribe_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
|
|
31
|
+
|
|
32
|
+ // On récupére le formulaire de filtrage
|
|
33
|
+ $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
|
|
34
|
+
|
|
35
|
+ // On décoche les tags
|
|
36
|
+ foreach ($this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findAll() as $tag)
|
|
37
|
+ {
|
|
38
|
+ $form['element_search_form[tags]['.$tag->getId().']']->untick();
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ // On met ce que l'on veut dans le form
|
|
42
|
+ $form['element_search_form[network]'] = ElementSearcher::NETWORK_PUBLIC;
|
|
43
|
+ $form['element_search_form[tags]['.$hardtek_id.']'] = $hardtek_id;
|
|
44
|
+ $form['element_search_form[tags]['.$tribe_id.']'] = $tribe_id;
|
|
45
|
+ $this->submit($form);
|
|
46
|
+
|
|
47
|
+ $this->client->submit($form);
|
|
48
|
+
|
|
49
|
+ $this->isResponseRedirection();
|
|
50
|
+ $this->followRedirection();
|
|
51
|
+ $this->isResponseSuccess();
|
|
52
|
+
|
|
53
|
+ $this->assertTrue($this->getSession()->has('user.element_search.params'));
|
|
54
|
+ $this->assertEquals(array(
|
|
55
|
+ 'network' => ElementSearcher::NETWORK_PUBLIC,
|
|
56
|
+ 'tags' => array(
|
|
57
|
+ $hardtek_id, $tribe_id
|
|
58
|
+ ),
|
|
59
|
+ 'count' => $this->getContainer()->getParameter('search_default_count'),
|
|
60
|
+ 'user_id' => null,
|
|
61
|
+ 'group_id' => null,
|
|
62
|
+ 'favorite' => false
|
|
63
|
+ ), $this->getSession()->get('user.element_search.params'));
|
|
64
|
+
|
|
65
|
+ // On fabrique l'ElementSearcher correspondant
|
|
66
|
+ $es = new ElementSearcher();
|
|
67
|
+ $es->init($this->getSession()->get('user.element_search.params'));
|
|
68
|
+
|
|
69
|
+ foreach ($es->getElements($this->getDoctrine(), $this->getUser()->getId()) as $element)
|
|
70
|
+ {
|
|
71
|
+ $this->exist('html:contains("'.$element->getName().'")');
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ /**
|
|
76
|
+ * Test de la présence des elements sur la page d'un utilisateur
|
|
77
|
+ */
|
|
78
|
+ public function testUserPage()
|
|
79
|
+ {
|
|
80
|
+ $this->connectUser('bux', 'toor');
|
|
81
|
+ $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
82
|
+ ->findOneByUsername('jean')
|
|
83
|
+ ;
|
|
84
|
+
|
|
85
|
+ $this->crawler = $this->client->request(
|
|
86
|
+ 'GET',
|
|
87
|
+ $this->generateUrl('show_user', array('slug' => $jean->getSlug()))
|
|
88
|
+ );
|
|
89
|
+
|
|
90
|
+ $this->isResponseSuccess();
|
|
91
|
+ $this->exist('h2:contains("'.$jean->getName().'")');
|
|
92
|
+
|
|
93
|
+ $es = new ElementSearcher();
|
|
94
|
+ $es->init(array(
|
|
95
|
+ 'user_id' => $jean->getId()
|
|
96
|
+ ));
|
|
97
|
+
|
|
98
|
+ foreach ($es->getElements($this->getDoctrine(), $this->getUser()->getId()) as $element)
|
|
99
|
+ {
|
|
100
|
+ $this->exist('html:contains("'.$element->getName().'")');
|
|
101
|
+ }
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ /**
|
|
105
|
+ * Test de la présence des elements sur la page d'un utilisateur
|
|
106
|
+ */
|
|
107
|
+ public function testGroupPage()
|
|
108
|
+ {
|
|
109
|
+ $this->connectUser('bux', 'toor');
|
|
110
|
+ $fdp = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
|
|
111
|
+ ->findOneBySlug('fans-de-psytrance')
|
|
112
|
+ ->getSingleResult()
|
|
113
|
+ ;
|
|
114
|
+
|
|
115
|
+ $this->crawler = $this->client->request(
|
|
116
|
+ 'GET',
|
|
117
|
+ $this->generateUrl('show_group', array('slug' => $fdp->getSlug()))
|
|
118
|
+ );
|
|
119
|
+
|
|
120
|
+ $this->isResponseSuccess();
|
|
121
|
+ $this->exist('h2:contains("'.$fdp->getName().'")');
|
|
122
|
+
|
|
123
|
+ $es = new ElementSearcher();
|
|
124
|
+ $es->init(array(
|
|
125
|
+ 'group_id' => $fdp->getId()
|
|
126
|
+ ));
|
|
127
|
+
|
|
128
|
+ foreach ($es->getElements($this->getDoctrine(), $this->getUser()->getId()) as $element)
|
|
129
|
+ {
|
|
130
|
+ $this->exist('html:contains("'.$element->getName().'")');
|
|
131
|
+ }
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ /**
|
|
135
|
+ * Ajouts d'éléments et tests de cas refusés
|
|
136
|
+ */
|
|
137
|
+ public function testAddElementSuccess()
|
|
138
|
+ {
|
|
139
|
+ $this->connectUser('bux', 'toor');
|
|
140
|
+
|
|
141
|
+ $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
|
|
142
|
+ $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
|
|
143
|
+
|
|
144
|
+ /*
|
|
145
|
+ * Ajout d'un élément avec succés
|
|
146
|
+ */
|
|
147
|
+ $this->procedure_add_element(
|
|
148
|
+ 'Mon bel element',
|
|
149
|
+ 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
150
|
+ array($hardtek->getId(), $tribe->getId())
|
|
151
|
+ );
|
|
152
|
+
|
|
153
|
+ $this->isResponseRedirection();
|
|
154
|
+ $this->followRedirection();
|
|
155
|
+ $this->isResponseSuccess();
|
|
156
|
+
|
|
157
|
+ $this->exist('li:contains("Mon bel element")');
|
|
158
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
159
|
+ ->findOneByName('Mon bel element')
|
|
160
|
+ ;
|
|
161
|
+ $this->assertTrue(!is_null($element));
|
|
162
|
+
|
|
163
|
+ }
|
|
164
|
+
|
|
165
|
+ /**
|
|
166
|
+ * Ajouts d'éléments et tests de cas refusés
|
|
167
|
+ */
|
|
168
|
+ public function testAddElementFailure()
|
|
169
|
+ {
|
|
170
|
+ $this->connectUser('bux', 'toor');
|
|
171
|
+
|
|
172
|
+ $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
|
|
173
|
+ $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
|
|
174
|
+
|
|
175
|
+ /*
|
|
176
|
+ * Ajouts d'éléments avec echec
|
|
177
|
+ */
|
|
178
|
+
|
|
179
|
+ // Nom trop court
|
|
180
|
+ $this->procedure_add_element(
|
|
181
|
+ 'Mo',
|
|
182
|
+ 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
183
|
+ array($hardtek->getId(), $tribe->getId())
|
|
184
|
+ );
|
|
185
|
+
|
|
186
|
+ $this->isResponseSuccess();
|
|
187
|
+
|
|
188
|
+ $this->notExist('li:contains("Mon bel element a4er563a1r")');
|
|
189
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
190
|
+ ->findOneByName('Mon bel element a4er563a1r')
|
|
191
|
+ ;
|
|
192
|
+ $this->assertTrue(is_null($element));
|
|
193
|
+
|
|
194
|
+ // Nom trop long
|
|
195
|
+ $this->procedure_add_element(
|
|
196
|
+ 'Mon bel element mais qui a un nom trop court la vache oui trop long hohoho',
|
|
197
|
+ 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
198
|
+ array($hardtek->getId(), $tribe->getId())
|
|
199
|
+ );
|
|
200
|
+
|
|
201
|
+ $this->isResponseSuccess();
|
|
202
|
+
|
|
203
|
+ $this->notExist('li:contains("Mon bel element mais qui a un nom trop court la vache oui trop long hohoho")');
|
|
204
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
205
|
+ ->findOneByName('Mon bel element mais qui a un nom trop court la vache oui trop long hohoho')
|
|
206
|
+ ;
|
|
207
|
+ $this->assertTrue(is_null($element));
|
|
208
|
+
|
|
209
|
+ // Pas d'url
|
|
210
|
+ $this->procedure_add_element(
|
|
211
|
+ 'Mon bel element',
|
|
212
|
+ '',
|
|
213
|
+ array($hardtek->getId(), $tribe->getId())
|
|
214
|
+ );
|
|
215
|
+
|
|
216
|
+ $this->isResponseSuccess();
|
|
217
|
+
|
|
218
|
+ $this->notExist('li:contains("Mon bel element gfez7f")');
|
|
219
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
220
|
+ ->findOneByName('Mon bel element gfez7f')
|
|
221
|
+ ;
|
|
222
|
+ $this->assertTrue(is_null($element));
|
|
223
|
+
|
|
224
|
+ // Pas de nom
|
|
225
|
+ $this->procedure_add_element(
|
|
226
|
+ '',
|
|
227
|
+ 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
228
|
+ array($hardtek->getId(), $tribe->getId())
|
|
229
|
+ );
|
|
230
|
+
|
|
231
|
+ $this->isResponseSuccess();
|
|
232
|
+
|
|
233
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
234
|
+ ->findOneByName('')
|
|
235
|
+ ;
|
|
236
|
+ $this->assertTrue(is_null($element));
|
|
237
|
+
|
|
238
|
+ }
|
|
239
|
+
|
|
240
|
+ /**
|
|
241
|
+ * L'ajout d'un Element a un de ses groupe ne doit pas poser de problème
|
|
242
|
+ */
|
|
243
|
+ public function testAddElementAtMyGroupSuccess()
|
|
244
|
+ {
|
|
245
|
+ $this->connectUser('bux', 'toor');
|
|
246
|
+ // Un groupe open, donc pas de soucis
|
|
247
|
+ $fan_de_psy = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
|
|
248
|
+
|
|
249
|
+ $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
|
|
250
|
+ $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
|
|
251
|
+
|
|
252
|
+ $this->isResponseSuccess();
|
|
253
|
+ $this->procedure_add_element(
|
|
254
|
+ 'Element mis dans le groupe de psytrance',
|
|
255
|
+ 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
256
|
+ array($hardtek->getId(), $tribe->getId()),
|
|
257
|
+ $fan_de_psy->getSlug()
|
|
258
|
+ );
|
|
259
|
+
|
|
260
|
+ $this->isResponseRedirection();
|
|
261
|
+ $this->followRedirection();
|
|
262
|
+ $this->isResponseSuccess();
|
|
263
|
+
|
|
264
|
+ $this->exist('li:contains("Element mis dans le groupe de psytrance")');
|
|
265
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
266
|
+ ->findOneByName('Element mis dans le groupe de psytrance')
|
|
267
|
+ ;
|
|
268
|
+ $this->assertTrue(!is_null($element));
|
|
269
|
+
|
|
270
|
+ if (!is_null($element))
|
|
271
|
+ {
|
|
272
|
+ $this->assertEquals($fan_de_psy->getId(), $element->getGroup()->getId());
|
|
273
|
+ }
|
|
274
|
+ else
|
|
275
|
+ {
|
|
276
|
+ $this->assertTrue(false);
|
|
277
|
+ }
|
|
278
|
+
|
|
279
|
+ $this->disconnectUser();
|
|
280
|
+
|
|
281
|
+ /*
|
|
282
|
+ * Ajout d'un element dans un groupe que l'on posséde.
|
|
283
|
+ */
|
|
284
|
+ $this->connectUser('joelle', 'toor');
|
|
285
|
+ $this->isResponseSuccess();
|
|
286
|
+
|
|
287
|
+ // Ce groupe appartient a joelle
|
|
288
|
+ $groupe_de_joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Le groupe de joelle');
|
|
289
|
+
|
|
290
|
+ $this->procedure_add_element(
|
|
291
|
+ 'Element mis dans le groupe de joelle',
|
|
292
|
+ 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
293
|
+ array($hardtek->getId(), $tribe->getId()),
|
|
294
|
+ $groupe_de_joelle->getSlug()
|
|
295
|
+ );
|
|
296
|
+
|
|
297
|
+ $this->isResponseRedirection();
|
|
298
|
+ $this->followRedirection();
|
|
299
|
+ $this->isResponseSuccess();
|
|
300
|
+
|
|
301
|
+ $this->exist('li:contains("Element mis dans le groupe de joelle")');
|
|
302
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
303
|
+ ->findOneByName('Element mis dans le groupe de joelle')
|
|
304
|
+ ;
|
|
305
|
+ $this->assertTrue(!is_null($element));
|
|
306
|
+
|
|
307
|
+ if (!is_null($element))
|
|
308
|
+ {
|
|
309
|
+ $this->assertEquals($groupe_de_joelle->getId(), $element->getGroup()->getId());
|
|
310
|
+ }
|
|
311
|
+ else
|
|
312
|
+ {
|
|
313
|
+ $this->assertTrue(false);
|
|
314
|
+ }
|
|
315
|
+ }
|
|
316
|
+
|
|
317
|
+ /**
|
|
318
|
+ * L'ajout a un group qui n'est pas a sois, ou qui n'est pas open
|
|
319
|
+ * doit être impossible.
|
|
320
|
+ */
|
|
321
|
+ public function testAddElementAtGroupFailure()
|
|
322
|
+ {
|
|
323
|
+ $this->connectUser('bux', 'toor');
|
|
324
|
+ // Un groupe no open
|
|
325
|
+ $dudeldrum = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
|
|
326
|
+
|
|
327
|
+ $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
|
|
328
|
+ $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
|
|
329
|
+
|
|
330
|
+ // Nous tentons d'ouvrir l'url d'ajout d'élément avec un groupe qui n'est pas ouvert
|
|
331
|
+ // et qui n'appartient pas a l'utilisateur connecté
|
|
332
|
+ $this->crawler = $this->client->request(
|
|
333
|
+ 'POST',
|
|
334
|
+ $this->generateUrl('element_add', array('group_slug' => $dudeldrum->getSlug())),
|
|
335
|
+ array(
|
|
336
|
+ 'element_add[name]' => 'Yohoho trululu',
|
|
337
|
+ 'element_add[url]' => 'http://www.youtube.com/watch?v=WC8qb_of04E',
|
|
338
|
+ 'element_add[tags]['.$hardtek->getId().']' => $hardtek->getId(),
|
|
339
|
+ 'element_add[tags]['.$tribe->getId().']' => $tribe->getId()
|
|
340
|
+ )
|
|
341
|
+ );
|
|
342
|
+
|
|
343
|
+ $this->isResponseNotFound();
|
|
344
|
+ }
|
|
345
|
+
|
|
346
|
+}
|