]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |
6 | use Wallabag\CoreBundle\Entity\Config; | |
7 | use Wallabag\CoreBundle\Entity\Entry; | |
8 | ||
9 | class EntryControllerTest extends WallabagCoreTestCase | |
10 | { | |
11 | 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'; | |
12 | ||
13 | public function testLogin() | |
14 | { | |
15 | $client = $this->getClient(); | |
16 | ||
17 | $client->request('GET', '/new'); | |
18 | ||
19 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
20 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
21 | } | |
22 | ||
23 | public function testQuickstart() | |
24 | { | |
25 | $this->logInAs('empty'); | |
26 | $client = $this->getClient(); | |
27 | ||
28 | $client->request('GET', '/unread/list'); | |
29 | $crawler = $client->followRedirect(); | |
30 | ||
31 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
32 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
33 | $this->assertContains('quickstart.intro.title', $body[0]); | |
34 | ||
35 | // Test if quickstart is disabled when user has 1 entry | |
36 | $crawler = $client->request('GET', '/new'); | |
37 | ||
38 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
39 | ||
40 | $form = $crawler->filter('form[name=entry]')->form(); | |
41 | ||
42 | $data = [ | |
43 | 'entry[url]' => $this->url, | |
44 | ]; | |
45 | ||
46 | $client->submit($form, $data); | |
47 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
48 | $client->followRedirect(); | |
49 | ||
50 | $crawler = $client->request('GET', '/unread/list'); | |
51 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
52 | $this->assertContains('entry.list.number_on_the_page', $body[0]); | |
53 | } | |
54 | ||
55 | public function testGetNew() | |
56 | { | |
57 | $this->logInAs('admin'); | |
58 | $client = $this->getClient(); | |
59 | ||
60 | $crawler = $client->request('GET', '/new'); | |
61 | ||
62 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
63 | ||
64 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
65 | $this->assertCount(1, $crawler->filter('form[name=entry]')); | |
66 | } | |
67 | ||
68 | public function testPostNewViaBookmarklet() | |
69 | { | |
70 | $this->logInAs('admin'); | |
71 | $client = $this->getClient(); | |
72 | ||
73 | $crawler = $client->request('GET', '/'); | |
74 | ||
75 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
76 | ||
77 | // Good URL | |
78 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); | |
79 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
80 | $client->followRedirect(); | |
81 | $crawler = $client->request('GET', '/'); | |
82 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
83 | ||
84 | $em = $client->getContainer() | |
85 | ->get('doctrine.orm.entity_manager'); | |
86 | $entry = $em | |
87 | ->getRepository('WallabagCoreBundle:Entry') | |
88 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
89 | $em->remove($entry); | |
90 | $em->flush(); | |
91 | } | |
92 | ||
93 | public function testPostNewEmpty() | |
94 | { | |
95 | $this->logInAs('admin'); | |
96 | $client = $this->getClient(); | |
97 | ||
98 | $crawler = $client->request('GET', '/new'); | |
99 | ||
100 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
101 | ||
102 | $form = $crawler->filter('form[name=entry]')->form(); | |
103 | ||
104 | $crawler = $client->submit($form); | |
105 | ||
106 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
107 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); | |
108 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
109 | } | |
110 | ||
111 | /** | |
112 | * This test will require an internet connection. | |
113 | */ | |
114 | public function testPostNewOk() | |
115 | { | |
116 | $this->logInAs('admin'); | |
117 | $client = $this->getClient(); | |
118 | ||
119 | $crawler = $client->request('GET', '/new'); | |
120 | ||
121 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
122 | ||
123 | $form = $crawler->filter('form[name=entry]')->form(); | |
124 | ||
125 | $data = [ | |
126 | 'entry[url]' => $this->url, | |
127 | ]; | |
128 | ||
129 | $client->submit($form, $data); | |
130 | ||
131 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
132 | ||
133 | $content = $client->getContainer() | |
134 | ->get('doctrine.orm.entity_manager') | |
135 | ->getRepository('WallabagCoreBundle:Entry') | |
136 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
137 | ||
138 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
139 | $this->assertEquals($this->url, $content->getUrl()); | |
140 | $this->assertContains('Google', $content->getTitle()); | |
141 | $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()); | |
142 | } | |
143 | ||
144 | public function testPostNewOkUrlExist() | |
145 | { | |
146 | $this->logInAs('admin'); | |
147 | $client = $this->getClient(); | |
148 | ||
149 | $crawler = $client->request('GET', '/new'); | |
150 | ||
151 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
152 | ||
153 | $form = $crawler->filter('form[name=entry]')->form(); | |
154 | ||
155 | $data = [ | |
156 | 'entry[url]' => $this->url, | |
157 | ]; | |
158 | ||
159 | $client->submit($form, $data); | |
160 | ||
161 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
162 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
163 | } | |
164 | ||
165 | public function testPostNewOkUrlExistWithAccent() | |
166 | { | |
167 | $this->logInAs('admin'); | |
168 | $client = $this->getClient(); | |
169 | ||
170 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | |
171 | ||
172 | $crawler = $client->request('GET', '/new'); | |
173 | ||
174 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
175 | ||
176 | $form = $crawler->filter('form[name=entry]')->form(); | |
177 | ||
178 | $data = [ | |
179 | 'entry[url]' => $url, | |
180 | ]; | |
181 | ||
182 | $client->submit($form, $data); | |
183 | ||
184 | $crawler = $client->request('GET', '/new'); | |
185 | ||
186 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
187 | ||
188 | $form = $crawler->filter('form[name=entry]')->form(); | |
189 | ||
190 | $data = [ | |
191 | 'entry[url]' => $url, | |
192 | ]; | |
193 | ||
194 | $client->submit($form, $data); | |
195 | ||
196 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
197 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
198 | ||
199 | $em = $client->getContainer() | |
200 | ->get('doctrine.orm.entity_manager'); | |
201 | $entry = $em | |
202 | ->getRepository('WallabagCoreBundle:Entry') | |
203 | ->findOneByUrl(urldecode($url)); | |
204 | ||
205 | $em->remove($entry); | |
206 | $em->flush(); | |
207 | } | |
208 | ||
209 | /** | |
210 | * This test will require an internet connection. | |
211 | */ | |
212 | public function testPostNewThatWillBeTagged() | |
213 | { | |
214 | $this->logInAs('admin'); | |
215 | $client = $this->getClient(); | |
216 | ||
217 | $crawler = $client->request('GET', '/new'); | |
218 | ||
219 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
220 | ||
221 | $form = $crawler->filter('form[name=entry]')->form(); | |
222 | ||
223 | $data = [ | |
224 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
225 | ]; | |
226 | ||
227 | $client->submit($form, $data); | |
228 | ||
229 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
230 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
231 | ||
232 | $em = $client->getContainer() | |
233 | ->get('doctrine.orm.entity_manager'); | |
234 | $entry = $em | |
235 | ->getRepository('WallabagCoreBundle:Entry') | |
236 | ->findOneByUrl($url); | |
237 | $tags = $entry->getTags(); | |
238 | ||
239 | $this->assertCount(1, $tags); | |
240 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
241 | ||
242 | $em->remove($entry); | |
243 | $em->flush(); | |
244 | ||
245 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
246 | // related https://github.com/wallabag/wallabag/issues/2121 | |
247 | $crawler = $client->request('GET', '/new'); | |
248 | ||
249 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
250 | ||
251 | $form = $crawler->filter('form[name=entry]')->form(); | |
252 | ||
253 | $data = [ | |
254 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
255 | ]; | |
256 | ||
257 | $client->submit($form, $data); | |
258 | ||
259 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
260 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
261 | ||
262 | $entry = $em | |
263 | ->getRepository('WallabagCoreBundle:Entry') | |
264 | ->findOneByUrl($url); | |
265 | ||
266 | $tags = $entry->getTags(); | |
267 | ||
268 | $this->assertCount(1, $tags); | |
269 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
270 | ||
271 | $em->remove($entry); | |
272 | $em->flush(); | |
273 | } | |
274 | ||
275 | public function testArchive() | |
276 | { | |
277 | $this->logInAs('admin'); | |
278 | $client = $this->getClient(); | |
279 | ||
280 | $client->request('GET', '/archive/list'); | |
281 | ||
282 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
283 | } | |
284 | ||
285 | public function testUntagged() | |
286 | { | |
287 | $this->logInAs('admin'); | |
288 | $client = $this->getClient(); | |
289 | ||
290 | $client->request('GET', '/untagged/list'); | |
291 | ||
292 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
293 | } | |
294 | ||
295 | public function testStarred() | |
296 | { | |
297 | $this->logInAs('admin'); | |
298 | $client = $this->getClient(); | |
299 | ||
300 | $client->request('GET', '/starred/list'); | |
301 | ||
302 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
303 | } | |
304 | ||
305 | public function testRangeException() | |
306 | { | |
307 | $this->logInAs('admin'); | |
308 | $client = $this->getClient(); | |
309 | ||
310 | $client->request('GET', '/all/list/900'); | |
311 | ||
312 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
313 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | |
314 | } | |
315 | ||
316 | /** | |
317 | * @depends testPostNewOk | |
318 | */ | |
319 | public function testView() | |
320 | { | |
321 | $this->logInAs('admin'); | |
322 | $client = $this->getClient(); | |
323 | ||
324 | $content = $client->getContainer() | |
325 | ->get('doctrine.orm.entity_manager') | |
326 | ->getRepository('WallabagCoreBundle:Entry') | |
327 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
328 | ||
329 | $crawler = $client->request('GET', '/view/'.$content->getId()); | |
330 | ||
331 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
332 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
333 | $this->assertContains($content->getTitle(), $body[0]); | |
334 | } | |
335 | ||
336 | /** | |
337 | * @depends testPostNewOk | |
338 | * | |
339 | * This test will require an internet connection. | |
340 | */ | |
341 | public function testReload() | |
342 | { | |
343 | $this->logInAs('admin'); | |
344 | $client = $this->getClient(); | |
345 | ||
346 | $em = $client->getContainer() | |
347 | ->get('doctrine.orm.entity_manager'); | |
348 | ||
349 | $content = $em | |
350 | ->getRepository('WallabagCoreBundle:Entry') | |
351 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
352 | ||
353 | // empty content | |
354 | $content->setContent(''); | |
355 | $em->persist($content); | |
356 | $em->flush(); | |
357 | ||
358 | $client->request('GET', '/reload/'.$content->getId()); | |
359 | ||
360 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
361 | ||
362 | $content = $em | |
363 | ->getRepository('WallabagCoreBundle:Entry') | |
364 | ->find($content->getId()); | |
365 | ||
366 | $this->assertNotEmpty($content->getContent()); | |
367 | } | |
368 | ||
369 | /** | |
370 | * @depends testPostNewOk | |
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 | ||
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') | |
415 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
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') | |
433 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
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 | ||
441 | $data = [ | |
442 | 'entry[title]' => 'My updated title hehe :)', | |
443 | ]; | |
444 | ||
445 | $client->submit($form, $data); | |
446 | ||
447 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
448 | ||
449 | $crawler = $client->followRedirect(); | |
450 | ||
451 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); | |
452 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
453 | } | |
454 | ||
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') | |
463 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
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') | |
472 | ->find($content->getId()); | |
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') | |
485 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
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') | |
507 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
508 | ||
509 | $client->request('GET', '/delete/'.$content->getId()); | |
510 | ||
511 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
512 | ||
513 | $client->request('GET', '/delete/'.$content->getId()); | |
514 | ||
515 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
516 | } | |
517 | ||
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 | ||
530 | $em = $client->getContainer() | |
531 | ->get('doctrine.orm.entity_manager'); | |
532 | ||
533 | // add a new content to be removed later | |
534 | $user = $em | |
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 | ||
548 | $em->persist($content); | |
549 | $em->flush(); | |
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 | ||
561 | public function testViewOtherUserEntry() | |
562 | { | |
563 | $this->logInAs('admin'); | |
564 | $client = $this->getClient(); | |
565 | ||
566 | $content = $client->getContainer() | |
567 | ->get('doctrine.orm.entity_manager') | |
568 | ->getRepository('WallabagCoreBundle:Entry') | |
569 | ->findOneByUsernameAndNotArchived('bob'); | |
570 | ||
571 | $client->request('GET', '/view/'.$content->getId()); | |
572 | ||
573 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
574 | } | |
575 | ||
576 | public function testFilterOnReadingTime() | |
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 | ||
585 | $data = [ | |
586 | 'entry_filter[readingTime][right_number]' => 22, | |
587 | 'entry_filter[readingTime][left_number]' => 22, | |
588 | ]; | |
589 | ||
590 | $crawler = $client->submit($form, $data); | |
591 | ||
592 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
593 | } | |
594 | ||
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 | ||
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 | ||
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 | ||
658 | $data = [ | |
659 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
660 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), | |
661 | ]; | |
662 | ||
663 | $crawler = $client->submit($form, $data); | |
664 | ||
665 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
666 | ||
667 | $data = [ | |
668 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
669 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
670 | ]; | |
671 | ||
672 | $crawler = $client->submit($form, $data); | |
673 | ||
674 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
675 | ||
676 | $data = [ | |
677 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
678 | 'entry_filter[createdAt][right_date]' => '01/01/1970', | |
679 | ]; | |
680 | ||
681 | $crawler = $client->submit($form, $data); | |
682 | ||
683 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
684 | } | |
685 | ||
686 | public function testPaginationWithFilter() | |
687 | { | |
688 | $this->logInAs('admin'); | |
689 | $client = $this->getClient(); | |
690 | $crawler = $client->request('GET', '/config'); | |
691 | ||
692 | $form = $crawler->filter('button[id=config_save]')->form(); | |
693 | ||
694 | $data = [ | |
695 | 'config[items_per_page]' => '1', | |
696 | ]; | |
697 | ||
698 | $client->submit($form, $data); | |
699 | ||
700 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
701 | ||
702 | $client->request('GET', 'unread/list'.$parameters); | |
703 | ||
704 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
705 | ||
706 | // reset pagination | |
707 | $crawler = $client->request('GET', '/config'); | |
708 | $form = $crawler->filter('button[id=config_save]')->form(); | |
709 | $data = [ | |
710 | 'config[items_per_page]' => '12', | |
711 | ]; | |
712 | $client->submit($form, $data); | |
713 | } | |
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(); | |
722 | $data = [ | |
723 | 'entry_filter[domainName]' => 'domain', | |
724 | ]; | |
725 | ||
726 | $crawler = $client->submit($form, $data); | |
727 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
728 | ||
729 | $crawler = $client->request('GET', '/unread/list'); | |
730 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
731 | $data = [ | |
732 | 'entry_filter[domainName]' => 'dOmain', | |
733 | ]; | |
734 | ||
735 | $crawler = $client->submit($form, $data); | |
736 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
737 | ||
738 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
739 | $data = [ | |
740 | 'entry_filter[domainName]' => 'wallabag', | |
741 | ]; | |
742 | ||
743 | $crawler = $client->submit($form, $data); | |
744 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
745 | } | |
746 | ||
747 | public function testFilterOnStatus() | |
748 | { | |
749 | $this->logInAs('admin'); | |
750 | $client = $this->getClient(); | |
751 | ||
752 | $crawler = $client->request('GET', '/unread/list'); | |
753 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
754 | $form['entry_filter[isArchived]']->tick(); | |
755 | $form['entry_filter[isStarred]']->untick(); | |
756 | ||
757 | $crawler = $client->submit($form); | |
758 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
759 | ||
760 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
761 | $form['entry_filter[isArchived]']->untick(); | |
762 | $form['entry_filter[isStarred]']->tick(); | |
763 | ||
764 | $crawler = $client->submit($form); | |
765 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
766 | } | |
767 | ||
768 | public function testPreviewPictureFilter() | |
769 | { | |
770 | $this->logInAs('admin'); | |
771 | $client = $this->getClient(); | |
772 | ||
773 | $crawler = $client->request('GET', '/unread/list'); | |
774 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
775 | $form['entry_filter[previewPicture]']->tick(); | |
776 | ||
777 | $crawler = $client->submit($form); | |
778 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
779 | } | |
780 | ||
781 | public function testFilterOnLanguage() | |
782 | { | |
783 | $this->logInAs('admin'); | |
784 | $client = $this->getClient(); | |
785 | ||
786 | $crawler = $client->request('GET', '/unread/list'); | |
787 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
788 | $data = [ | |
789 | 'entry_filter[language]' => 'fr', | |
790 | ]; | |
791 | ||
792 | $crawler = $client->submit($form, $data); | |
793 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
794 | ||
795 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
796 | $data = [ | |
797 | 'entry_filter[language]' => 'en', | |
798 | ]; | |
799 | ||
800 | $crawler = $client->submit($form, $data); | |
801 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
802 | } | |
803 | ||
804 | public function testShareEntryPublicly() | |
805 | { | |
806 | $this->logInAs('admin'); | |
807 | $client = $this->getClient(); | |
808 | ||
809 | $content = $client->getContainer() | |
810 | ->get('doctrine.orm.entity_manager') | |
811 | ->getRepository('WallabagCoreBundle:Entry') | |
812 | ->findOneByUser($this->getLoggedInUserId()); | |
813 | ||
814 | // no uid | |
815 | $client->request('GET', '/share/'.$content->getUid()); | |
816 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
817 | ||
818 | // generating the uid | |
819 | $client->request('GET', '/share/'.$content->getId()); | |
820 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
821 | ||
822 | // follow link with uid | |
823 | $crawler = $client->followRedirect(); | |
824 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
825 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
826 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
827 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
828 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
829 | $this->assertContains('og:title', $client->getResponse()->getContent()); | |
830 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
831 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
832 | $this->assertContains('og:image', $client->getResponse()->getContent()); | |
833 | ||
834 | // sharing is now disabled | |
835 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
836 | $client->request('GET', '/share/'.$content->getUid()); | |
837 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
838 | ||
839 | $client->request('GET', '/view/'.$content->getId()); | |
840 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
841 | ||
842 | // removing the share | |
843 | $client->request('GET', '/share/delete/'.$content->getId()); | |
844 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
845 | ||
846 | // share is now disable | |
847 | $client->request('GET', '/share/'.$content->getUid()); | |
848 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
849 | } | |
850 | ||
851 | public function testNewEntryWithDownloadImagesEnabled() | |
852 | { | |
853 | $this->logInAs('admin'); | |
854 | $client = $this->getClient(); | |
855 | ||
856 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | |
857 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
858 | ||
859 | $crawler = $client->request('GET', '/new'); | |
860 | ||
861 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
862 | ||
863 | $form = $crawler->filter('form[name=entry]')->form(); | |
864 | ||
865 | $data = [ | |
866 | 'entry[url]' => $url, | |
867 | ]; | |
868 | ||
869 | $client->submit($form, $data); | |
870 | ||
871 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
872 | ||
873 | $em = $client->getContainer() | |
874 | ->get('doctrine.orm.entity_manager'); | |
875 | ||
876 | $entry = $em | |
877 | ->getRepository('WallabagCoreBundle:Entry') | |
878 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
879 | ||
880 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | |
881 | $this->assertEquals($url, $entry->getUrl()); | |
882 | $this->assertContains('Perpignan', $entry->getTitle()); | |
883 | $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); | |
884 | ||
885 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
886 | } | |
887 | ||
888 | /** | |
889 | * @depends testNewEntryWithDownloadImagesEnabled | |
890 | */ | |
891 | public function testRemoveEntryWithDownloadImagesEnabled() | |
892 | { | |
893 | $this->logInAs('admin'); | |
894 | $client = $this->getClient(); | |
895 | ||
896 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | |
897 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
898 | ||
899 | $content = $client->getContainer() | |
900 | ->get('doctrine.orm.entity_manager') | |
901 | ->getRepository('WallabagCoreBundle:Entry') | |
902 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
903 | ||
904 | $client->request('GET', '/delete/'.$content->getId()); | |
905 | ||
906 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
907 | ||
908 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
909 | } | |
910 | ||
911 | public function testRedirectToHomepage() | |
912 | { | |
913 | $this->logInAs('empty'); | |
914 | $client = $this->getClient(); | |
915 | ||
916 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
917 | $user = $em | |
918 | ->getRepository('WallabagUserBundle:User') | |
919 | ->find($this->getLoggedInUserId()); | |
920 | ||
921 | if (!$user) { | |
922 | $this->markTestSkipped('No user found in db.'); | |
923 | } | |
924 | ||
925 | // Redirect to homepage | |
926 | $config = $user->getConfig(); | |
927 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | |
928 | $em->persist($config); | |
929 | $em->flush(); | |
930 | ||
931 | $content = $client->getContainer() | |
932 | ->get('doctrine.orm.entity_manager') | |
933 | ->getRepository('WallabagCoreBundle:Entry') | |
934 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
935 | ||
936 | $client->request('GET', '/view/'.$content->getId()); | |
937 | $client->request('GET', '/archive/'.$content->getId()); | |
938 | ||
939 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
940 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | |
941 | } | |
942 | ||
943 | public function testRedirectToCurrentPage() | |
944 | { | |
945 | $this->logInAs('empty'); | |
946 | $client = $this->getClient(); | |
947 | ||
948 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
949 | $user = $em | |
950 | ->getRepository('WallabagUserBundle:User') | |
951 | ->find($this->getLoggedInUserId()); | |
952 | ||
953 | if (!$user) { | |
954 | $this->markTestSkipped('No user found in db.'); | |
955 | } | |
956 | ||
957 | // Redirect to current page | |
958 | $config = $user->getConfig(); | |
959 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | |
960 | $em->persist($config); | |
961 | $em->flush(); | |
962 | ||
963 | $content = $client->getContainer() | |
964 | ->get('doctrine.orm.entity_manager') | |
965 | ->getRepository('WallabagCoreBundle:Entry') | |
966 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
967 | ||
968 | $client->request('GET', '/view/'.$content->getId()); | |
969 | $client->request('GET', '/archive/'.$content->getId()); | |
970 | ||
971 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
972 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | |
973 | } | |
974 | ||
975 | public function testFilterOnHttpStatus() | |
976 | { | |
977 | $this->logInAs('admin'); | |
978 | $client = $this->getClient(); | |
979 | ||
980 | $crawler = $client->request('GET', '/new'); | |
981 | $form = $crawler->filter('form[name=entry]')->form(); | |
982 | ||
983 | $data = [ | |
984 | 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', | |
985 | ]; | |
986 | ||
987 | $client->submit($form, $data); | |
988 | ||
989 | $crawler = $client->request('GET', '/all/list'); | |
990 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
991 | ||
992 | $data = [ | |
993 | 'entry_filter[httpStatus]' => 404, | |
994 | ]; | |
995 | ||
996 | $crawler = $client->submit($form, $data); | |
997 | ||
998 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
999 | ||
1000 | $crawler = $client->request('GET', '/new'); | |
1001 | $form = $crawler->filter('form[name=entry]')->form(); | |
1002 | ||
1003 | $data = [ | |
1004 | 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', | |
1005 | ]; | |
1006 | ||
1007 | $client->submit($form, $data); | |
1008 | ||
1009 | $crawler = $client->request('GET', '/all/list'); | |
1010 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1011 | ||
1012 | $data = [ | |
1013 | 'entry_filter[httpStatus]' => 200, | |
1014 | ]; | |
1015 | ||
1016 | $crawler = $client->submit($form, $data); | |
1017 | ||
1018 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1019 | ||
1020 | $crawler = $client->request('GET', '/all/list'); | |
1021 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1022 | ||
1023 | $data = [ | |
1024 | 'entry_filter[httpStatus]' => 1024, | |
1025 | ]; | |
1026 | ||
1027 | $crawler = $client->submit($form, $data); | |
1028 | ||
1029 | $this->assertCount(7, $crawler->filter('div[class=entry]')); | |
1030 | } | |
1031 | ||
1032 | public function testSearch() | |
1033 | { | |
1034 | $this->logInAs('admin'); | |
1035 | $client = $this->getClient(); | |
1036 | ||
1037 | // Search on unread list | |
1038 | $crawler = $client->request('GET', '/unread/list'); | |
1039 | ||
1040 | $form = $crawler->filter('form[name=search]')->form(); | |
1041 | $data = [ | |
1042 | 'search_entry[term]' => 'title', | |
1043 | ]; | |
1044 | ||
1045 | $crawler = $client->submit($form, $data); | |
1046 | ||
1047 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
1048 | ||
1049 | // Search on starred list | |
1050 | $crawler = $client->request('GET', '/starred/list'); | |
1051 | ||
1052 | $form = $crawler->filter('form[name=search]')->form(); | |
1053 | $data = [ | |
1054 | 'search_entry[term]' => 'title', | |
1055 | ]; | |
1056 | ||
1057 | $crawler = $client->submit($form, $data); | |
1058 | ||
1059 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1060 | ||
1061 | // Added new article to test on archive list | |
1062 | $crawler = $client->request('GET', '/new'); | |
1063 | $form = $crawler->filter('form[name=entry]')->form(); | |
1064 | $data = [ | |
1065 | 'entry[url]' => $this->url, | |
1066 | ]; | |
1067 | $client->submit($form, $data); | |
1068 | $content = $client->getContainer() | |
1069 | ->get('doctrine.orm.entity_manager') | |
1070 | ->getRepository('WallabagCoreBundle:Entry') | |
1071 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
1072 | $client->request('GET', '/archive/'.$content->getId()); | |
1073 | ||
1074 | $crawler = $client->request('GET', '/archive/list'); | |
1075 | ||
1076 | $form = $crawler->filter('form[name=search]')->form(); | |
1077 | $data = [ | |
1078 | 'search_entry[term]' => 'manège', | |
1079 | ]; | |
1080 | ||
1081 | $crawler = $client->submit($form, $data); | |
1082 | ||
1083 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1084 | $client->request('GET', '/delete/'.$content->getId()); | |
1085 | ||
1086 | // test on list of all articles | |
1087 | $crawler = $client->request('GET', '/all/list'); | |
1088 | ||
1089 | $form = $crawler->filter('form[name=search]')->form(); | |
1090 | $data = [ | |
1091 | 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database | |
1092 | ]; | |
1093 | ||
1094 | $crawler = $client->submit($form, $data); | |
1095 | ||
1096 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
1097 | ||
1098 | // test url search on list of all articles | |
1099 | $crawler = $client->request('GET', '/all/list'); | |
1100 | ||
1101 | $form = $crawler->filter('form[name=search]')->form(); | |
1102 | $data = [ | |
1103 | 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url | |
1104 | ]; | |
1105 | ||
1106 | $crawler = $client->submit($form, $data); | |
1107 | ||
1108 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1109 | ||
1110 | // same as previous test but for case-sensitivity | |
1111 | $crawler = $client->request('GET', '/all/list'); | |
1112 | ||
1113 | $form = $crawler->filter('form[name=search]')->form(); | |
1114 | $data = [ | |
1115 | 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url | |
1116 | ]; | |
1117 | ||
1118 | $crawler = $client->submit($form, $data); | |
1119 | ||
1120 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1121 | } | |
1122 | } |