|
@@ -7,217 +7,217 @@ use Muzich\CoreBundle\lib\FunctionalTest;
|
7
|
7
|
class FavoriteControllerTest extends FunctionalTest
|
8
|
8
|
{
|
9
|
9
|
|
10
|
|
-// /**
|
11
|
|
-// * Test du listing de ses favoris
|
12
|
|
-// */
|
13
|
|
-// public function testMyFavorites()
|
14
|
|
-// {
|
15
|
|
-// $this->client = self::createClient();
|
16
|
|
-// $this->connectUser('bux', 'toor');
|
17
|
|
-//
|
18
|
|
-// // On va cliquer sur le lien 'Mes favoris'
|
19
|
|
-// $this->exist('a[href="'.($url = $this->generateUrl('favorites_my_list')).'"]');
|
20
|
|
-// $link = $this->selectLink('a[href="'.$url.'"]');
|
21
|
|
-// // On clique dessus
|
22
|
|
-// $this->clickOnLink($link);
|
23
|
|
-// $this->isResponseSuccess();
|
24
|
|
-//
|
25
|
|
-// $elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
26
|
|
-// SELECT e FROM MuzichCoreBundle:Element e
|
27
|
|
-// LEFT JOIN e.elements_favorites ef
|
28
|
|
-// WHERE ef.user = :uid
|
29
|
|
-// ")->setParameter('uid', $this->getUser()->getId())
|
30
|
|
-// ->getResult()
|
31
|
|
-// ;
|
32
|
|
-//
|
33
|
|
-// $this->assertTrue(!is_null($elements));
|
34
|
|
-//
|
35
|
|
-// if (count($elements))
|
36
|
|
-// {
|
37
|
|
-// foreach ($elements as $element)
|
38
|
|
-// {
|
39
|
|
-// $this->exist('li:contains("'.$element->getName().'")');
|
40
|
|
-// }
|
41
|
|
-// }
|
42
|
|
-// }
|
43
|
|
-//
|
44
|
|
-// /**
|
45
|
|
-// * Test de la page listant les favoris d'un utilisateur
|
46
|
|
-// */
|
47
|
|
-// public function testHisFavorites()
|
48
|
|
-// {
|
49
|
|
-// $this->client = self::createClient();
|
50
|
|
-// $this->connectUser('bob', 'toor');
|
51
|
|
-//
|
52
|
|
-// $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
53
|
|
-// ->findOneByUsername('bux')
|
54
|
|
-// ;
|
55
|
|
-//
|
56
|
|
-// // On se rend sur sa page des favoris de bux
|
57
|
|
-// $this->crawler = $this->client->request('GET', $this->generateUrl('favorite_user_list', array('slug' => 'bux')));
|
58
|
|
-//
|
59
|
|
-// $elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
60
|
|
-// SELECT e FROM MuzichCoreBundle:Element e
|
61
|
|
-// LEFT JOIN e.elements_favorites ef
|
62
|
|
-// WHERE ef.user = :uid
|
63
|
|
-// ")->setParameter('uid', $bux->getId())
|
64
|
|
-// ->getResult()
|
65
|
|
-// ;
|
66
|
|
-//
|
67
|
|
-// $this->assertTrue(!is_null($elements));
|
68
|
|
-//
|
69
|
|
-// if (count($elements))
|
70
|
|
-// {
|
71
|
|
-// foreach ($elements as $element)
|
72
|
|
-// {
|
73
|
|
-// $this->exist('li:contains("'.$element->getName().'")');
|
74
|
|
-// }
|
75
|
|
-// }
|
76
|
|
-// }
|
77
|
|
-//
|
78
|
|
-// /**
|
79
|
|
-// * Test d'ajout en favori un element, puis son retrait
|
80
|
|
-// * Ce test dépend actuellement du fait que l'élément testé se truove sur la
|
81
|
|
-// * page du groupe en question
|
82
|
|
-// */
|
83
|
|
-// public function testFavoritesManagement()
|
84
|
|
-// {
|
85
|
|
-// $this->client = self::createClient();
|
86
|
|
-// $this->connectUser('bob', 'toor');
|
87
|
|
-//
|
88
|
|
-// // On se rend sur la page du groupe Dudeldrum
|
89
|
|
-// $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
|
90
|
|
-// ->findOneBySlug('dudeldrum')
|
91
|
|
-// ->getSingleResult()
|
92
|
|
-// ;
|
93
|
|
-//
|
94
|
|
-// $element_DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
95
|
|
-// ->findOneByName('DUDELDRUM')
|
96
|
|
-// ;
|
97
|
|
-//
|
98
|
|
-// // En base l'enregistrement n'existe pas encore
|
99
|
|
-// $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
100
|
|
-// 'user' => $this->getUser()->getId(),
|
101
|
|
-// 'element' => $element_DUDELDRUM->getId()
|
102
|
|
-// ));
|
103
|
|
-//
|
104
|
|
-// $this->assertTrue(is_null($favorite));
|
105
|
|
-//
|
106
|
|
-// $this->crawler = $this->client->request(
|
107
|
|
-// 'GET',
|
108
|
|
-// $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug()))
|
109
|
|
-// );
|
110
|
|
-//
|
111
|
|
-// $this->isResponseSuccess();
|
112
|
|
-//
|
113
|
|
-// // L'élément est présent sur la page
|
114
|
|
-// $this->exist('li:contains("DUDELDRUM")');
|
115
|
|
-// $this->exist('a[href="'.($url = $this->generateUrl('favorite_add', array(
|
116
|
|
-// 'id' => $element_DUDELDRUM->getId(),
|
117
|
|
-// 'token' => $this->getUser()->getPersonalHash()
|
118
|
|
-// ))).'"]');
|
119
|
|
-// $link = $this->selectLink('a[href="'.$url.'"]');
|
120
|
|
-// $this->clickOnLink($link);
|
121
|
|
-//
|
122
|
|
-// $this->isResponseRedirection();
|
123
|
|
-// $this->followRedirection();
|
124
|
|
-// $this->isResponseSuccess();
|
125
|
|
-//
|
126
|
|
-// // Le lien pour ajouter aux favoris a disparus
|
127
|
|
-// $this->exist('li:contains("DUDELDRUM")');
|
128
|
|
-// $this->notExist('a[href="'.$url.'"]');
|
129
|
|
-//
|
130
|
|
-// // Il a laissé place aux lien pour le retirer
|
131
|
|
-// $this->exist('a[href="'.($url_rm = $this->generateUrl('favorite_remove', array(
|
132
|
|
-// 'id' => $element_DUDELDRUM->getId(),
|
133
|
|
-// 'token' => $this->getUser()->getPersonalHash()
|
134
|
|
-// ))).'"]');
|
135
|
|
-//
|
136
|
|
-// // En base l'enregistrement existe
|
137
|
|
-// $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
138
|
|
-// 'user' => $this->getUser()->getId(),
|
139
|
|
-// 'element' => $element_DUDELDRUM->getId()
|
140
|
|
-// ));
|
141
|
|
-//
|
142
|
|
-// $this->assertTrue(!is_null($favorite));
|
143
|
|
-//
|
144
|
|
-// // On se rend sur la page de ses favoris
|
145
|
|
-// $this->crawler = $this->client->request('GET', $this->generateUrl('favorites_my_list'));
|
146
|
|
-//
|
147
|
|
-// $this->exist('li:contains("DUDELDRUM")');
|
148
|
|
-//
|
149
|
|
-// // On va maintenant le retirer de nox favoris
|
150
|
|
-// $this->exist('a[href="'.$url_rm.'"]');
|
151
|
|
-// $link = $this->selectLink('a[href="'.$url_rm.'"]');
|
152
|
|
-// $this->clickOnLink($link);
|
153
|
|
-//
|
154
|
|
-// $this->isResponseRedirection();
|
155
|
|
-// $this->followRedirection();
|
156
|
|
-// $this->isResponseSuccess();
|
157
|
|
-//
|
158
|
|
-// $this->NotExist('li:contains("DUDELDRUM")');
|
159
|
|
-//
|
160
|
|
-// // En base l'enregistrement a été supprimé
|
161
|
|
-// $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
162
|
|
-// 'user' => $this->getUser()->getId(),
|
163
|
|
-// 'element' => $element_DUDELDRUM->getId()
|
164
|
|
-// ));
|
165
|
|
-//
|
166
|
|
-// $this->assertTrue(is_null($favorite));
|
167
|
|
-// }
|
168
|
|
-//
|
169
|
|
-// public function testAjax()
|
170
|
|
-// {
|
171
|
|
-// $this->client = self::createClient();
|
172
|
|
-// $this->connectUser('bux', 'toor');
|
173
|
|
-//
|
174
|
|
-// $bux = $this->getUser();
|
175
|
|
-//
|
176
|
|
-// $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
177
|
|
-// ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
178
|
|
-// ;
|
179
|
|
-//
|
180
|
|
-// // Ajout d'un élément en favoris
|
181
|
|
-// // Il ajoute cet élément en favoris
|
182
|
|
-// $url = $this->generateUrl('favorite_add', array(
|
183
|
|
-// 'id' => $element->getId(),
|
184
|
|
-// 'token' => $bux->getPersonalHash()
|
185
|
|
-// ));
|
186
|
|
-//
|
187
|
|
-// $crawler = $this->client->request('GET', $url, array(), array(), array(
|
188
|
|
-// 'HTTP_X-Requested-With' => 'XMLHttpRequest',
|
189
|
|
-// ));
|
190
|
|
-//
|
191
|
|
-// $this->isResponseSuccess();
|
192
|
|
-//
|
193
|
|
-// // On contrôle la présence du favoris
|
194
|
|
-// $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
195
|
|
-// ->findOneBy(array(
|
196
|
|
-// 'user' => $bux->getId(),
|
197
|
|
-// 'element' => $element->getId()
|
198
|
|
-// ));
|
199
|
|
-//
|
200
|
|
-// $this->assertTrue(!is_null($fav));
|
201
|
|
-//
|
202
|
|
-// // On enlève des favoris
|
203
|
|
-// $url = $this->generateUrl('favorite_remove', array(
|
204
|
|
-// 'id' => $element->getId(),
|
205
|
|
-// 'token' => $bux->getPersonalHash()
|
206
|
|
-// ));
|
207
|
|
-//
|
208
|
|
-// $crawler = $this->client->request('GET', $url, array(), array(), array(
|
209
|
|
-// 'HTTP_X-Requested-With' => 'XMLHttpRequest',
|
210
|
|
-// ));
|
211
|
|
-//
|
212
|
|
-// // On contrôle l'absence du favoris
|
213
|
|
-// $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
214
|
|
-// ->findOneBy(array(
|
215
|
|
-// 'user' => $bux->getId(),
|
216
|
|
-// 'element' => $element->getId()
|
217
|
|
-// ));
|
218
|
|
-//
|
219
|
|
-// $this->assertTrue(is_null($fav));
|
220
|
|
-// }
|
|
10
|
+ /**
|
|
11
|
+ * Test du listing de ses favoris
|
|
12
|
+ */
|
|
13
|
+ public function testMyFavorites()
|
|
14
|
+ {
|
|
15
|
+ $this->client = self::createClient();
|
|
16
|
+ $this->connectUser('bux', 'toor');
|
|
17
|
+
|
|
18
|
+ // On va cliquer sur le lien 'Mes favoris'
|
|
19
|
+ $this->exist('a[href="'.($url = $this->generateUrl('favorites_my_list')).'"]');
|
|
20
|
+ $link = $this->selectLink('a[href="'.$url.'"]');
|
|
21
|
+ // On clique dessus
|
|
22
|
+ $this->clickOnLink($link);
|
|
23
|
+ $this->isResponseSuccess();
|
|
24
|
+
|
|
25
|
+ $elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
|
26
|
+ SELECT e FROM MuzichCoreBundle:Element e
|
|
27
|
+ LEFT JOIN e.elements_favorites ef
|
|
28
|
+ WHERE ef.user = :uid
|
|
29
|
+ ")->setParameter('uid', $this->getUser()->getId())
|
|
30
|
+ ->getResult()
|
|
31
|
+ ;
|
|
32
|
+
|
|
33
|
+ $this->assertTrue(!is_null($elements));
|
|
34
|
+
|
|
35
|
+ if (count($elements))
|
|
36
|
+ {
|
|
37
|
+ foreach ($elements as $element)
|
|
38
|
+ {
|
|
39
|
+ $this->exist('li:contains("'.$element->getName().'")');
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ /**
|
|
45
|
+ * Test de la page listant les favoris d'un utilisateur
|
|
46
|
+ */
|
|
47
|
+ public function testHisFavorites()
|
|
48
|
+ {
|
|
49
|
+ $this->client = self::createClient();
|
|
50
|
+ $this->connectUser('bob', 'toor');
|
|
51
|
+
|
|
52
|
+ $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
53
|
+ ->findOneByUsername('bux')
|
|
54
|
+ ;
|
|
55
|
+
|
|
56
|
+ // On se rend sur sa page des favoris de bux
|
|
57
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('favorite_user_list', array('slug' => 'bux')));
|
|
58
|
+
|
|
59
|
+ $elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
|
60
|
+ SELECT e FROM MuzichCoreBundle:Element e
|
|
61
|
+ LEFT JOIN e.elements_favorites ef
|
|
62
|
+ WHERE ef.user = :uid
|
|
63
|
+ ")->setParameter('uid', $bux->getId())
|
|
64
|
+ ->getResult()
|
|
65
|
+ ;
|
|
66
|
+
|
|
67
|
+ $this->assertTrue(!is_null($elements));
|
|
68
|
+
|
|
69
|
+ if (count($elements))
|
|
70
|
+ {
|
|
71
|
+ foreach ($elements as $element)
|
|
72
|
+ {
|
|
73
|
+ $this->exist('li:contains("'.$element->getName().'")');
|
|
74
|
+ }
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ /**
|
|
79
|
+ * Test d'ajout en favori un element, puis son retrait
|
|
80
|
+ * Ce test dépend actuellement du fait que l'élément testé se truove sur la
|
|
81
|
+ * page du groupe en question
|
|
82
|
+ */
|
|
83
|
+ public function testFavoritesManagement()
|
|
84
|
+ {
|
|
85
|
+ $this->client = self::createClient();
|
|
86
|
+ $this->connectUser('bob', 'toor');
|
|
87
|
+
|
|
88
|
+ // On se rend sur la page du groupe Dudeldrum
|
|
89
|
+ $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
|
|
90
|
+ ->findOneBySlug('dudeldrum')
|
|
91
|
+ ->getSingleResult()
|
|
92
|
+ ;
|
|
93
|
+
|
|
94
|
+ $element_DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
95
|
+ ->findOneByName('DUDELDRUM')
|
|
96
|
+ ;
|
|
97
|
+
|
|
98
|
+ // En base l'enregistrement n'existe pas encore
|
|
99
|
+ $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
|
100
|
+ 'user' => $this->getUser()->getId(),
|
|
101
|
+ 'element' => $element_DUDELDRUM->getId()
|
|
102
|
+ ));
|
|
103
|
+
|
|
104
|
+ $this->assertTrue(is_null($favorite));
|
|
105
|
+
|
|
106
|
+ $this->crawler = $this->client->request(
|
|
107
|
+ 'GET',
|
|
108
|
+ $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug()))
|
|
109
|
+ );
|
|
110
|
+
|
|
111
|
+ $this->isResponseSuccess();
|
|
112
|
+
|
|
113
|
+ // L'élément est présent sur la page
|
|
114
|
+ $this->exist('li:contains("DUDELDRUM")');
|
|
115
|
+ $this->exist('a[href="'.($url = $this->generateUrl('favorite_add', array(
|
|
116
|
+ 'id' => $element_DUDELDRUM->getId(),
|
|
117
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
118
|
+ ))).'"]');
|
|
119
|
+ $link = $this->selectLink('a[href="'.$url.'"]');
|
|
120
|
+ $this->clickOnLink($link);
|
|
121
|
+
|
|
122
|
+ $this->isResponseRedirection();
|
|
123
|
+ $this->followRedirection();
|
|
124
|
+ $this->isResponseSuccess();
|
|
125
|
+
|
|
126
|
+ // Le lien pour ajouter aux favoris a disparus
|
|
127
|
+ $this->exist('li:contains("DUDELDRUM")');
|
|
128
|
+ $this->notExist('a[href="'.$url.'"]');
|
|
129
|
+
|
|
130
|
+ // Il a laissé place aux lien pour le retirer
|
|
131
|
+ $this->exist('a[href="'.($url_rm = $this->generateUrl('favorite_remove', array(
|
|
132
|
+ 'id' => $element_DUDELDRUM->getId(),
|
|
133
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
134
|
+ ))).'"]');
|
|
135
|
+
|
|
136
|
+ // En base l'enregistrement existe
|
|
137
|
+ $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
|
138
|
+ 'user' => $this->getUser()->getId(),
|
|
139
|
+ 'element' => $element_DUDELDRUM->getId()
|
|
140
|
+ ));
|
|
141
|
+
|
|
142
|
+ $this->assertTrue(!is_null($favorite));
|
|
143
|
+
|
|
144
|
+ // On se rend sur la page de ses favoris
|
|
145
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('favorites_my_list'));
|
|
146
|
+
|
|
147
|
+ $this->exist('li:contains("DUDELDRUM")');
|
|
148
|
+
|
|
149
|
+ // On va maintenant le retirer de nox favoris
|
|
150
|
+ $this->exist('a[href="'.$url_rm.'"]');
|
|
151
|
+ $link = $this->selectLink('a[href="'.$url_rm.'"]');
|
|
152
|
+ $this->clickOnLink($link);
|
|
153
|
+
|
|
154
|
+ $this->isResponseRedirection();
|
|
155
|
+ $this->followRedirection();
|
|
156
|
+ $this->isResponseSuccess();
|
|
157
|
+
|
|
158
|
+ $this->NotExist('li:contains("DUDELDRUM")');
|
|
159
|
+
|
|
160
|
+ // En base l'enregistrement a été supprimé
|
|
161
|
+ $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
|
162
|
+ 'user' => $this->getUser()->getId(),
|
|
163
|
+ 'element' => $element_DUDELDRUM->getId()
|
|
164
|
+ ));
|
|
165
|
+
|
|
166
|
+ $this->assertTrue(is_null($favorite));
|
|
167
|
+ }
|
|
168
|
+
|
|
169
|
+ public function testAjax()
|
|
170
|
+ {
|
|
171
|
+ $this->client = self::createClient();
|
|
172
|
+ $this->connectUser('bux', 'toor');
|
|
173
|
+
|
|
174
|
+ $bux = $this->getUser();
|
|
175
|
+
|
|
176
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
177
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
178
|
+ ;
|
|
179
|
+
|
|
180
|
+ // Ajout d'un élément en favoris
|
|
181
|
+ // Il ajoute cet élément en favoris
|
|
182
|
+ $url = $this->generateUrl('favorite_add', array(
|
|
183
|
+ 'id' => $element->getId(),
|
|
184
|
+ 'token' => $bux->getPersonalHash()
|
|
185
|
+ ));
|
|
186
|
+
|
|
187
|
+ $crawler = $this->client->request('GET', $url, array(), array(), array(
|
|
188
|
+ 'HTTP_X-Requested-With' => 'XMLHttpRequest',
|
|
189
|
+ ));
|
|
190
|
+
|
|
191
|
+ $this->isResponseSuccess();
|
|
192
|
+
|
|
193
|
+ // On contrôle la présence du favoris
|
|
194
|
+ $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
|
195
|
+ ->findOneBy(array(
|
|
196
|
+ 'user' => $bux->getId(),
|
|
197
|
+ 'element' => $element->getId()
|
|
198
|
+ ));
|
|
199
|
+
|
|
200
|
+ $this->assertTrue(!is_null($fav));
|
|
201
|
+
|
|
202
|
+ // On enlève des favoris
|
|
203
|
+ $url = $this->generateUrl('favorite_remove', array(
|
|
204
|
+ 'id' => $element->getId(),
|
|
205
|
+ 'token' => $bux->getPersonalHash()
|
|
206
|
+ ));
|
|
207
|
+
|
|
208
|
+ $crawler = $this->client->request('GET', $url, array(), array(), array(
|
|
209
|
+ 'HTTP_X-Requested-With' => 'XMLHttpRequest',
|
|
210
|
+ ));
|
|
211
|
+
|
|
212
|
+ // On contrôle l'absence du favoris
|
|
213
|
+ $fav = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
|
214
|
+ ->findOneBy(array(
|
|
215
|
+ 'user' => $bux->getId(),
|
|
216
|
+ 'element' => $element->getId()
|
|
217
|
+ ));
|
|
218
|
+
|
|
219
|
+ $this->assertTrue(is_null($fav));
|
|
220
|
+ }
|
221
|
221
|
|
222
|
222
|
/**
|
223
|
223
|
* Test de la fonction ajax de récupération de plus de favoris
|