|
@@ -0,0 +1,230 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Tests\Controller;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\lib\FunctionalTest;
|
|
6
|
+
|
|
7
|
+class MynetworkControllerTest extends FunctionalTest
|
|
8
|
+{
|
|
9
|
+ /**
|
|
10
|
+ * Test de l'affichage de la page "mon réseau"
|
|
11
|
+ */
|
|
12
|
+ public function testMyNetwork()
|
|
13
|
+ {
|
|
14
|
+ /**
|
|
15
|
+ * Avec l'utilisateur 'bux' , qui d'après les fixtures suis: jean, paul,
|
|
16
|
+ * les groupes DUDELDRUM et Fans de psytrance
|
|
17
|
+ * et est suivis par joelle
|
|
18
|
+ */
|
|
19
|
+ $this->connectUser('bux', 'toor');
|
|
20
|
+ $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
|
|
21
|
+ $this->clickOnLink($link);
|
|
22
|
+ $this->isResponseSuccess();
|
|
23
|
+
|
|
24
|
+ // Récupération des entités
|
|
25
|
+ $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('jean');
|
|
26
|
+ $paul = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('paul');
|
|
27
|
+ $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
|
|
28
|
+ $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
|
|
29
|
+ $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
|
|
30
|
+
|
|
31
|
+ $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $jean->getSlug())).'"]');
|
|
32
|
+ $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $paul->getSlug())).'"]');
|
|
33
|
+ $this->exist('ul#followers_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
|
|
34
|
+ $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())).'"]');
|
|
35
|
+ $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Fans_de_psytrance->getSlug())).'"]');
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ /**
|
|
39
|
+ * Test de la recherche
|
|
40
|
+ */
|
|
41
|
+ public function testSearch()
|
|
42
|
+ {
|
|
43
|
+ $this->connectUser('bux', 'toor');
|
|
44
|
+ $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
|
|
45
|
+ $this->clickOnLink($link);
|
|
46
|
+ $this->isResponseSuccess();
|
|
47
|
+ $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_search').'"]');
|
|
48
|
+ $this->clickOnLink($link);
|
|
49
|
+ $this->isResponseSuccess();
|
|
50
|
+
|
|
51
|
+ $this->exist('form[action="'.($url = $this->generateUrl('mynetwork_search')).'"]');
|
|
52
|
+ $this->exist('form[action="'.$url.'"] input[id="form_string"]');
|
|
53
|
+ $this->exist('form[action="'.$url.'"] input[type="submit"]');
|
|
54
|
+
|
|
55
|
+ $bob = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bob');
|
|
56
|
+ // On va rechercher l'utilisateur bob
|
|
57
|
+ $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
|
|
58
|
+ $form['form[string]'] = 'bob';
|
|
59
|
+ $this->submit($form);
|
|
60
|
+ $this->outputDebug();
|
|
61
|
+ $this->isResponseSuccess();
|
|
62
|
+
|
|
63
|
+ // On trouve bob
|
|
64
|
+ $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $bob->getSlug())).'"]');
|
|
65
|
+
|
|
66
|
+ $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
|
|
67
|
+ $Le_groupe_de_joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Le groupe de joelle');
|
|
68
|
+ // On va maintenant rechercher le groupe de joelle
|
|
69
|
+ $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
|
|
70
|
+ $form['form[string]'] = 'joelle';
|
|
71
|
+ $this->submit($form);
|
|
72
|
+ $this->isResponseSuccess();
|
|
73
|
+
|
|
74
|
+ // On trouve joelle mais aussi son groupe (il y a joelle dans le nom)
|
|
75
|
+ $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
|
|
76
|
+ $this->exist('ul#search_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Le_groupe_de_joelle->getSlug())).'"]');
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ /**
|
|
80
|
+ * Test de l'action 'suivre' et 'ne plus suivre' sur un user
|
|
81
|
+ */
|
|
82
|
+ public function testUserFollow()
|
|
83
|
+ {
|
|
84
|
+ // Connection de bob
|
|
85
|
+ $this->connectUser('bob', 'toor');
|
|
86
|
+
|
|
87
|
+ // Récupération des entités (bob ne les suit pas)
|
|
88
|
+ $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bux');
|
|
89
|
+
|
|
90
|
+ // On tente de récupérer l'entité FollowUser
|
|
91
|
+ $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
|
|
92
|
+ ->findOneBy(array(
|
|
93
|
+ 'follower' => $this->getUser()->getId(),
|
|
94
|
+ 'followed' => $bux->getId()
|
|
95
|
+ ))
|
|
96
|
+ ;
|
|
97
|
+
|
|
98
|
+ // Mais celle-ci doit-être innexistante
|
|
99
|
+ $this->assertTrue(is_null($FollowUser));
|
|
100
|
+
|
|
101
|
+ // Ouverture de la page d'un user (bux)
|
|
102
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('show_user', array('slug' => $bux->getSlug())));
|
|
103
|
+ $this->isResponseSuccess();
|
|
104
|
+
|
|
105
|
+ $url_follow = $this->generateUrl('follow', array(
|
|
106
|
+ 'type' => 'user',
|
|
107
|
+ 'id' => $bux->getId(),
|
|
108
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
109
|
+ ));
|
|
110
|
+
|
|
111
|
+ // On lance l'action de suivre
|
|
112
|
+ $this->exist('a.notfollowing[href="'.$url_follow.'"]');
|
|
113
|
+ $link = $this->selectLink('a[href="'.$url_follow.'"]');
|
|
114
|
+ $this->clickOnLink($link);
|
|
115
|
+
|
|
116
|
+ $this->isResponseRedirection();
|
|
117
|
+ $this->followRedirection();
|
|
118
|
+ $this->isResponseSuccess();
|
|
119
|
+
|
|
120
|
+ $this->exist('a.following[href="'.$url_follow.'"]');
|
|
121
|
+
|
|
122
|
+ // On tente de récupérer l'entité FollowUser
|
|
123
|
+ $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
|
|
124
|
+ ->findOneBy(array(
|
|
125
|
+ 'follower' => $this->getUser()->getId(),
|
|
126
|
+ 'followed' => $bux->getId()
|
|
127
|
+ ))
|
|
128
|
+ ;
|
|
129
|
+
|
|
130
|
+ // Celle-ci doit exister maintenant
|
|
131
|
+ $this->assertTrue(!is_null($FollowUser));
|
|
132
|
+
|
|
133
|
+ // On lance l'action de ne plus suivre
|
|
134
|
+ $link = $this->selectLink('a[href="'.$url_follow.'"]');
|
|
135
|
+ $this->clickOnLink($link);
|
|
136
|
+
|
|
137
|
+ $this->isResponseRedirection();
|
|
138
|
+ $this->followRedirection();
|
|
139
|
+ $this->isResponseSuccess();
|
|
140
|
+
|
|
141
|
+ $this->exist('a.notfollowing[href="'.$url_follow.'"]');
|
|
142
|
+
|
|
143
|
+ // On tente de récupérer l'entité FollowUser
|
|
144
|
+ $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
|
|
145
|
+ ->findOneBy(array(
|
|
146
|
+ 'follower' => $this->getUser()->getId(),
|
|
147
|
+ 'followed' => $bux->getId()
|
|
148
|
+ ))
|
|
149
|
+ ;
|
|
150
|
+
|
|
151
|
+ // Celle-ci ne doit plus exister maintenant
|
|
152
|
+ $this->assertTrue(is_null($FollowUser));
|
|
153
|
+ }
|
|
154
|
+
|
|
155
|
+ /**
|
|
156
|
+ * Test de l'action 'suivre' et 'ne plus suivre' sur un groupe
|
|
157
|
+ */
|
|
158
|
+ public function testGroupFollow()
|
|
159
|
+ {
|
|
160
|
+ // Connection de bob
|
|
161
|
+ $this->connectUser('bob', 'toor');
|
|
162
|
+
|
|
163
|
+ // Récupération des entités (bob ne les suit pas)
|
|
164
|
+ $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
|
|
165
|
+
|
|
166
|
+ // On tente de récupérer l'entité FollowUser
|
|
167
|
+ $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
|
|
168
|
+ ->findOneBy(array(
|
|
169
|
+ 'follower' => $this->getUser()->getId(),
|
|
170
|
+ 'group' => $DUDELDRUM->getId()
|
|
171
|
+ ))
|
|
172
|
+ ;
|
|
173
|
+
|
|
174
|
+ // Mais celle-ci doit-être innexistante
|
|
175
|
+ $this->assertTrue(is_null($FollowGroup));
|
|
176
|
+
|
|
177
|
+ // Ouverture de la page d'un user (bux)
|
|
178
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())));
|
|
179
|
+ $this->isResponseSuccess();
|
|
180
|
+
|
|
181
|
+ $url_follow = $this->generateUrl('follow', array(
|
|
182
|
+ 'type' => 'group',
|
|
183
|
+ 'id' => $DUDELDRUM->getId(),
|
|
184
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
185
|
+ ));
|
|
186
|
+
|
|
187
|
+ // On lance l'action de suivre
|
|
188
|
+ $this->exist('a.notfollowing[href="'.$url_follow.'"]');
|
|
189
|
+ $link = $this->selectLink('a[href="'.$url_follow.'"]');
|
|
190
|
+ $this->clickOnLink($link);
|
|
191
|
+
|
|
192
|
+ $this->isResponseRedirection();
|
|
193
|
+ $this->followRedirection();
|
|
194
|
+ $this->isResponseSuccess();
|
|
195
|
+
|
|
196
|
+ $this->exist('a.following[href="'.$url_follow.'"]');
|
|
197
|
+
|
|
198
|
+ // On tente de récupérer l'entité FollowUser
|
|
199
|
+ $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
|
|
200
|
+ ->findOneBy(array(
|
|
201
|
+ 'follower' => $this->getUser()->getId(),
|
|
202
|
+ 'group' => $DUDELDRUM->getId()
|
|
203
|
+ ))
|
|
204
|
+ ;
|
|
205
|
+
|
|
206
|
+ // Celle-ci doit exister maintenant
|
|
207
|
+ $this->assertTrue(!is_null($FollowGroup));
|
|
208
|
+
|
|
209
|
+ // On lance l'action de ne plus suivre
|
|
210
|
+ $link = $this->selectLink('a[href="'.$url_follow.'"]');
|
|
211
|
+ $this->clickOnLink($link);
|
|
212
|
+
|
|
213
|
+ $this->isResponseRedirection();
|
|
214
|
+ $this->followRedirection();
|
|
215
|
+ $this->isResponseSuccess();
|
|
216
|
+
|
|
217
|
+ $this->exist('a.notfollowing[href="'.$url_follow.'"]');
|
|
218
|
+
|
|
219
|
+ // On tente de récupérer l'entité FollowUser
|
|
220
|
+ $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
|
|
221
|
+ ->findOneBy(array(
|
|
222
|
+ 'follower' => $this->getUser()->getId(),
|
|
223
|
+ 'group' => $DUDELDRUM->getId()
|
|
224
|
+ ))
|
|
225
|
+ ;
|
|
226
|
+
|
|
227
|
+ // Celle-ci ne doit plus exister maintenant
|
|
228
|
+ $this->assertTrue(is_null($FollowGroup));
|
|
229
|
+ }
|
|
230
|
+}
|