|
@@ -0,0 +1,210 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Tests\Controller;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\lib\FunctionalTest;
|
|
6
|
+use Muzich\CoreBundle\Managers\CommentsManager;
|
|
7
|
+
|
|
8
|
+/**
|
|
9
|
+ * Test des commentaires. Doit couvrir:
|
|
10
|
+ *
|
|
11
|
+ * * La consultation de commentaires en fixtures
|
|
12
|
+ * * L'ajout de commentaire
|
|
13
|
+ * * La modification d'un commentaire
|
|
14
|
+ * * La suppression d'un commentaire
|
|
15
|
+ *
|
|
16
|
+ */
|
|
17
|
+class CommentControllerTest extends FunctionalTest
|
|
18
|
+{
|
|
19
|
+
|
|
20
|
+ public function testView()
|
|
21
|
+ {
|
|
22
|
+ $this->client = self::createClient();
|
|
23
|
+ $this->connectUser('paul', 'toor');
|
|
24
|
+
|
|
25
|
+ // On est sur la page home, d'après les fixtures on a des coms en dom
|
|
26
|
+ $this->exist('div.comments:contains("C\'est trop bon hein ?")');
|
|
27
|
+ $this->exist('div.comments:contains("C\'est pas mal en effet")');
|
|
28
|
+ $this->exist('li.element a.display_comments');
|
|
29
|
+ $this->exist('li.element a.hide_comments');
|
|
30
|
+ $this->exist('li.element a.add_comment');
|
|
31
|
+ $this->exist('div.comments a.add_comment');
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ public function testAddEditDelete()
|
|
35
|
+ {
|
|
36
|
+ $this->client = self::createClient();
|
|
37
|
+ $this->connectUser('paul', 'toor');
|
|
38
|
+
|
|
39
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
40
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
41
|
+ ;
|
|
42
|
+
|
|
43
|
+ // On va ajouter un commentaire a la toute dernière musique posté par bux
|
|
44
|
+ $this->crawler = $this->client->request(
|
|
45
|
+ 'POST',
|
|
46
|
+ $this->generateUrl('ajax_add_comment', array(
|
|
47
|
+ 'element_id' => $element->getId(),
|
|
48
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
49
|
+ )),
|
|
50
|
+ array(
|
|
51
|
+ 'comment' => "J'ai réécouté et ouaa je kiff BrOOO"
|
|
52
|
+
|
|
53
|
+ ),
|
|
54
|
+ array(),
|
|
55
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
56
|
+ );
|
|
57
|
+
|
|
58
|
+ $this->isResponseSuccess();
|
|
59
|
+
|
|
60
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
61
|
+ $this->assertEquals($response['status'], 'success');
|
|
62
|
+
|
|
63
|
+ // On ré-affiche la page home pour voir si le commentaire y est
|
|
64
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
|
|
65
|
+ $this->exist('div.comments:contains("J\'ai réécouté et ouaa je kiff BrOOO")');
|
|
66
|
+
|
|
67
|
+ $extract = $this->crawler->filter('div.comments li:contains("J\'ai réécouté et ouaa je kiff BrOOO")')
|
|
68
|
+ ->extract(array('id'));
|
|
69
|
+ $id = $extract[0];
|
|
70
|
+
|
|
71
|
+ // Faut que l'on récupère la date
|
|
72
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
73
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
74
|
+ ;
|
|
75
|
+ $cm = new CommentsManager($element->getComments());
|
|
76
|
+ $comment = $cm->getLast();
|
|
77
|
+
|
|
78
|
+ $this->assertEquals($comment['c'], "J'ai réécouté et ouaa je kiff BrOOO");
|
|
79
|
+
|
|
80
|
+ // On effectue une modification de ce commentaire
|
|
81
|
+ $this->crawler = $this->client->request(
|
|
82
|
+ 'POST',
|
|
83
|
+ $this->generateUrl('ajax_update_comment', array(
|
|
84
|
+ 'element_id' => $element->getId(),
|
|
85
|
+ 'date' => $comment['d'],
|
|
86
|
+ 'dom_id' => $id,
|
|
87
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
88
|
+ )),
|
|
89
|
+ array(
|
|
90
|
+ 'comment' => "Je me modifie mon com kwaa"
|
|
91
|
+ ),
|
|
92
|
+ array(),
|
|
93
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
94
|
+ );
|
|
95
|
+
|
|
96
|
+ $this->isResponseSuccess();
|
|
97
|
+
|
|
98
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
99
|
+ $this->assertEquals($response['status'], 'success');
|
|
100
|
+
|
|
101
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
102
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
103
|
+ ;
|
|
104
|
+ $cm = new CommentsManager($element->getComments());
|
|
105
|
+ $comment = $cm->getLast();
|
|
106
|
+
|
|
107
|
+ $this->assertEquals($comment['c'], "Je me modifie mon com kwaa");
|
|
108
|
+ // Il y a une date d'edition
|
|
109
|
+ $this->assertTrue(array_key_exists('e', $comment));
|
|
110
|
+
|
|
111
|
+ // On ré-affiche la page home pour voir si le commentaire modifié y est
|
|
112
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
|
|
113
|
+ $this->exist('div.comments:contains("Je me modifie mon com kwaa")');
|
|
114
|
+
|
|
115
|
+ // maintenant on le supprime
|
|
116
|
+ $this->crawler = $this->client->request(
|
|
117
|
+ 'GET',
|
|
118
|
+ $this->generateUrl('ajax_delete_comment', array(
|
|
119
|
+ 'element_id' => $element->getId(),
|
|
120
|
+ 'date' => $comment['d'],
|
|
121
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
122
|
+ )),
|
|
123
|
+ array(),
|
|
124
|
+ array(),
|
|
125
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
126
|
+ );
|
|
127
|
+
|
|
128
|
+ $this->isResponseSuccess();
|
|
129
|
+
|
|
130
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
131
|
+ $this->assertEquals($response['status'], 'success');
|
|
132
|
+
|
|
133
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
134
|
+ ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
|
|
135
|
+ ;
|
|
136
|
+ $cm = new CommentsManager($element->getComments());
|
|
137
|
+ $comment = $cm->getLast();
|
|
138
|
+
|
|
139
|
+ $this->assertNotEquals($comment['c'], "Je me modifie mon com kwaa");
|
|
140
|
+
|
|
141
|
+ // On ré-affiche la page home pour voir si le commentaire modifié y est
|
|
142
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
|
|
143
|
+ $this->notExist('div.comments:contains("Je me modifie mon com kwaa")');
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ /**
|
|
147
|
+ * On test ici la sécurité nous empêchant de modifier / supprimer le comm
|
|
148
|
+ * d'un autre.
|
|
149
|
+ */
|
|
150
|
+ public function testFails()
|
|
151
|
+ {
|
|
152
|
+ $this->client = self::createClient();
|
|
153
|
+ $this->connectUser('paul', 'toor');
|
|
154
|
+
|
|
155
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
156
|
+ ->findOneByName('Babylon Pression - Des Tasers et des Pauvres')
|
|
157
|
+ ;
|
|
158
|
+
|
|
159
|
+ $cm = new CommentsManager($element->getComments());
|
|
160
|
+ // D'après fixtures: Ce dernier commentaire est à bux
|
|
161
|
+ $comment = $cm->getLast();
|
|
162
|
+
|
|
163
|
+ $this->assertEquals($comment['c'], "Je répond 13");
|
|
164
|
+
|
|
165
|
+ // On récupère l'id dom
|
|
166
|
+ $extract = $this->crawler->filter('div.comments li:contains("Je répond 13")')
|
|
167
|
+ ->extract(array('id'));
|
|
168
|
+ $id = $extract[0];
|
|
169
|
+
|
|
170
|
+ // On essaie de le modifier
|
|
171
|
+ $this->crawler = $this->client->request(
|
|
172
|
+ 'POST',
|
|
173
|
+ $this->generateUrl('ajax_update_comment', array(
|
|
174
|
+ 'element_id' => $element->getId(),
|
|
175
|
+ 'date' => $comment['d'],
|
|
176
|
+ 'dom_id' => $id,
|
|
177
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
178
|
+ )),
|
|
179
|
+ array(
|
|
180
|
+ 'comment' => "Je répond 13 HACKED"
|
|
181
|
+ ),
|
|
182
|
+ array(),
|
|
183
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
184
|
+ );
|
|
185
|
+
|
|
186
|
+ $this->isResponseSuccess();
|
|
187
|
+
|
|
188
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
189
|
+ $this->assertEquals($response['status'], 'error');
|
|
190
|
+
|
|
191
|
+ // On essaie de le supprimer
|
|
192
|
+ $this->crawler = $this->client->request(
|
|
193
|
+ 'GET',
|
|
194
|
+ $this->generateUrl('ajax_delete_comment', array(
|
|
195
|
+ 'element_id' => $element->getId(),
|
|
196
|
+ 'date' => $comment['d'],
|
|
197
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
198
|
+ )),
|
|
199
|
+ array(),
|
|
200
|
+ array(),
|
|
201
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
202
|
+ );
|
|
203
|
+
|
|
204
|
+ $this->isResponseSuccess();
|
|
205
|
+
|
|
206
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
207
|
+ $this->assertEquals($response['status'], 'error');
|
|
208
|
+ }
|
|
209
|
+
|
|
210
|
+}
|