]>
Commit | Line | Data |
---|---|---|
93fd4692 NL |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
93fd4692 | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
2863bf2a | 6 | use Wallabag\CoreBundle\Entity\Entry; |
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 | ||
5c072d2b NL |
22 | public function testQuickstart() |
23 | { | |
24 | $this->logInAs('empty'); | |
25 | $client = $this->getClient(); | |
26 | ||
27 | $client->request('GET', '/unread/list'); | |
4f9cf232 | 28 | $crawler = $client->followRedirect(); |
5c072d2b NL |
29 | |
30 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 31 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
24ad330b | 32 | $this->assertContains('quickstart.intro.title', $body[0]); |
5c072d2b NL |
33 | |
34 | // Test if quickstart is disabled when user has 1 entry | |
35 | $crawler = $client->request('GET', '/new'); | |
36 | ||
37 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
38 | ||
0d42217e | 39 | $form = $crawler->filter('form[name=entry]')->form(); |
5c072d2b | 40 | |
4094ea47 | 41 | $data = [ |
78833672 | 42 | 'entry[url]' => $this->url, |
4094ea47 | 43 | ]; |
5c072d2b NL |
44 | |
45 | $client->submit($form, $data); | |
46 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
47 | $client->followRedirect(); | |
48 | ||
4f9cf232 | 49 | $crawler = $client->request('GET', '/unread/list'); |
4094ea47 | 50 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 51 | $this->assertContains('entry.list.number_on_the_page', $body[0]); |
5c072d2b NL |
52 | } |
53 | ||
9c0c8820 | 54 | public function testGetNew() |
93fd4692 | 55 | { |
eb3bd7ef | 56 | $this->logInAs('admin'); |
3b815d2d | 57 | $client = $this->getClient(); |
93fd4692 | 58 | |
aa6e27cf | 59 | $crawler = $client->request('GET', '/new'); |
93fd4692 NL |
60 | |
61 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9c0c8820 J |
62 | |
63 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
0d42217e | 64 | $this->assertCount(1, $crawler->filter('form[name=entry]')); |
9c0c8820 J |
65 | } |
66 | ||
880a0e1c NL |
67 | public function testPostNewViaBookmarklet() |
68 | { | |
69 | $this->logInAs('admin'); | |
70 | $client = $this->getClient(); | |
71 | ||
72 | $crawler = $client->request('GET', '/'); | |
73 | ||
74 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
75 | ||
76 | // Good URL | |
4094ea47 | 77 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); |
880a0e1c | 78 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
5c072d2b | 79 | $client->followRedirect(); |
880a0e1c NL |
80 | $crawler = $client->request('GET', '/'); |
81 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
82 | ||
83 | $em = $client->getContainer() | |
84 | ->get('doctrine.orm.entity_manager'); | |
85 | $entry = $em | |
86 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 87 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
880a0e1c NL |
88 | $em->remove($entry); |
89 | $em->flush(); | |
90 | } | |
91 | ||
9c0c8820 J |
92 | public function testPostNewEmpty() |
93 | { | |
eb3bd7ef | 94 | $this->logInAs('admin'); |
3b815d2d | 95 | $client = $this->getClient(); |
9c0c8820 J |
96 | |
97 | $crawler = $client->request('GET', '/new'); | |
98 | ||
99 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
100 | ||
0d42217e | 101 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 J |
102 | |
103 | $crawler = $client->submit($form); | |
104 | ||
105 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 106 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); |
9c0c8820 J |
107 | $this->assertEquals('This value should not be blank.', $alert[0]); |
108 | } | |
109 | ||
8a493541 | 110 | /** |
75c48e3a | 111 | * This test will require an internet connection. |
8a493541 | 112 | */ |
9c0c8820 J |
113 | public function testPostNewOk() |
114 | { | |
eb3bd7ef | 115 | $this->logInAs('admin'); |
3b815d2d | 116 | $client = $this->getClient(); |
9c0c8820 J |
117 | |
118 | $crawler = $client->request('GET', '/new'); | |
119 | ||
120 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
121 | ||
0d42217e | 122 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 | 123 | |
4094ea47 | 124 | $data = [ |
02d17813 | 125 | 'entry[url]' => $this->url, |
4094ea47 | 126 | ]; |
9c0c8820 J |
127 | |
128 | $client->submit($form, $data); | |
129 | ||
130 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
131 | ||
a0d6ccc5 JB |
132 | $content = $client->getContainer() |
133 | ->get('doctrine.orm.entity_manager') | |
134 | ->getRepository('WallabagCoreBundle:Entry') | |
135 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
136 | ||
137 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
138 | $this->assertEquals($this->url, $content->getUrl()); | |
139 | $this->assertContains('Google', $content->getTitle()); | |
140 | } | |
9c0c8820 | 141 | |
a0d6ccc5 JB |
142 | public function testPostNewOkUrlExist() |
143 | { | |
144 | $this->logInAs('admin'); | |
145 | $client = $this->getClient(); | |
146 | ||
147 | $crawler = $client->request('GET', '/new'); | |
148 | ||
149 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
150 | ||
0d42217e | 151 | $form = $crawler->filter('form[name=entry]')->form(); |
a0d6ccc5 | 152 | |
4094ea47 | 153 | $data = [ |
a0d6ccc5 | 154 | 'entry[url]' => $this->url, |
4094ea47 | 155 | ]; |
a0d6ccc5 JB |
156 | |
157 | $client->submit($form, $data); | |
158 | ||
159 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
160 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
9c0c8820 J |
161 | } |
162 | ||
19ca0b2f JB |
163 | public function testPostNewOkUrlExistWithAccent() |
164 | { | |
165 | $this->logInAs('admin'); | |
166 | $client = $this->getClient(); | |
167 | ||
168 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | |
169 | ||
170 | $crawler = $client->request('GET', '/new'); | |
171 | ||
172 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
173 | ||
174 | $form = $crawler->filter('form[name=entry]')->form(); | |
175 | ||
176 | $data = [ | |
177 | 'entry[url]' => $url, | |
178 | ]; | |
179 | ||
180 | $client->submit($form, $data); | |
181 | ||
182 | $crawler = $client->request('GET', '/new'); | |
183 | ||
184 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
185 | ||
186 | $form = $crawler->filter('form[name=entry]')->form(); | |
187 | ||
188 | $data = [ | |
189 | 'entry[url]' => $url, | |
190 | ]; | |
a0d6ccc5 JB |
191 | |
192 | $client->submit($form, $data); | |
193 | ||
194 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
195 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
d6d3fb6e JB |
196 | |
197 | $em = $client->getContainer() | |
198 | ->get('doctrine.orm.entity_manager'); | |
199 | $entry = $em | |
200 | ->getRepository('WallabagCoreBundle:Entry') | |
201 | ->findOneByUrl(urldecode($url)); | |
202 | ||
203 | $em->remove($entry); | |
204 | $em->flush(); | |
9c0c8820 J |
205 | } |
206 | ||
958671a7 KG |
207 | /** |
208 | * This test will require an internet connection. | |
209 | */ | |
3be04745 | 210 | public function testPostNewThatWillBeTagged() |
958671a7 KG |
211 | { |
212 | $this->logInAs('admin'); | |
213 | $client = $this->getClient(); | |
214 | ||
215 | $crawler = $client->request('GET', '/new'); | |
216 | ||
217 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
218 | ||
0d42217e | 219 | $form = $crawler->filter('form[name=entry]')->form(); |
958671a7 | 220 | |
4094ea47 | 221 | $data = [ |
958671a7 | 222 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', |
4094ea47 | 223 | ]; |
958671a7 KG |
224 | |
225 | $client->submit($form, $data); | |
226 | ||
227 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
3be04745 | 228 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); |
958671a7 KG |
229 | |
230 | $em = $client->getContainer() | |
231 | ->get('doctrine.orm.entity_manager'); | |
232 | $entry = $em | |
233 | ->getRepository('WallabagCoreBundle:Entry') | |
234 | ->findOneByUrl($url); | |
69edb774 KG |
235 | $tags = $entry->getTags(); |
236 | ||
237 | $this->assertCount(1, $tags); | |
238 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
958671a7 KG |
239 | |
240 | $em->remove($entry); | |
241 | $em->flush(); | |
3be04745 JB |
242 | |
243 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
244 | // related https://github.com/wallabag/wallabag/issues/2121 | |
245 | $crawler = $client->request('GET', '/new'); | |
246 | ||
247 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
248 | ||
249 | $form = $crawler->filter('form[name=entry]')->form(); | |
250 | ||
251 | $data = [ | |
252 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
253 | ]; | |
254 | ||
255 | $client->submit($form, $data); | |
256 | ||
257 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
258 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
259 | ||
260 | $entry = $em | |
261 | ->getRepository('WallabagCoreBundle:Entry') | |
262 | ->findOneByUrl($url); | |
263 | ||
264 | $tags = $entry->getTags(); | |
265 | ||
266 | $this->assertCount(1, $tags); | |
267 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
268 | ||
269 | $em->remove($entry); | |
270 | $em->flush(); | |
958671a7 KG |
271 | } |
272 | ||
9c0c8820 J |
273 | public function testArchive() |
274 | { | |
eb3bd7ef | 275 | $this->logInAs('admin'); |
3b815d2d | 276 | $client = $this->getClient(); |
9c0c8820 | 277 | |
9fb6ac83 | 278 | $client->request('GET', '/archive/list'); |
9c0c8820 J |
279 | |
280 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
281 | } | |
282 | ||
d5d16121 NL |
283 | public function testUntagged() |
284 | { | |
285 | $this->logInAs('admin'); | |
286 | $client = $this->getClient(); | |
287 | ||
288 | $client->request('GET', '/untagged/list'); | |
289 | ||
290 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
291 | } | |
292 | ||
9c0c8820 J |
293 | public function testStarred() |
294 | { | |
eb3bd7ef | 295 | $this->logInAs('admin'); |
3b815d2d | 296 | $client = $this->getClient(); |
9c0c8820 | 297 | |
9fb6ac83 | 298 | $client->request('GET', '/starred/list'); |
9c0c8820 J |
299 | |
300 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
301 | } | |
302 | ||
671a2b88 ML |
303 | public function testRangeException() |
304 | { | |
305 | $this->logInAs('admin'); | |
306 | $client = $this->getClient(); | |
307 | ||
308 | $client->request('GET', '/all/list/900'); | |
309 | ||
1880da74 NL |
310 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
311 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | |
671a2b88 ML |
312 | } |
313 | ||
8a493541 JB |
314 | /** |
315 | * @depends testPostNewOk | |
316 | */ | |
9c0c8820 J |
317 | public function testView() |
318 | { | |
eb3bd7ef | 319 | $this->logInAs('admin'); |
3b815d2d | 320 | $client = $this->getClient(); |
9c0c8820 J |
321 | |
322 | $content = $client->getContainer() | |
323 | ->get('doctrine.orm.entity_manager') | |
324 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 325 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
9c0c8820 | 326 | |
4f9cf232 | 327 | $crawler = $client->request('GET', '/view/'.$content->getId()); |
9c0c8820 J |
328 | |
329 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 330 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 331 | $this->assertContains($content->getTitle(), $body[0]); |
93fd4692 | 332 | } |
eb3bd7ef | 333 | |
831b02aa JB |
334 | /** |
335 | * @depends testPostNewOk | |
336 | * | |
337 | * This test will require an internet connection. | |
338 | */ | |
339 | public function testReload() | |
340 | { | |
341 | $this->logInAs('admin'); | |
342 | $client = $this->getClient(); | |
343 | ||
ac8cf632 JB |
344 | $em = $client->getContainer() |
345 | ->get('doctrine.orm.entity_manager'); | |
346 | ||
347 | $content = $em | |
831b02aa | 348 | ->getRepository('WallabagCoreBundle:Entry') |
78833672 | 349 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
831b02aa JB |
350 | |
351 | // empty content | |
352 | $content->setContent(''); | |
ac8cf632 JB |
353 | $em->persist($content); |
354 | $em->flush(); | |
831b02aa JB |
355 | |
356 | $client->request('GET', '/reload/'.$content->getId()); | |
357 | ||
358 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
359 | ||
ac8cf632 | 360 | $content = $em |
831b02aa | 361 | ->getRepository('WallabagCoreBundle:Entry') |
2297d60f | 362 | ->find($content->getId()); |
831b02aa JB |
363 | |
364 | $this->assertNotEmpty($content->getContent()); | |
365 | } | |
366 | ||
2297d60f JB |
367 | /** |
368 | * @depends testPostNewOk | |
369 | * | |
370 | * This test will require an internet connection. | |
371 | */ | |
372 | public function testReloadWithFetchingFailed() | |
373 | { | |
374 | $this->logInAs('admin'); | |
375 | $client = $this->getClient(); | |
376 | ||
377 | $em = $client->getContainer() | |
378 | ->get('doctrine.orm.entity_manager'); | |
379 | ||
380 | $content = $em | |
381 | ->getRepository('WallabagCoreBundle:Entry') | |
382 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
383 | ||
384 | // put a known failed url | |
385 | $content->setUrl('http://0.0.0.0/failed.html'); | |
386 | $em->persist($content); | |
387 | $em->flush(); | |
388 | ||
389 | $client->request('GET', '/reload/'.$content->getId()); | |
390 | ||
391 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
392 | ||
393 | // force EntityManager to clear previous entity | |
394 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | |
395 | $em->clear(); | |
396 | $newContent = $em | |
397 | ->getRepository('WallabagCoreBundle:Entry') | |
398 | ->find($content->getId()); | |
399 | ||
400 | $newContent->setUrl($this->url); | |
401 | $em->persist($newContent); | |
402 | $em->flush(); | |
403 | ||
404 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | |
405 | } | |
406 | ||
82d6d9cb JB |
407 | public function testEdit() |
408 | { | |
409 | $this->logInAs('admin'); | |
410 | $client = $this->getClient(); | |
411 | ||
412 | $content = $client->getContainer() | |
413 | ->get('doctrine.orm.entity_manager') | |
414 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 415 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
82d6d9cb JB |
416 | |
417 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
418 | ||
419 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
420 | ||
421 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
422 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
423 | } | |
424 | ||
425 | public function testEditUpdate() | |
426 | { | |
427 | $this->logInAs('admin'); | |
428 | $client = $this->getClient(); | |
429 | ||
430 | $content = $client->getContainer() | |
431 | ->get('doctrine.orm.entity_manager') | |
432 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 433 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
82d6d9cb JB |
434 | |
435 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
436 | ||
437 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
438 | ||
439 | $form = $crawler->filter('button[type=submit]')->form(); | |
440 | ||
4094ea47 | 441 | $data = [ |
82d6d9cb | 442 | 'entry[title]' => 'My updated title hehe :)', |
4094ea47 | 443 | ]; |
82d6d9cb JB |
444 | |
445 | $client->submit($form, $data); | |
446 | ||
447 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
448 | ||
449 | $crawler = $client->followRedirect(); | |
450 | ||
4094ea47 | 451 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); |
82d6d9cb JB |
452 | $this->assertContains('My updated title hehe :)', $alert[0]); |
453 | } | |
454 | ||
eb3bd7ef J |
455 | public function testToggleArchive() |
456 | { | |
457 | $this->logInAs('admin'); | |
458 | $client = $this->getClient(); | |
459 | ||
460 | $content = $client->getContainer() | |
461 | ->get('doctrine.orm.entity_manager') | |
462 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 463 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
eb3bd7ef J |
464 | |
465 | $client->request('GET', '/archive/'.$content->getId()); | |
466 | ||
467 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
468 | ||
469 | $res = $client->getContainer() | |
470 | ->get('doctrine.orm.entity_manager') | |
471 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 472 | ->find($content->getId()); |
eb3bd7ef J |
473 | |
474 | $this->assertEquals($res->isArchived(), true); | |
475 | } | |
476 | ||
477 | public function testToggleStar() | |
478 | { | |
479 | $this->logInAs('admin'); | |
480 | $client = $this->getClient(); | |
481 | ||
482 | $content = $client->getContainer() | |
483 | ->get('doctrine.orm.entity_manager') | |
484 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 485 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
eb3bd7ef J |
486 | |
487 | $client->request('GET', '/star/'.$content->getId()); | |
488 | ||
489 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
490 | ||
491 | $res = $client->getContainer() | |
492 | ->get('doctrine.orm.entity_manager') | |
493 | ->getRepository('WallabagCoreBundle:Entry') | |
494 | ->findOneById($content->getId()); | |
495 | ||
496 | $this->assertEquals($res->isStarred(), true); | |
497 | } | |
498 | ||
499 | public function testDelete() | |
500 | { | |
501 | $this->logInAs('admin'); | |
502 | $client = $this->getClient(); | |
503 | ||
504 | $content = $client->getContainer() | |
505 | ->get('doctrine.orm.entity_manager') | |
506 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 507 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
eb3bd7ef J |
508 | |
509 | $client->request('GET', '/delete/'.$content->getId()); | |
510 | ||
511 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
512 | ||
1d147791 | 513 | $client->request('GET', '/delete/'.$content->getId()); |
eb3bd7ef | 514 | |
1d147791 | 515 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 516 | } |
3d2b2d62 | 517 | |
2863bf2a JB |
518 | /** |
519 | * It will create a new entry. | |
520 | * Browse to it. | |
521 | * Then remove it. | |
522 | * | |
523 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
524 | */ | |
525 | public function testViewAndDelete() | |
526 | { | |
527 | $this->logInAs('admin'); | |
528 | $client = $this->getClient(); | |
529 | ||
ac8cf632 JB |
530 | $em = $client->getContainer() |
531 | ->get('doctrine.orm.entity_manager'); | |
532 | ||
2863bf2a | 533 | // add a new content to be removed later |
ac8cf632 | 534 | $user = $em |
2863bf2a JB |
535 | ->getRepository('WallabagUserBundle:User') |
536 | ->findOneByUserName('admin'); | |
537 | ||
538 | $content = new Entry($user); | |
539 | $content->setUrl('http://1.1.1.1/entry'); | |
540 | $content->setReadingTime(12); | |
541 | $content->setDomainName('domain.io'); | |
542 | $content->setMimetype('text/html'); | |
543 | $content->setTitle('test title entry'); | |
544 | $content->setContent('This is my content /o/'); | |
545 | $content->setArchived(true); | |
546 | $content->setLanguage('fr'); | |
547 | ||
ac8cf632 JB |
548 | $em->persist($content); |
549 | $em->flush(); | |
2863bf2a JB |
550 | |
551 | $client->request('GET', '/view/'.$content->getId()); | |
552 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
553 | ||
554 | $client->request('GET', '/delete/'.$content->getId()); | |
555 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
556 | ||
557 | $client->followRedirect(); | |
558 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
559 | } | |
560 | ||
3d2b2d62 J |
561 | public function testViewOtherUserEntry() |
562 | { | |
159986c4 | 563 | $this->logInAs('admin'); |
3d2b2d62 J |
564 | $client = $this->getClient(); |
565 | ||
566 | $content = $client->getContainer() | |
567 | ->get('doctrine.orm.entity_manager') | |
568 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 569 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 570 | |
159986c4 | 571 | $client->request('GET', '/view/'.$content->getId()); |
3d2b2d62 J |
572 | |
573 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
574 | } | |
26864574 | 575 | |
3f357ee2 | 576 | public function testFilterOnReadingTime() |
26864574 NL |
577 | { |
578 | $this->logInAs('admin'); | |
579 | $client = $this->getClient(); | |
580 | ||
581 | $crawler = $client->request('GET', '/unread/list'); | |
582 | ||
583 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
584 | ||
4094ea47 | 585 | $data = [ |
d6a9e139 NL |
586 | 'entry_filter[readingTime][right_number]' => 22, |
587 | 'entry_filter[readingTime][left_number]' => 22, | |
4094ea47 | 588 | ]; |
26864574 NL |
589 | |
590 | $crawler = $client->submit($form, $data); | |
591 | ||
592 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
593 | } | |
ab2c93c7 | 594 | |
95859e54 JB |
595 | public function testFilterOnReadingTimeOnlyUpper() |
596 | { | |
597 | $this->logInAs('admin'); | |
598 | $client = $this->getClient(); | |
599 | ||
600 | $crawler = $client->request('GET', '/unread/list'); | |
601 | ||
602 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
603 | ||
604 | $data = [ | |
605 | 'entry_filter[readingTime][right_number]' => 22, | |
606 | ]; | |
607 | ||
608 | $crawler = $client->submit($form, $data); | |
609 | ||
610 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
611 | } | |
612 | ||
613 | public function testFilterOnReadingTimeOnlyLower() | |
614 | { | |
615 | $this->logInAs('admin'); | |
616 | $client = $this->getClient(); | |
617 | ||
618 | $crawler = $client->request('GET', '/unread/list'); | |
619 | ||
620 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
621 | ||
622 | $data = [ | |
623 | 'entry_filter[readingTime][left_number]' => 22, | |
624 | ]; | |
625 | ||
626 | $crawler = $client->submit($form, $data); | |
627 | ||
628 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
629 | } | |
630 | ||
30334567 DB |
631 | public function testFilterOnUnreadStatus() |
632 | { | |
633 | $this->logInAs('admin'); | |
634 | $client = $this->getClient(); | |
635 | ||
636 | $crawler = $client->request('GET', '/all/list'); | |
637 | ||
638 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
639 | ||
640 | $data = [ | |
641 | 'entry_filter[isUnread]' => true, | |
642 | ]; | |
643 | ||
644 | $crawler = $client->submit($form, $data); | |
645 | ||
646 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
647 | } | |
648 | ||
3f357ee2 NL |
649 | public function testFilterOnCreationDate() |
650 | { | |
651 | $this->logInAs('admin'); | |
652 | $client = $this->getClient(); | |
653 | ||
654 | $crawler = $client->request('GET', '/unread/list'); | |
655 | ||
656 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
657 | ||
4094ea47 | 658 | $data = [ |
3f357ee2 | 659 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
8ce32af6 | 660 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), |
4094ea47 | 661 | ]; |
3f357ee2 NL |
662 | |
663 | $crawler = $client->submit($form, $data); | |
664 | ||
e1779760 | 665 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
3f357ee2 | 666 | |
4094ea47 | 667 | $data = [ |
f90af145 JB |
668 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
669 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
4094ea47 | 670 | ]; |
f90af145 JB |
671 | |
672 | $crawler = $client->submit($form, $data); | |
673 | ||
674 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
675 | ||
4094ea47 | 676 | $data = [ |
3f357ee2 | 677 | 'entry_filter[createdAt][left_date]' => '01/01/1970', |
8ce32af6 | 678 | 'entry_filter[createdAt][right_date]' => '01/01/1970', |
4094ea47 | 679 | ]; |
3f357ee2 NL |
680 | |
681 | $crawler = $client->submit($form, $data); | |
682 | ||
683 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
3f357ee2 NL |
684 | } |
685 | ||
ab2c93c7 NL |
686 | public function testPaginationWithFilter() |
687 | { | |
688 | $this->logInAs('admin'); | |
689 | $client = $this->getClient(); | |
ab2c93c7 NL |
690 | $crawler = $client->request('GET', '/config'); |
691 | ||
692 | $form = $crawler->filter('button[id=config_save]')->form(); | |
693 | ||
4094ea47 | 694 | $data = [ |
ab2c93c7 | 695 | 'config[items_per_page]' => '1', |
4094ea47 | 696 | ]; |
ab2c93c7 NL |
697 | |
698 | $client->submit($form, $data); | |
699 | ||
76cd8dbb | 700 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; |
ab2c93c7 | 701 | |
5c072d2b | 702 | $client->request('GET', 'unread/list'.$parameters); |
ab2c93c7 NL |
703 | |
704 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
705 | |
706 | // reset pagination | |
707 | $crawler = $client->request('GET', '/config'); | |
708 | $form = $crawler->filter('button[id=config_save]')->form(); | |
4094ea47 | 709 | $data = [ |
e1779760 | 710 | 'config[items_per_page]' => '12', |
4094ea47 | 711 | ]; |
e1779760 | 712 | $client->submit($form, $data); |
ab2c93c7 | 713 | } |
443cecd2 NL |
714 | |
715 | public function testFilterOnDomainName() | |
716 | { | |
717 | $this->logInAs('admin'); | |
718 | $client = $this->getClient(); | |
719 | ||
720 | $crawler = $client->request('GET', '/unread/list'); | |
721 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 722 | $data = [ |
02d17813 | 723 | 'entry_filter[domainName]' => 'domain', |
4094ea47 | 724 | ]; |
443cecd2 NL |
725 | |
726 | $crawler = $client->submit($form, $data); | |
02d17813 | 727 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
443cecd2 NL |
728 | |
729 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 730 | $data = [ |
8ce32af6 | 731 | 'entry_filter[domainName]' => 'wallabag', |
4094ea47 | 732 | ]; |
443cecd2 NL |
733 | |
734 | $crawler = $client->submit($form, $data); | |
735 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
736 | } | |
e1779760 NL |
737 | |
738 | public function testFilterOnStatus() | |
739 | { | |
740 | $this->logInAs('admin'); | |
741 | $client = $this->getClient(); | |
742 | ||
743 | $crawler = $client->request('GET', '/unread/list'); | |
744 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
745 | $form['entry_filter[isArchived]']->tick(); | |
746 | $form['entry_filter[isStarred]']->untick(); | |
747 | ||
748 | $crawler = $client->submit($form); | |
159986c4 | 749 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 NL |
750 | |
751 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
752 | $form['entry_filter[isArchived]']->untick(); | |
753 | $form['entry_filter[isStarred]']->tick(); | |
754 | ||
755 | $crawler = $client->submit($form); | |
02d17813 | 756 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 | 757 | } |
497e0cad NL |
758 | |
759 | public function testPreviewPictureFilter() | |
760 | { | |
761 | $this->logInAs('admin'); | |
762 | $client = $this->getClient(); | |
763 | ||
764 | $crawler = $client->request('GET', '/unread/list'); | |
765 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
766 | $form['entry_filter[previewPicture]']->tick(); | |
767 | ||
768 | $crawler = $client->submit($form); | |
769 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
770 | } | |
d4ebe5c5 JB |
771 | |
772 | public function testFilterOnLanguage() | |
773 | { | |
774 | $this->logInAs('admin'); | |
775 | $client = $this->getClient(); | |
776 | ||
777 | $crawler = $client->request('GET', '/unread/list'); | |
778 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 779 | $data = [ |
159986c4 | 780 | 'entry_filter[language]' => 'fr', |
4094ea47 | 781 | ]; |
d4ebe5c5 JB |
782 | |
783 | $crawler = $client->submit($form, $data); | |
02d17813 | 784 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
d4ebe5c5 JB |
785 | |
786 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 787 | $data = [ |
d4ebe5c5 | 788 | 'entry_filter[language]' => 'en', |
4094ea47 | 789 | ]; |
d4ebe5c5 JB |
790 | |
791 | $crawler = $client->submit($form, $data); | |
792 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
793 | } | |
a7e2218e | 794 | |
21d82c3c | 795 | public function testShareEntryPublicly() |
a7e2218e NL |
796 | { |
797 | $this->logInAs('admin'); | |
798 | $client = $this->getClient(); | |
799 | ||
800 | $content = $client->getContainer() | |
801 | ->get('doctrine.orm.entity_manager') | |
802 | ->getRepository('WallabagCoreBundle:Entry') | |
803 | ->findOneByUser($this->getLoggedInUserId()); | |
804 | ||
eddda878 | 805 | // no uuid |
a7e2218e | 806 | $client->request('GET', '/share/'.$content->getUuid()); |
eddda878 JB |
807 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
808 | ||
809 | // generating the uuid | |
810 | $client->request('GET', '/share/'.$content->getId()); | |
811 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
812 | ||
813 | // follow link with uuid | |
814 | $crawler = $client->followRedirect(); | |
815 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
816 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
817 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
818 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
a7e2218e | 819 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); |
21d82c3c NL |
820 | $this->assertContains('og:title', $client->getResponse()->getContent()); |
821 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
822 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
d5c45d52 | 823 | $this->assertContains('og:image', $client->getResponse()->getContent()); |
a7e2218e | 824 | |
eddda878 JB |
825 | // sharing is now disabled |
826 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
827 | $client->request('GET', '/share/'.$content->getUuid()); | |
828 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
829 | ||
a7e2218e NL |
830 | $client->request('GET', '/view/'.$content->getId()); |
831 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
eddda878 JB |
832 | |
833 | // removing the share | |
834 | $client->request('GET', '/share/delete/'.$content->getId()); | |
835 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
836 | ||
837 | // share is now disable | |
838 | $client->request('GET', '/share/'.$content->getUuid()); | |
839 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
a7e2218e | 840 | } |
93fd4692 | 841 | } |