]>
Commit | Line | Data |
---|---|---|
93fd4692 NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Tests\Controller; |
93fd4692 | 4 | |
769e19dc | 5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; |
eb3bd7ef | 6 | use Doctrine\ORM\AbstractQuery; |
93fd4692 | 7 | |
769e19dc | 8 | class EntryControllerTest extends WallabagCoreTestCase |
93fd4692 | 9 | { |
02d17813 JB |
10 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; |
11 | ||
3b815d2d J |
12 | public function testLogin() |
13 | { | |
14 | $client = $this->getClient(); | |
15 | ||
eb3bd7ef | 16 | $client->request('GET', '/new'); |
3b815d2d J |
17 | |
18 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
19 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
20 | } | |
21 | ||
9c0c8820 | 22 | public function testGetNew() |
93fd4692 | 23 | { |
eb3bd7ef | 24 | $this->logInAs('admin'); |
3b815d2d | 25 | $client = $this->getClient(); |
93fd4692 | 26 | |
aa6e27cf | 27 | $crawler = $client->request('GET', '/new'); |
93fd4692 NL |
28 | |
29 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9c0c8820 J |
30 | |
31 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
32 | $this->assertCount(1, $crawler->filter('button[type=submit]')); | |
33 | } | |
34 | ||
35 | public function testPostNewEmpty() | |
36 | { | |
eb3bd7ef | 37 | $this->logInAs('admin'); |
3b815d2d | 38 | $client = $this->getClient(); |
9c0c8820 J |
39 | |
40 | $crawler = $client->request('GET', '/new'); | |
41 | ||
42 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
43 | ||
44 | $form = $crawler->filter('button[type=submit]')->form(); | |
45 | ||
46 | $crawler = $client->submit($form); | |
47 | ||
48 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
49 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(array('_text'))); | |
50 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
51 | } | |
52 | ||
53 | public function testPostNewOk() | |
54 | { | |
eb3bd7ef | 55 | $this->logInAs('admin'); |
3b815d2d | 56 | $client = $this->getClient(); |
9c0c8820 J |
57 | |
58 | $crawler = $client->request('GET', '/new'); | |
59 | ||
60 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
61 | ||
62 | $form = $crawler->filter('button[type=submit]')->form(); | |
63 | ||
64 | $data = array( | |
02d17813 | 65 | 'entry[url]' => $this->url, |
9c0c8820 J |
66 | ); |
67 | ||
68 | $client->submit($form, $data); | |
69 | ||
70 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
71 | ||
72 | $crawler = $client->followRedirect(); | |
73 | ||
3b815d2d | 74 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); |
34c06cab | 75 | $this->assertContains('Google', $alert[0]); |
9c0c8820 J |
76 | } |
77 | ||
78 | public function testArchive() | |
79 | { | |
eb3bd7ef | 80 | $this->logInAs('admin'); |
3b815d2d | 81 | $client = $this->getClient(); |
9c0c8820 | 82 | |
9fb6ac83 | 83 | $client->request('GET', '/archive/list'); |
9c0c8820 J |
84 | |
85 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
86 | } | |
87 | ||
88 | public function testStarred() | |
89 | { | |
eb3bd7ef | 90 | $this->logInAs('admin'); |
3b815d2d | 91 | $client = $this->getClient(); |
9c0c8820 | 92 | |
9fb6ac83 | 93 | $client->request('GET', '/starred/list'); |
9c0c8820 J |
94 | |
95 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
96 | } | |
97 | ||
98 | public function testView() | |
99 | { | |
eb3bd7ef | 100 | $this->logInAs('admin'); |
3b815d2d | 101 | $client = $this->getClient(); |
9c0c8820 J |
102 | |
103 | $content = $client->getContainer() | |
104 | ->get('doctrine.orm.entity_manager') | |
105 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 106 | ->findOneByUrl($this->url); |
9c0c8820 | 107 | |
eb3bd7ef | 108 | $client->request('GET', '/view/'.$content->getId()); |
9c0c8820 J |
109 | |
110 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
111 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); | |
93fd4692 | 112 | } |
eb3bd7ef | 113 | |
82d6d9cb JB |
114 | public function testEdit() |
115 | { | |
116 | $this->logInAs('admin'); | |
117 | $client = $this->getClient(); | |
118 | ||
119 | $content = $client->getContainer() | |
120 | ->get('doctrine.orm.entity_manager') | |
121 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 122 | ->findOneByUrl($this->url); |
82d6d9cb JB |
123 | |
124 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
125 | ||
126 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
127 | ||
128 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
129 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
130 | } | |
131 | ||
132 | public function testEditUpdate() | |
133 | { | |
134 | $this->logInAs('admin'); | |
135 | $client = $this->getClient(); | |
136 | ||
137 | $content = $client->getContainer() | |
138 | ->get('doctrine.orm.entity_manager') | |
139 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 140 | ->findOneByUrl($this->url); |
82d6d9cb JB |
141 | |
142 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
143 | ||
144 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
145 | ||
146 | $form = $crawler->filter('button[type=submit]')->form(); | |
147 | ||
148 | $data = array( | |
149 | 'entry[title]' => 'My updated title hehe :)', | |
150 | ); | |
151 | ||
152 | $client->submit($form, $data); | |
153 | ||
154 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
155 | ||
156 | $crawler = $client->followRedirect(); | |
157 | ||
158 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); | |
159 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
160 | } | |
161 | ||
eb3bd7ef J |
162 | public function testToggleArchive() |
163 | { | |
164 | $this->logInAs('admin'); | |
165 | $client = $this->getClient(); | |
166 | ||
167 | $content = $client->getContainer() | |
168 | ->get('doctrine.orm.entity_manager') | |
169 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 170 | ->findOneByUrl($this->url); |
eb3bd7ef J |
171 | |
172 | $client->request('GET', '/archive/'.$content->getId()); | |
173 | ||
174 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
175 | ||
176 | $res = $client->getContainer() | |
177 | ->get('doctrine.orm.entity_manager') | |
178 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 179 | ->find($content->getId()); |
eb3bd7ef J |
180 | |
181 | $this->assertEquals($res->isArchived(), true); | |
182 | } | |
183 | ||
184 | public function testToggleStar() | |
185 | { | |
186 | $this->logInAs('admin'); | |
187 | $client = $this->getClient(); | |
188 | ||
189 | $content = $client->getContainer() | |
190 | ->get('doctrine.orm.entity_manager') | |
191 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 192 | ->findOneByUrl($this->url); |
eb3bd7ef J |
193 | |
194 | $client->request('GET', '/star/'.$content->getId()); | |
195 | ||
196 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
197 | ||
198 | $res = $client->getContainer() | |
199 | ->get('doctrine.orm.entity_manager') | |
200 | ->getRepository('WallabagCoreBundle:Entry') | |
201 | ->findOneById($content->getId()); | |
202 | ||
203 | $this->assertEquals($res->isStarred(), true); | |
204 | } | |
205 | ||
206 | public function testDelete() | |
207 | { | |
208 | $this->logInAs('admin'); | |
209 | $client = $this->getClient(); | |
210 | ||
211 | $content = $client->getContainer() | |
212 | ->get('doctrine.orm.entity_manager') | |
213 | ->getRepository('WallabagCoreBundle:Entry') | |
02d17813 | 214 | ->findOneByUrl($this->url); |
eb3bd7ef J |
215 | |
216 | $client->request('GET', '/delete/'.$content->getId()); | |
217 | ||
218 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
219 | ||
1d147791 | 220 | $client->request('GET', '/delete/'.$content->getId()); |
eb3bd7ef | 221 | |
1d147791 | 222 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 223 | } |
3d2b2d62 J |
224 | |
225 | public function testViewOtherUserEntry() | |
226 | { | |
159986c4 | 227 | $this->logInAs('admin'); |
3d2b2d62 J |
228 | $client = $this->getClient(); |
229 | ||
230 | $content = $client->getContainer() | |
231 | ->get('doctrine.orm.entity_manager') | |
232 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 233 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 234 | |
159986c4 | 235 | $client->request('GET', '/view/'.$content->getId()); |
3d2b2d62 J |
236 | |
237 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
238 | } | |
26864574 | 239 | |
3f357ee2 | 240 | public function testFilterOnReadingTime() |
26864574 NL |
241 | { |
242 | $this->logInAs('admin'); | |
243 | $client = $this->getClient(); | |
244 | ||
245 | $crawler = $client->request('GET', '/unread/list'); | |
246 | ||
247 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
248 | ||
249 | $data = array( | |
250 | 'entry_filter[readingTime][right_number]' => 11, | |
8ce32af6 | 251 | 'entry_filter[readingTime][left_number]' => 11, |
26864574 NL |
252 | ); |
253 | ||
254 | $crawler = $client->submit($form, $data); | |
255 | ||
256 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
257 | } | |
ab2c93c7 | 258 | |
3f357ee2 NL |
259 | public function testFilterOnCreationDate() |
260 | { | |
261 | $this->logInAs('admin'); | |
262 | $client = $this->getClient(); | |
263 | ||
264 | $crawler = $client->request('GET', '/unread/list'); | |
265 | ||
266 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
267 | ||
268 | $data = array( | |
269 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
8ce32af6 | 270 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), |
3f357ee2 NL |
271 | ); |
272 | ||
273 | $crawler = $client->submit($form, $data); | |
274 | ||
e1779760 | 275 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
3f357ee2 | 276 | |
f90af145 JB |
277 | $data = array( |
278 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
279 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
280 | ); | |
281 | ||
282 | $crawler = $client->submit($form, $data); | |
283 | ||
284 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
285 | ||
3f357ee2 NL |
286 | $data = array( |
287 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
8ce32af6 | 288 | 'entry_filter[createdAt][right_date]' => '01/01/1970', |
3f357ee2 NL |
289 | ); |
290 | ||
291 | $crawler = $client->submit($form, $data); | |
292 | ||
293 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
3f357ee2 NL |
294 | } |
295 | ||
ab2c93c7 NL |
296 | public function testPaginationWithFilter() |
297 | { | |
298 | $this->logInAs('admin'); | |
299 | $client = $this->getClient(); | |
ab2c93c7 NL |
300 | $crawler = $client->request('GET', '/config'); |
301 | ||
302 | $form = $crawler->filter('button[id=config_save]')->form(); | |
303 | ||
304 | $data = array( | |
305 | 'config[items_per_page]' => '1', | |
306 | ); | |
307 | ||
308 | $client->submit($form, $data); | |
309 | ||
310 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
311 | ||
312 | $crawler = $client->request('GET', 'unread/list'.$parameters); | |
313 | ||
314 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
315 | |
316 | // reset pagination | |
317 | $crawler = $client->request('GET', '/config'); | |
318 | $form = $crawler->filter('button[id=config_save]')->form(); | |
319 | $data = array( | |
320 | 'config[items_per_page]' => '12', | |
321 | ); | |
322 | $client->submit($form, $data); | |
ab2c93c7 | 323 | } |
443cecd2 NL |
324 | |
325 | public function testFilterOnDomainName() | |
326 | { | |
327 | $this->logInAs('admin'); | |
328 | $client = $this->getClient(); | |
329 | ||
330 | $crawler = $client->request('GET', '/unread/list'); | |
331 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
332 | $data = array( | |
02d17813 | 333 | 'entry_filter[domainName]' => 'domain', |
443cecd2 NL |
334 | ); |
335 | ||
336 | $crawler = $client->submit($form, $data); | |
02d17813 | 337 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
443cecd2 NL |
338 | |
339 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
340 | $data = array( | |
8ce32af6 | 341 | 'entry_filter[domainName]' => 'wallabag', |
443cecd2 NL |
342 | ); |
343 | ||
344 | $crawler = $client->submit($form, $data); | |
345 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
346 | } | |
e1779760 NL |
347 | |
348 | public function testFilterOnStatus() | |
349 | { | |
350 | $this->logInAs('admin'); | |
351 | $client = $this->getClient(); | |
352 | ||
353 | $crawler = $client->request('GET', '/unread/list'); | |
354 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
355 | $form['entry_filter[isArchived]']->tick(); | |
356 | $form['entry_filter[isStarred]']->untick(); | |
357 | ||
358 | $crawler = $client->submit($form); | |
159986c4 | 359 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 NL |
360 | |
361 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
362 | $form['entry_filter[isArchived]']->untick(); | |
363 | $form['entry_filter[isStarred]']->tick(); | |
364 | ||
365 | $crawler = $client->submit($form); | |
02d17813 | 366 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 | 367 | } |
497e0cad NL |
368 | |
369 | public function testPreviewPictureFilter() | |
370 | { | |
371 | $this->logInAs('admin'); | |
372 | $client = $this->getClient(); | |
373 | ||
374 | $crawler = $client->request('GET', '/unread/list'); | |
375 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
376 | $form['entry_filter[previewPicture]']->tick(); | |
377 | ||
378 | $crawler = $client->submit($form); | |
379 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
380 | } | |
d4ebe5c5 JB |
381 | |
382 | public function testFilterOnLanguage() | |
383 | { | |
384 | $this->logInAs('admin'); | |
385 | $client = $this->getClient(); | |
386 | ||
387 | $crawler = $client->request('GET', '/unread/list'); | |
388 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
389 | $data = array( | |
159986c4 | 390 | 'entry_filter[language]' => 'fr', |
d4ebe5c5 JB |
391 | ); |
392 | ||
393 | $crawler = $client->submit($form, $data); | |
02d17813 | 394 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
d4ebe5c5 JB |
395 | |
396 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
397 | $data = array( | |
398 | 'entry_filter[language]' => 'en', | |
399 | ); | |
400 | ||
401 | $crawler = $client->submit($form, $data); | |
402 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
403 | } | |
93fd4692 | 404 | } |