]>
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 | use Wallabag\CoreBundle\Entity\SiteCredential; | |
9 | use Wallabag\CoreBundle\Entity\Tag; | |
10 | use Wallabag\CoreBundle\Helper\ContentProxy; | |
11 | ||
12 | class EntryControllerTest extends WallabagCoreTestCase | |
13 | { | |
14 | const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html'; | |
15 | public $downloadImagesEnabled = false; | |
16 | public $url = 'https://www.lemonde.fr/pixels/article/2019/06/18/ce-qu-il-faut-savoir-sur-le-libra-la-cryptomonnaie-de-facebook_5477887_4408996.html'; | |
17 | ||
18 | /** | |
19 | * @after | |
20 | * | |
21 | * Ensure download_images_enabled is disabled after each script | |
22 | */ | |
23 | public function tearDownImagesEnabled() | |
24 | { | |
25 | if ($this->downloadImagesEnabled) { | |
26 | $client = static::createClient(); | |
27 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
28 | ||
29 | $this->downloadImagesEnabled = false; | |
30 | } | |
31 | } | |
32 | ||
33 | public function testLogin() | |
34 | { | |
35 | $client = $this->getClient(); | |
36 | ||
37 | $client->request('GET', '/new'); | |
38 | ||
39 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
40 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
41 | } | |
42 | ||
43 | public function testQuickstart() | |
44 | { | |
45 | $this->logInAs('empty'); | |
46 | $client = $this->getClient(); | |
47 | ||
48 | $client->request('GET', '/unread/list'); | |
49 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
50 | $crawler = $client->followRedirect(); | |
51 | ||
52 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
53 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
54 | $this->assertContains('quickstart.intro.title', $body[0]); | |
55 | ||
56 | // Test if quickstart is disabled when user has 1 entry | |
57 | $crawler = $client->request('GET', '/new'); | |
58 | ||
59 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
60 | ||
61 | $form = $crawler->filter('form[name=entry]')->form(); | |
62 | ||
63 | $data = [ | |
64 | 'entry[url]' => $this->url, | |
65 | ]; | |
66 | ||
67 | $client->submit($form, $data); | |
68 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
69 | $client->followRedirect(); | |
70 | ||
71 | $crawler = $client->request('GET', '/unread/list'); | |
72 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
73 | $this->assertContains('entry.list.number_on_the_page', $body[0]); | |
74 | } | |
75 | ||
76 | public function testGetNew() | |
77 | { | |
78 | $this->logInAs('admin'); | |
79 | $this->useTheme('baggy'); | |
80 | $client = $this->getClient(); | |
81 | ||
82 | $crawler = $client->request('GET', '/new'); | |
83 | ||
84 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
85 | ||
86 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
87 | $this->assertCount(1, $crawler->filter('form[name=entry]')); | |
88 | } | |
89 | ||
90 | public function testPostNewViaBookmarklet() | |
91 | { | |
92 | $this->logInAs('admin'); | |
93 | $client = $this->getClient(); | |
94 | ||
95 | $crawler = $client->request('GET', '/'); | |
96 | ||
97 | $this->assertCount(4, $crawler->filter('li.entry')); | |
98 | ||
99 | // Good URL | |
100 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); | |
101 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
102 | $client->followRedirect(); | |
103 | $crawler = $client->request('GET', '/'); | |
104 | $this->assertCount(5, $crawler->filter('li.entry')); | |
105 | ||
106 | $em = $client->getContainer() | |
107 | ->get('doctrine.orm.entity_manager'); | |
108 | $entry = $em | |
109 | ->getRepository('WallabagCoreBundle:Entry') | |
110 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
111 | $em->remove($entry); | |
112 | $em->flush(); | |
113 | } | |
114 | ||
115 | public function testPostNewEmpty() | |
116 | { | |
117 | $this->logInAs('admin'); | |
118 | $client = $this->getClient(); | |
119 | ||
120 | $crawler = $client->request('GET', '/new'); | |
121 | ||
122 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
123 | ||
124 | $form = $crawler->filter('form[name=entry]')->form(); | |
125 | ||
126 | $crawler = $client->submit($form); | |
127 | ||
128 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
129 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); | |
130 | $this->assertSame('This value should not be blank.', $alert[0]); | |
131 | } | |
132 | ||
133 | /** | |
134 | * This test will require an internet connection. | |
135 | */ | |
136 | public function testPostNewOk() | |
137 | { | |
138 | $this->logInAs('admin'); | |
139 | $client = $this->getClient(); | |
140 | ||
141 | $client->getContainer()->get('craue_config')->set('store_article_headers', 1); | |
142 | ||
143 | $crawler = $client->request('GET', '/new'); | |
144 | ||
145 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
146 | ||
147 | $form = $crawler->filter('form[name=entry]')->form(); | |
148 | ||
149 | $data = [ | |
150 | 'entry[url]' => $this->url, | |
151 | ]; | |
152 | ||
153 | $client->submit($form, $data); | |
154 | ||
155 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
156 | ||
157 | $content = $client->getContainer() | |
158 | ->get('doctrine.orm.entity_manager') | |
159 | ->getRepository('WallabagCoreBundle:Entry') | |
160 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
161 | ||
162 | $author = $content->getPublishedBy(); | |
163 | ||
164 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
165 | $this->assertSame($this->url, $content->getUrl()); | |
166 | $this->assertContains('la cryptomonnaie de Facebook', $content->getTitle()); | |
167 | $this->assertSame('fr', $content->getLanguage()); | |
168 | $this->assertArrayHasKey('x-frame-options', $content->getHeaders()); | |
169 | $client->getContainer()->get('craue_config')->set('store_article_headers', 0); | |
170 | } | |
171 | ||
172 | public function testPostWithMultipleAuthors() | |
173 | { | |
174 | $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | |
175 | $this->logInAs('admin'); | |
176 | $client = $this->getClient(); | |
177 | ||
178 | $crawler = $client->request('GET', '/new'); | |
179 | ||
180 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
181 | ||
182 | $form = $crawler->filter('form[name=entry]')->form(); | |
183 | ||
184 | $data = [ | |
185 | 'entry[url]' => $url, | |
186 | ]; | |
187 | ||
188 | $client->submit($form, $data); | |
189 | ||
190 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
191 | ||
192 | $content = $client->getContainer() | |
193 | ->get('doctrine.orm.entity_manager') | |
194 | ->getRepository('WallabagCoreBundle:Entry') | |
195 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
196 | ||
197 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
198 | $authors = $content->getPublishedBy(); | |
199 | $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | |
200 | $this->assertSame('fr', $content->getLanguage()); | |
201 | $this->assertSame('Raphaël Balenieri', $authors[0]); | |
202 | $this->assertSame('Frédéric Autran', $authors[1]); | |
203 | } | |
204 | ||
205 | public function testPostNewOkUrlExist() | |
206 | { | |
207 | $this->logInAs('admin'); | |
208 | ||
209 | $entry = new Entry($this->getLoggedInUser()); | |
210 | $entry->setUrl($this->url); | |
211 | $this->getEntityManager()->persist($entry); | |
212 | $this->getEntityManager()->flush(); | |
213 | ||
214 | $client = $this->getClient(); | |
215 | ||
216 | $crawler = $client->request('GET', '/new'); | |
217 | ||
218 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
219 | ||
220 | $form = $crawler->filter('form[name=entry]')->form(); | |
221 | ||
222 | $data = [ | |
223 | 'entry[url]' => $this->url, | |
224 | ]; | |
225 | ||
226 | $client->submit($form, $data); | |
227 | ||
228 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
229 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
230 | } | |
231 | ||
232 | public function testPostNewOkUrlExistWithAccent() | |
233 | { | |
234 | $this->logInAs('admin'); | |
235 | $client = $this->getClient(); | |
236 | ||
237 | $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | |
238 | ||
239 | $crawler = $client->request('GET', '/new'); | |
240 | ||
241 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
242 | ||
243 | $form = $crawler->filter('form[name=entry]')->form(); | |
244 | ||
245 | $data = [ | |
246 | 'entry[url]' => $url, | |
247 | ]; | |
248 | ||
249 | $client->submit($form, $data); | |
250 | ||
251 | $crawler = $client->request('GET', '/new'); | |
252 | ||
253 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
254 | ||
255 | $form = $crawler->filter('form[name=entry]')->form(); | |
256 | ||
257 | $data = [ | |
258 | 'entry[url]' => $url, | |
259 | ]; | |
260 | ||
261 | $client->submit($form, $data); | |
262 | ||
263 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
264 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
265 | } | |
266 | ||
267 | /** | |
268 | * This test will require an internet connection. | |
269 | */ | |
270 | public function testPostNewOkUrlExistWithRedirection() | |
271 | { | |
272 | $this->logInAs('admin'); | |
273 | $client = $this->getClient(); | |
274 | ||
275 | $url = 'https://wllbg.org/test-redirect/c51c'; | |
276 | ||
277 | $crawler = $client->request('GET', '/new'); | |
278 | ||
279 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
280 | ||
281 | $form = $crawler->filter('form[name=entry]')->form(); | |
282 | ||
283 | $data = [ | |
284 | 'entry[url]' => $url, | |
285 | ]; | |
286 | ||
287 | $client->submit($form, $data); | |
288 | ||
289 | $crawler = $client->request('GET', '/new'); | |
290 | ||
291 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
292 | ||
293 | $form = $crawler->filter('form[name=entry]')->form(); | |
294 | ||
295 | $data = [ | |
296 | 'entry[url]' => $url, | |
297 | ]; | |
298 | ||
299 | $client->submit($form, $data); | |
300 | ||
301 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
302 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
303 | } | |
304 | ||
305 | /** | |
306 | * This test will require an internet connection. | |
307 | */ | |
308 | public function testPostNewThatWillBeTagged() | |
309 | { | |
310 | $this->logInAs('admin'); | |
311 | $client = $this->getClient(); | |
312 | ||
313 | $crawler = $client->request('GET', '/new'); | |
314 | ||
315 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
316 | ||
317 | $form = $crawler->filter('form[name=entry]')->form(); | |
318 | ||
319 | $data = [ | |
320 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
321 | ]; | |
322 | ||
323 | $client->submit($form, $data); | |
324 | ||
325 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
326 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
327 | ||
328 | $em = $client->getContainer() | |
329 | ->get('doctrine.orm.entity_manager'); | |
330 | $entry = $em | |
331 | ->getRepository('WallabagCoreBundle:Entry') | |
332 | ->findOneByUrl($url); | |
333 | $tags = $entry->getTags(); | |
334 | ||
335 | $this->assertCount(2, $tags); | |
336 | $this->assertContains('wallabag', $tags); | |
337 | $this->assertSame('en', $entry->getLanguage()); | |
338 | ||
339 | $em->remove($entry); | |
340 | $em->flush(); | |
341 | ||
342 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
343 | // related https://github.com/wallabag/wallabag/issues/2121 | |
344 | $crawler = $client->request('GET', '/new'); | |
345 | ||
346 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
347 | ||
348 | $form = $crawler->filter('form[name=entry]')->form(); | |
349 | ||
350 | $data = [ | |
351 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
352 | ]; | |
353 | ||
354 | $client->submit($form, $data); | |
355 | ||
356 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
357 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
358 | ||
359 | $entry = $em | |
360 | ->getRepository('WallabagCoreBundle:Entry') | |
361 | ->findOneByUrl($url); | |
362 | ||
363 | $tags = $entry->getTags(); | |
364 | ||
365 | $this->assertCount(2, $tags); | |
366 | $this->assertContains('wallabag', $tags); | |
367 | ||
368 | $em->remove($entry); | |
369 | $em->flush(); | |
370 | } | |
371 | ||
372 | public function testArchive() | |
373 | { | |
374 | $this->logInAs('admin'); | |
375 | $client = $this->getClient(); | |
376 | ||
377 | $client->request('GET', '/archive/list'); | |
378 | ||
379 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
380 | } | |
381 | ||
382 | public function testUntagged() | |
383 | { | |
384 | $this->logInAs('admin'); | |
385 | $client = $this->getClient(); | |
386 | ||
387 | $client->request('GET', '/untagged/list'); | |
388 | ||
389 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
390 | } | |
391 | ||
392 | public function testStarred() | |
393 | { | |
394 | $this->logInAs('admin'); | |
395 | $client = $this->getClient(); | |
396 | ||
397 | $client->request('GET', '/starred/list'); | |
398 | ||
399 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
400 | } | |
401 | ||
402 | public function testRangeException() | |
403 | { | |
404 | $this->logInAs('admin'); | |
405 | $client = $this->getClient(); | |
406 | ||
407 | $client->request('GET', '/all/list/900'); | |
408 | ||
409 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
410 | $this->assertSame('/all/list', $client->getResponse()->getTargetUrl()); | |
411 | } | |
412 | ||
413 | public function testView() | |
414 | { | |
415 | $this->logInAs('admin'); | |
416 | $client = $this->getClient(); | |
417 | ||
418 | $entry = new Entry($this->getLoggedInUser()); | |
419 | $entry->setUrl('http://example.com/foo'); | |
420 | $entry->setTitle('title foo'); | |
421 | $entry->setContent('foo bar baz'); | |
422 | $this->getEntityManager()->persist($entry); | |
423 | $this->getEntityManager()->flush(); | |
424 | ||
425 | $crawler = $client->request('GET', '/view/' . $entry->getId()); | |
426 | ||
427 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
428 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
429 | $this->assertContains($entry->getTitle(), $body[0]); | |
430 | } | |
431 | ||
432 | /** | |
433 | * This test will require an internet connection. | |
434 | */ | |
435 | public function testReload() | |
436 | { | |
437 | $this->logInAs('admin'); | |
438 | $client = $this->getClient(); | |
439 | ||
440 | $entry = new Entry($this->getLoggedInUser()); | |
441 | $entry->setUrl($this->url); | |
442 | $entry->setTitle('title foo'); | |
443 | $entry->setContent(''); | |
444 | $this->getEntityManager()->persist($entry); | |
445 | $this->getEntityManager()->flush(); | |
446 | $this->getEntityManager()->clear(); | |
447 | ||
448 | $client->request('GET', '/reload/' . $entry->getId()); | |
449 | ||
450 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
451 | ||
452 | $entry = $this->getEntityManager() | |
453 | ->getRepository('WallabagCoreBundle:Entry') | |
454 | ->find($entry->getId()); | |
455 | ||
456 | $this->assertNotEmpty($entry->getContent()); | |
457 | } | |
458 | ||
459 | public function testReloadWithFetchingFailed() | |
460 | { | |
461 | $this->logInAs('admin'); | |
462 | $client = $this->getClient(); | |
463 | ||
464 | $entry = new Entry($this->getLoggedInUser()); | |
465 | $entry->setUrl('http://0.0.0.0/failed.html'); | |
466 | $this->getEntityManager()->persist($entry); | |
467 | $this->getEntityManager()->flush(); | |
468 | ||
469 | $client->request('GET', '/reload/' . $entry->getId()); | |
470 | ||
471 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
472 | ||
473 | // force EntityManager to clear previous entity | |
474 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | |
475 | $this->getEntityManager()->clear(); | |
476 | $newContent = $this->getEntityManager() | |
477 | ->getRepository('WallabagCoreBundle:Entry') | |
478 | ->find($entry->getId()); | |
479 | ||
480 | $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | |
481 | } | |
482 | ||
483 | public function testEdit() | |
484 | { | |
485 | $this->logInAs('admin'); | |
486 | $client = $this->getClient(); | |
487 | ||
488 | $entry = new Entry($this->getLoggedInUser()); | |
489 | $entry->setUrl($this->url); | |
490 | $this->getEntityManager()->persist($entry); | |
491 | $this->getEntityManager()->flush(); | |
492 | ||
493 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); | |
494 | ||
495 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
496 | ||
497 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
498 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
499 | } | |
500 | ||
501 | public function testEditUpdate() | |
502 | { | |
503 | $this->logInAs('admin'); | |
504 | $client = $this->getClient(); | |
505 | ||
506 | $entry = new Entry($this->getLoggedInUser()); | |
507 | $entry->setUrl($this->url); | |
508 | $this->getEntityManager()->persist($entry); | |
509 | $this->getEntityManager()->flush(); | |
510 | ||
511 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); | |
512 | ||
513 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
514 | ||
515 | $form = $crawler->filter('button[id=entry_save]')->form(); | |
516 | ||
517 | $data = [ | |
518 | 'entry[title]' => 'My updated title hehe :)', | |
519 | 'entry[origin_url]' => 'https://example.io', | |
520 | ]; | |
521 | ||
522 | $client->submit($form, $data); | |
523 | ||
524 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
525 | ||
526 | $crawler = $client->followRedirect(); | |
527 | ||
528 | $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); | |
529 | $this->assertContains('My updated title hehe :)', $title[0]); | |
530 | $this->assertGreaterThan(1, $stats = $crawler->filter('div[class="tools grey-text"] ul[class=stats] li a[class="tool grey-text"]')->extract(['_text'])); | |
531 | $this->assertContains('example.io', trim($stats[1])); | |
532 | } | |
533 | ||
534 | public function testEditRemoveOriginUrl() | |
535 | { | |
536 | $this->logInAs('admin'); | |
537 | $client = $this->getClient(); | |
538 | ||
539 | $entry = new Entry($this->getLoggedInUser()); | |
540 | $entry->setUrl($this->url); | |
541 | $this->getEntityManager()->persist($entry); | |
542 | $this->getEntityManager()->flush(); | |
543 | ||
544 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); | |
545 | ||
546 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
547 | ||
548 | $form = $crawler->filter('button[id=entry_save]')->form(); | |
549 | ||
550 | $data = [ | |
551 | 'entry[title]' => 'My updated title hehe :)', | |
552 | 'entry[origin_url]' => '', | |
553 | ]; | |
554 | ||
555 | $client->submit($form, $data); | |
556 | ||
557 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
558 | ||
559 | $crawler = $client->followRedirect(); | |
560 | ||
561 | $title = $crawler->filter('div[id=article] h1')->extract(['_text']); | |
562 | $this->assertGreaterThan(1, $title); | |
563 | $this->assertContains('My updated title hehe :)', $title[0]); | |
564 | ||
565 | $stats = $crawler->filter('div[class="tools grey-text"] ul[class=stats] li a[class="tool grey-text"]')->extract(['_text']); | |
566 | $this->assertCount(1, $stats); | |
567 | $this->assertNotContains('example.io', trim($stats[0])); | |
568 | } | |
569 | ||
570 | public function testToggleArchive() | |
571 | { | |
572 | $this->logInAs('admin'); | |
573 | $client = $this->getClient(); | |
574 | ||
575 | $entry = new Entry($this->getLoggedInUser()); | |
576 | $entry->setUrl($this->url); | |
577 | $this->getEntityManager()->persist($entry); | |
578 | $this->getEntityManager()->flush(); | |
579 | $this->getEntityManager()->clear(); | |
580 | ||
581 | $client->request('GET', '/archive/' . $entry->getId()); | |
582 | ||
583 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
584 | ||
585 | $res = $client->getContainer() | |
586 | ->get('doctrine.orm.entity_manager') | |
587 | ->getRepository('WallabagCoreBundle:Entry') | |
588 | ->find($entry->getId()); | |
589 | ||
590 | $this->assertSame(1, $res->isArchived()); | |
591 | } | |
592 | ||
593 | public function testToggleStar() | |
594 | { | |
595 | $this->logInAs('admin'); | |
596 | $client = $this->getClient(); | |
597 | ||
598 | $entry = new Entry($this->getLoggedInUser()); | |
599 | $entry->setUrl($this->url); | |
600 | $this->getEntityManager()->persist($entry); | |
601 | $this->getEntityManager()->flush(); | |
602 | $this->getEntityManager()->clear(); | |
603 | ||
604 | $client->request('GET', '/star/' . $entry->getId()); | |
605 | ||
606 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
607 | ||
608 | $res = $client->getContainer() | |
609 | ->get('doctrine.orm.entity_manager') | |
610 | ->getRepository('WallabagCoreBundle:Entry') | |
611 | ->findOneById($entry->getId()); | |
612 | ||
613 | $this->assertSame(1, $res->isStarred()); | |
614 | } | |
615 | ||
616 | public function testDelete() | |
617 | { | |
618 | $this->logInAs('admin'); | |
619 | $client = $this->getClient(); | |
620 | ||
621 | $entry = new Entry($this->getLoggedInUser()); | |
622 | $entry->setUrl($this->url); | |
623 | $this->getEntityManager()->persist($entry); | |
624 | $this->getEntityManager()->flush(); | |
625 | ||
626 | $client->request('GET', '/delete/' . $entry->getId()); | |
627 | ||
628 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
629 | ||
630 | $client->request('GET', '/delete/' . $entry->getId()); | |
631 | ||
632 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
633 | } | |
634 | ||
635 | /** | |
636 | * It will create a new entry. | |
637 | * Browse to it. | |
638 | * Then remove it. | |
639 | * | |
640 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
641 | */ | |
642 | public function testViewAndDelete() | |
643 | { | |
644 | $this->logInAs('admin'); | |
645 | $client = $this->getClient(); | |
646 | ||
647 | $em = $client->getContainer() | |
648 | ->get('doctrine.orm.entity_manager'); | |
649 | ||
650 | // add a new content to be removed later | |
651 | $user = $em | |
652 | ->getRepository('WallabagUserBundle:User') | |
653 | ->findOneByUserName('admin'); | |
654 | ||
655 | $content = new Entry($user); | |
656 | $content->setUrl('http://1.1.1.1/entry'); | |
657 | $content->setReadingTime(12); | |
658 | $content->setDomainName('domain.io'); | |
659 | $content->setMimetype('text/html'); | |
660 | $content->setTitle('test title entry'); | |
661 | $content->setContent('This is my content /o/'); | |
662 | $content->updateArchived(true); | |
663 | $content->setLanguage('fr'); | |
664 | ||
665 | $em->persist($content); | |
666 | $em->flush(); | |
667 | ||
668 | $client->request('GET', '/view/' . $content->getId()); | |
669 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
670 | ||
671 | $client->request('GET', '/delete/' . $content->getId()); | |
672 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
673 | ||
674 | $client->followRedirect(); | |
675 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
676 | } | |
677 | ||
678 | public function testViewOtherUserEntry() | |
679 | { | |
680 | $this->logInAs('admin'); | |
681 | $client = $this->getClient(); | |
682 | ||
683 | $content = $client->getContainer() | |
684 | ->get('doctrine.orm.entity_manager') | |
685 | ->getRepository('WallabagCoreBundle:Entry') | |
686 | ->findOneByUsernameAndNotArchived('bob'); | |
687 | ||
688 | $client->request('GET', '/view/' . $content->getId()); | |
689 | ||
690 | $this->assertSame(403, $client->getResponse()->getStatusCode()); | |
691 | } | |
692 | ||
693 | public function testFilterOnReadingTime() | |
694 | { | |
695 | $this->logInAs('admin'); | |
696 | $client = $this->getClient(); | |
697 | $entry = new Entry($this->getLoggedInUser()); | |
698 | $entry->setUrl($this->url); | |
699 | $entry->setReadingTime(22); | |
700 | $this->getEntityManager()->persist($entry); | |
701 | $this->getEntityManager()->flush(); | |
702 | ||
703 | $crawler = $client->request('GET', '/unread/list'); | |
704 | ||
705 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
706 | ||
707 | $data = [ | |
708 | 'entry_filter[readingTime][right_number]' => 22, | |
709 | 'entry_filter[readingTime][left_number]' => 22, | |
710 | ]; | |
711 | ||
712 | $crawler = $client->submit($form, $data); | |
713 | ||
714 | $this->assertCount(1, $crawler->filter('li.entry')); | |
715 | } | |
716 | ||
717 | public function testFilterOnReadingTimeWithNegativeValue() | |
718 | { | |
719 | $this->logInAs('admin'); | |
720 | $client = $this->getClient(); | |
721 | ||
722 | $crawler = $client->request('GET', '/unread/list'); | |
723 | ||
724 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
725 | ||
726 | $data = [ | |
727 | 'entry_filter[readingTime][right_number]' => -22, | |
728 | 'entry_filter[readingTime][left_number]' => -22, | |
729 | ]; | |
730 | ||
731 | $crawler = $client->submit($form, $data); | |
732 | ||
733 | // forcing negative value results in no entry displayed | |
734 | $this->assertCount(0, $crawler->filter('li.entry')); | |
735 | } | |
736 | ||
737 | public function testFilterOnReadingTimeOnlyUpper() | |
738 | { | |
739 | $this->logInAs('admin'); | |
740 | $client = $this->getClient(); | |
741 | ||
742 | $crawler = $client->request('GET', '/all/list'); | |
743 | $this->assertCount(5, $crawler->filter('li.entry')); | |
744 | ||
745 | $entry = new Entry($this->getLoggedInUser()); | |
746 | $entry->setUrl($this->url); | |
747 | $entry->setReadingTime(23); | |
748 | $this->getEntityManager()->persist($entry); | |
749 | $this->getEntityManager()->flush(); | |
750 | ||
751 | $crawler = $client->request('GET', '/all/list'); | |
752 | $this->assertCount(6, $crawler->filter('li.entry')); | |
753 | ||
754 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
755 | ||
756 | $data = [ | |
757 | 'entry_filter[readingTime][right_number]' => 22, | |
758 | ]; | |
759 | ||
760 | $crawler = $client->submit($form, $data); | |
761 | ||
762 | $this->assertCount(5, $crawler->filter('li.entry')); | |
763 | } | |
764 | ||
765 | public function testFilterOnReadingTimeOnlyLower() | |
766 | { | |
767 | $this->logInAs('admin'); | |
768 | $client = $this->getClient(); | |
769 | ||
770 | $crawler = $client->request('GET', '/unread/list'); | |
771 | ||
772 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
773 | ||
774 | $data = [ | |
775 | 'entry_filter[readingTime][left_number]' => 22, | |
776 | ]; | |
777 | ||
778 | $crawler = $client->submit($form, $data); | |
779 | ||
780 | $this->assertCount(0, $crawler->filter('li.entry')); | |
781 | ||
782 | $entry = new Entry($this->getLoggedInUser()); | |
783 | $entry->setUrl($this->url); | |
784 | $entry->setReadingTime(23); | |
785 | $this->getEntityManager()->persist($entry); | |
786 | $this->getEntityManager()->flush(); | |
787 | ||
788 | $crawler = $client->submit($form, $data); | |
789 | $this->assertCount(1, $crawler->filter('li.entry')); | |
790 | } | |
791 | ||
792 | public function testFilterOnUnreadStatus() | |
793 | { | |
794 | $this->logInAs('admin'); | |
795 | $client = $this->getClient(); | |
796 | ||
797 | $crawler = $client->request('GET', '/all/list'); | |
798 | ||
799 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
800 | ||
801 | $data = [ | |
802 | 'entry_filter[isUnread]' => true, | |
803 | ]; | |
804 | ||
805 | $crawler = $client->submit($form, $data); | |
806 | ||
807 | $this->assertCount(4, $crawler->filter('li.entry')); | |
808 | ||
809 | $entry = new Entry($this->getLoggedInUser()); | |
810 | $entry->setUrl($this->url); | |
811 | $entry->updateArchived(false); | |
812 | $this->getEntityManager()->persist($entry); | |
813 | $this->getEntityManager()->flush(); | |
814 | ||
815 | $crawler = $client->submit($form, $data); | |
816 | ||
817 | $this->assertCount(5, $crawler->filter('li.entry')); | |
818 | } | |
819 | ||
820 | public function testFilterOnCreationDate() | |
821 | { | |
822 | $this->logInAs('admin'); | |
823 | $client = $this->getClient(); | |
824 | ||
825 | $em = $this->getEntityManager(); | |
826 | ||
827 | $today = new \DateTimeImmutable(); | |
828 | $tomorrow = $today->add(new \DateInterval('P1D')); | |
829 | $yesterday = $today->sub(new \DateInterval('P1D')); | |
830 | ||
831 | $entry = new Entry($this->getLoggedInUser()); | |
832 | $entry->setUrl('http://0.0.0.0/testFilterOnCreationDate'); | |
833 | $entry->setCreatedAt($yesterday); | |
834 | $em->persist($entry); | |
835 | $em->flush(); | |
836 | ||
837 | $crawler = $client->request('GET', '/unread/list'); | |
838 | ||
839 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
840 | ||
841 | $data = [ | |
842 | 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'), | |
843 | 'entry_filter[createdAt][right_date]' => $tomorrow->format('Y-m-d'), | |
844 | ]; | |
845 | ||
846 | $crawler = $client->submit($form, $data); | |
847 | ||
848 | $this->assertCount(5, $crawler->filter('li.entry')); | |
849 | ||
850 | $data = [ | |
851 | 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'), | |
852 | 'entry_filter[createdAt][right_date]' => $today->format('Y-m-d'), | |
853 | ]; | |
854 | ||
855 | $crawler = $client->submit($form, $data); | |
856 | ||
857 | $this->assertCount(5, $crawler->filter('li.entry')); | |
858 | ||
859 | $data = [ | |
860 | 'entry_filter[createdAt][left_date]' => '1970-01-01', | |
861 | 'entry_filter[createdAt][right_date]' => '1970-01-01', | |
862 | ]; | |
863 | ||
864 | $crawler = $client->submit($form, $data); | |
865 | ||
866 | $this->assertCount(0, $crawler->filter('li.entry')); | |
867 | } | |
868 | ||
869 | public function testPaginationWithFilter() | |
870 | { | |
871 | $this->logInAs('admin'); | |
872 | $client = $this->getClient(); | |
873 | $crawler = $client->request('GET', '/config'); | |
874 | ||
875 | $form = $crawler->filter('button[id=config_save]')->form(); | |
876 | ||
877 | $data = [ | |
878 | 'config[items_per_page]' => '1', | |
879 | ]; | |
880 | ||
881 | $client->submit($form, $data); | |
882 | ||
883 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
884 | ||
885 | $client->request('GET', 'unread/list' . $parameters); | |
886 | ||
887 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
888 | ||
889 | // reset pagination | |
890 | $crawler = $client->request('GET', '/config'); | |
891 | $form = $crawler->filter('button[id=config_save]')->form(); | |
892 | $data = [ | |
893 | 'config[items_per_page]' => '12', | |
894 | ]; | |
895 | $client->submit($form, $data); | |
896 | } | |
897 | ||
898 | public function testFilterOnDomainName() | |
899 | { | |
900 | $this->logInAs('admin'); | |
901 | $client = $this->getClient(); | |
902 | ||
903 | $crawler = $client->request('GET', '/unread/list'); | |
904 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
905 | $data = [ | |
906 | 'entry_filter[domainName]' => 'domain', | |
907 | ]; | |
908 | ||
909 | $crawler = $client->submit($form, $data); | |
910 | $this->assertCount(5, $crawler->filter('li.entry')); | |
911 | ||
912 | $crawler = $client->request('GET', '/unread/list'); | |
913 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
914 | $data = [ | |
915 | 'entry_filter[domainName]' => 'dOmain', | |
916 | ]; | |
917 | ||
918 | $crawler = $client->submit($form, $data); | |
919 | $this->assertCount(5, $crawler->filter('li.entry')); | |
920 | ||
921 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
922 | $data = [ | |
923 | 'entry_filter[domainName]' => 'wallabag', | |
924 | ]; | |
925 | ||
926 | $crawler = $client->submit($form, $data); | |
927 | $this->assertCount(0, $crawler->filter('li.entry')); | |
928 | } | |
929 | ||
930 | public function testFilterOnStatus() | |
931 | { | |
932 | $this->logInAs('admin'); | |
933 | $client = $this->getClient(); | |
934 | ||
935 | $crawler = $client->request('GET', '/unread/list'); | |
936 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
937 | $form['entry_filter[isArchived]']->tick(); | |
938 | $form['entry_filter[isStarred]']->untick(); | |
939 | ||
940 | $crawler = $client->submit($form); | |
941 | $this->assertCount(1, $crawler->filter('li.entry')); | |
942 | ||
943 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
944 | $form['entry_filter[isArchived]']->untick(); | |
945 | $form['entry_filter[isStarred]']->tick(); | |
946 | ||
947 | $crawler = $client->submit($form); | |
948 | $this->assertCount(1, $crawler->filter('li.entry')); | |
949 | } | |
950 | ||
951 | public function testFilterOnIsPublic() | |
952 | { | |
953 | $this->logInAs('admin'); | |
954 | $client = $this->getClient(); | |
955 | ||
956 | $crawler = $client->request('GET', '/unread/list'); | |
957 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
958 | $form['entry_filter[isPublic]']->tick(); | |
959 | ||
960 | $crawler = $client->submit($form); | |
961 | $this->assertCount(0, $crawler->filter('li.entry')); | |
962 | } | |
963 | ||
964 | public function testPreviewPictureFilter() | |
965 | { | |
966 | $this->logInAs('admin'); | |
967 | $client = $this->getClient(); | |
968 | ||
969 | $crawler = $client->request('GET', '/unread/list'); | |
970 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
971 | $form['entry_filter[previewPicture]']->tick(); | |
972 | ||
973 | $crawler = $client->submit($form); | |
974 | $this->assertCount(1, $crawler->filter('li.entry')); | |
975 | } | |
976 | ||
977 | public function testFilterOnLanguage() | |
978 | { | |
979 | $this->logInAs('admin'); | |
980 | $client = $this->getClient(); | |
981 | ||
982 | $entry = new Entry($this->getLoggedInUser()); | |
983 | $entry->setUrl($this->url); | |
984 | $entry->setLanguage('fr'); | |
985 | $this->getEntityManager()->persist($entry); | |
986 | $this->getEntityManager()->flush(); | |
987 | ||
988 | $crawler = $client->request('GET', '/unread/list'); | |
989 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
990 | $data = [ | |
991 | 'entry_filter[language]' => 'fr', | |
992 | ]; | |
993 | ||
994 | $crawler = $client->submit($form, $data); | |
995 | $this->assertCount(3, $crawler->filter('li.entry')); | |
996 | ||
997 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
998 | $data = [ | |
999 | 'entry_filter[language]' => 'en', | |
1000 | ]; | |
1001 | ||
1002 | $crawler = $client->submit($form, $data); | |
1003 | $this->assertCount(2, $crawler->filter('li.entry')); | |
1004 | } | |
1005 | ||
1006 | public function testShareEntryPublicly() | |
1007 | { | |
1008 | $this->logInAs('admin'); | |
1009 | $client = $this->getClient(); | |
1010 | ||
1011 | // sharing is enabled | |
1012 | $client->getContainer()->get('craue_config')->set('share_public', 1); | |
1013 | ||
1014 | $content = new Entry($this->getLoggedInUser()); | |
1015 | $content->setUrl($this->url); | |
1016 | $this->getEntityManager()->persist($content); | |
1017 | $this->getEntityManager()->flush(); | |
1018 | $this->getEntityManager()->clear(); | |
1019 | ||
1020 | // no uid | |
1021 | $client->request('GET', '/share/' . $content->getUid()); | |
1022 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
1023 | ||
1024 | // generating the uid | |
1025 | $client->request('GET', '/share/' . $content->getId()); | |
1026 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1027 | ||
1028 | $shareUrl = $client->getResponse()->getTargetUrl(); | |
1029 | ||
1030 | // use a new client to have a fresh empty session (instead of a logged one from the previous client) | |
1031 | $client->restart(); | |
1032 | ||
1033 | $client->request('GET', $shareUrl); | |
1034 | ||
1035 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1036 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
1037 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
1038 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
1039 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
1040 | $this->assertContains('og:title', $client->getResponse()->getContent()); | |
1041 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
1042 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
1043 | $this->assertContains('og:image', $client->getResponse()->getContent()); | |
1044 | ||
1045 | // sharing is now disabled | |
1046 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
1047 | $client->request('GET', '/share/' . $content->getUid()); | |
1048 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
1049 | ||
1050 | // removing the share | |
1051 | $client->request('GET', '/share/delete/' . $content->getId()); | |
1052 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1053 | ||
1054 | // share is now disable | |
1055 | $client->request('GET', '/share/' . $content->getUid()); | |
1056 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
1057 | } | |
1058 | ||
1059 | public function testNewEntryWithDownloadImagesEnabled() | |
1060 | { | |
1061 | $this->downloadImagesEnabled = true; | |
1062 | $this->logInAs('admin'); | |
1063 | $client = $this->getClient(); | |
1064 | ||
1065 | $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; | |
1066 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
1067 | ||
1068 | $crawler = $client->request('GET', '/new'); | |
1069 | ||
1070 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1071 | ||
1072 | $form = $crawler->filter('form[name=entry]')->form(); | |
1073 | ||
1074 | $data = [ | |
1075 | 'entry[url]' => $url, | |
1076 | ]; | |
1077 | ||
1078 | $client->submit($form, $data); | |
1079 | ||
1080 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1081 | ||
1082 | $em = $client->getContainer() | |
1083 | ->get('doctrine.orm.entity_manager'); | |
1084 | ||
1085 | $entry = $em | |
1086 | ->getRepository('WallabagCoreBundle:Entry') | |
1087 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1088 | ||
1089 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | |
1090 | $this->assertSame($url, $entry->getUrl()); | |
1091 | $this->assertContains('Judo', $entry->getTitle()); | |
1092 | // instead of checking for the filename (which might change) check that the image is now local | |
1093 | $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent()); | |
1094 | ||
1095 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
1096 | } | |
1097 | ||
1098 | /** | |
1099 | * @depends testNewEntryWithDownloadImagesEnabled | |
1100 | */ | |
1101 | public function testRemoveEntryWithDownloadImagesEnabled() | |
1102 | { | |
1103 | $this->downloadImagesEnabled = true; | |
1104 | $this->logInAs('admin'); | |
1105 | $client = $this->getClient(); | |
1106 | ||
1107 | $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; | |
1108 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
1109 | ||
1110 | $crawler = $client->request('GET', '/new'); | |
1111 | ||
1112 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1113 | ||
1114 | $form = $crawler->filter('form[name=entry]')->form(); | |
1115 | ||
1116 | $data = [ | |
1117 | 'entry[url]' => $url, | |
1118 | ]; | |
1119 | ||
1120 | $client->submit($form, $data); | |
1121 | ||
1122 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1123 | ||
1124 | $content = $client->getContainer() | |
1125 | ->get('doctrine.orm.entity_manager') | |
1126 | ->getRepository('WallabagCoreBundle:Entry') | |
1127 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1128 | ||
1129 | $client->request('GET', '/delete/' . $content->getId()); | |
1130 | ||
1131 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1132 | ||
1133 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
1134 | } | |
1135 | ||
1136 | public function testRedirectToHomepage() | |
1137 | { | |
1138 | $this->logInAs('empty'); | |
1139 | $client = $this->getClient(); | |
1140 | ||
1141 | // Redirect to homepage | |
1142 | $config = $this->getLoggedInUser()->getConfig(); | |
1143 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | |
1144 | $this->getEntityManager()->persist($config); | |
1145 | ||
1146 | $entry = new Entry($this->getLoggedInUser()); | |
1147 | $entry->setUrl($this->url); | |
1148 | $this->getEntityManager()->persist($entry); | |
1149 | ||
1150 | $this->getEntityManager()->flush(); | |
1151 | ||
1152 | $client->request('GET', '/view/' . $entry->getId()); | |
1153 | $client->request('GET', '/archive/' . $entry->getId()); | |
1154 | ||
1155 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1156 | $this->assertSame('/', $client->getResponse()->headers->get('location')); | |
1157 | } | |
1158 | ||
1159 | public function testRedirectToCurrentPage() | |
1160 | { | |
1161 | $this->logInAs('empty'); | |
1162 | $client = $this->getClient(); | |
1163 | ||
1164 | // Redirect to current page | |
1165 | $config = $this->getLoggedInUser()->getConfig(); | |
1166 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | |
1167 | $this->getEntityManager()->persist($config); | |
1168 | ||
1169 | $entry = new Entry($this->getLoggedInUser()); | |
1170 | $entry->setUrl($this->url); | |
1171 | $this->getEntityManager()->persist($entry); | |
1172 | ||
1173 | $this->getEntityManager()->flush(); | |
1174 | ||
1175 | $client->request('GET', '/view/' . $entry->getId()); | |
1176 | $client->request('GET', '/archive/' . $entry->getId()); | |
1177 | ||
1178 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1179 | $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers->get('location')); | |
1180 | } | |
1181 | ||
1182 | public function testFilterOnHttpStatus() | |
1183 | { | |
1184 | $this->logInAs('admin'); | |
1185 | $client = $this->getClient(); | |
1186 | ||
1187 | $entry = new Entry($this->getLoggedInUser()); | |
1188 | $entry->setUrl('https://www.lemonde.fr/incorrect-url/'); | |
1189 | $entry->setHttpStatus(404); | |
1190 | $this->getEntityManager()->persist($entry); | |
1191 | ||
1192 | $this->getEntityManager()->flush(); | |
1193 | ||
1194 | $crawler = $client->request('GET', '/all/list'); | |
1195 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1196 | ||
1197 | $data = [ | |
1198 | 'entry_filter[httpStatus]' => 404, | |
1199 | ]; | |
1200 | ||
1201 | $crawler = $client->submit($form, $data); | |
1202 | ||
1203 | $this->assertCount(1, $crawler->filter('li.entry')); | |
1204 | ||
1205 | $entry = new Entry($this->getLoggedInUser()); | |
1206 | $entry->setUrl($this->url); | |
1207 | $entry->setHttpStatus(200); | |
1208 | $this->getEntityManager()->persist($entry); | |
1209 | ||
1210 | $entry = new Entry($this->getLoggedInUser()); | |
1211 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); | |
1212 | $entry->setHttpStatus(200); | |
1213 | $this->getEntityManager()->persist($entry); | |
1214 | ||
1215 | $this->getEntityManager()->flush(); | |
1216 | ||
1217 | $crawler = $client->request('GET', '/all/list'); | |
1218 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1219 | ||
1220 | $data = [ | |
1221 | 'entry_filter[httpStatus]' => 200, | |
1222 | ]; | |
1223 | ||
1224 | $crawler = $client->submit($form, $data); | |
1225 | ||
1226 | $this->assertCount(2, $crawler->filter('li.entry')); | |
1227 | ||
1228 | $crawler = $client->request('GET', '/all/list'); | |
1229 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1230 | ||
1231 | $data = [ | |
1232 | 'entry_filter[httpStatus]' => 1024, | |
1233 | ]; | |
1234 | ||
1235 | $crawler = $client->submit($form, $data); | |
1236 | ||
1237 | $this->assertCount(8, $crawler->filter('li.entry')); | |
1238 | } | |
1239 | ||
1240 | public function testSearch() | |
1241 | { | |
1242 | $this->logInAs('admin'); | |
1243 | $client = $this->getClient(); | |
1244 | ||
1245 | $entry = new Entry($this->getLoggedInUser()); | |
1246 | $entry->setUrl($this->url); | |
1247 | $entry->setTitle('test'); | |
1248 | $this->getEntityManager()->persist($entry); | |
1249 | $this->getEntityManager()->flush(); | |
1250 | ||
1251 | // Search on unread list | |
1252 | $crawler = $client->request('GET', '/unread/list'); | |
1253 | ||
1254 | $form = $crawler->filter('form[name=search]')->form(); | |
1255 | $data = [ | |
1256 | 'search_entry[term]' => 'title', | |
1257 | ]; | |
1258 | ||
1259 | $crawler = $client->submit($form, $data); | |
1260 | ||
1261 | $this->assertCount(4, $crawler->filter('li.entry')); | |
1262 | ||
1263 | // Search on starred list | |
1264 | $crawler = $client->request('GET', '/starred/list'); | |
1265 | ||
1266 | $entry = new Entry($this->getLoggedInUser()); | |
1267 | $entry->setUrl('http://localhost/foo/bar'); | |
1268 | $entry->setTitle('testeur'); | |
1269 | $entry->setStarred(true); | |
1270 | $this->getEntityManager()->persist($entry); | |
1271 | $this->getEntityManager()->flush(); | |
1272 | ||
1273 | $form = $crawler->filter('form[name=search]')->form(); | |
1274 | $data = [ | |
1275 | 'search_entry[term]' => 'testeur', | |
1276 | ]; | |
1277 | ||
1278 | $crawler = $client->submit($form, $data); | |
1279 | ||
1280 | $this->assertCount(1, $crawler->filter('li.entry')); | |
1281 | ||
1282 | $crawler = $client->request('GET', '/archive/list'); | |
1283 | ||
1284 | // Added new article to test on archive list | |
1285 | $entry = new Entry($this->getLoggedInUser()); | |
1286 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | |
1287 | $entry->setTitle('Le manège'); | |
1288 | $entry->updateArchived(true); | |
1289 | $this->getEntityManager()->persist($entry); | |
1290 | $this->getEntityManager()->flush(); | |
1291 | ||
1292 | $form = $crawler->filter('form[name=search]')->form(); | |
1293 | $data = [ | |
1294 | 'search_entry[term]' => 'manège', | |
1295 | ]; | |
1296 | ||
1297 | $crawler = $client->submit($form, $data); | |
1298 | ||
1299 | $this->assertCount(1, $crawler->filter('li.entry')); | |
1300 | $client->request('GET', '/delete/' . $entry->getId()); | |
1301 | ||
1302 | // test on list of all articles | |
1303 | $crawler = $client->request('GET', '/all/list'); | |
1304 | ||
1305 | $form = $crawler->filter('form[name=search]')->form(); | |
1306 | $data = [ | |
1307 | 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database | |
1308 | ]; | |
1309 | ||
1310 | $crawler = $client->submit($form, $data); | |
1311 | ||
1312 | $this->assertCount(0, $crawler->filter('li.entry')); | |
1313 | ||
1314 | // test url search on list of all articles | |
1315 | $entry = new Entry($this->getLoggedInUser()); | |
1316 | $entry->setUrl('http://domain/qux'); | |
1317 | $entry->setTitle('Le manège'); | |
1318 | $entry->updateArchived(true); | |
1319 | $this->getEntityManager()->persist($entry); | |
1320 | $this->getEntityManager()->flush(); | |
1321 | ||
1322 | $crawler = $client->request('GET', '/all/list'); | |
1323 | ||
1324 | $form = $crawler->filter('form[name=search]')->form(); | |
1325 | $data = [ | |
1326 | 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url | |
1327 | ]; | |
1328 | ||
1329 | $crawler = $client->submit($form, $data); | |
1330 | ||
1331 | $this->assertCount(1, $crawler->filter('li.entry')); | |
1332 | ||
1333 | // same as previous test but for case-sensitivity | |
1334 | $crawler = $client->request('GET', '/all/list'); | |
1335 | ||
1336 | $form = $crawler->filter('form[name=search]')->form(); | |
1337 | $data = [ | |
1338 | 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url | |
1339 | ]; | |
1340 | ||
1341 | $crawler = $client->submit($form, $data); | |
1342 | ||
1343 | $this->assertCount(1, $crawler->filter('li.entry')); | |
1344 | } | |
1345 | ||
1346 | public function dataForLanguage() | |
1347 | { | |
1348 | return [ | |
1349 | 'ru' => [ | |
1350 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | |
1351 | 'ru', | |
1352 | ], | |
1353 | 'fr' => [ | |
1354 | 'https://fr.wikipedia.org/wiki/Wallabag', | |
1355 | 'fr', | |
1356 | ], | |
1357 | 'de' => [ | |
1358 | 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', | |
1359 | 'de', | |
1360 | ], | |
1361 | 'it' => [ | |
1362 | 'https://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', | |
1363 | 'it', | |
1364 | ], | |
1365 | 'zh_CN' => [ | |
1366 | 'http://www.hao123.com/shequ?__noscript__-=1', | |
1367 | 'zh_CN', | |
1368 | ], | |
1369 | 'pt_BR' => [ | |
1370 | 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', | |
1371 | 'pt_BR', | |
1372 | ], | |
1373 | 'fucked_list_of_languages' => [ | |
1374 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', | |
1375 | null, | |
1376 | ], | |
1377 | 'es-ES' => [ | |
1378 | 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/', | |
1379 | 'es_ES', | |
1380 | ], | |
1381 | ]; | |
1382 | } | |
1383 | ||
1384 | /** | |
1385 | * @dataProvider dataForLanguage | |
1386 | */ | |
1387 | public function testLanguageValidation($url, $expectedLanguage) | |
1388 | { | |
1389 | $this->logInAs('admin'); | |
1390 | $client = $this->getClient(); | |
1391 | ||
1392 | $crawler = $client->request('GET', '/new'); | |
1393 | ||
1394 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1395 | ||
1396 | $form = $crawler->filter('form[name=entry]')->form(); | |
1397 | ||
1398 | $data = [ | |
1399 | 'entry[url]' => $url, | |
1400 | ]; | |
1401 | ||
1402 | $client->submit($form, $data); | |
1403 | ||
1404 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1405 | ||
1406 | $content = $client->getContainer() | |
1407 | ->get('doctrine.orm.entity_manager') | |
1408 | ->getRepository('WallabagCoreBundle:Entry') | |
1409 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1410 | ||
1411 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
1412 | $this->assertSame($url, $content->getUrl()); | |
1413 | $this->assertSame($expectedLanguage, $content->getLanguage()); | |
1414 | } | |
1415 | ||
1416 | /** | |
1417 | * This test will require an internet connection. | |
1418 | */ | |
1419 | public function testRestrictedArticle() | |
1420 | { | |
1421 | $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475'; | |
1422 | $this->logInAs('admin'); | |
1423 | $client = $this->getClient(); | |
1424 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1425 | ||
1426 | // enable restricted access | |
1427 | $client->getContainer()->get('craue_config')->set('restricted_access', 1); | |
1428 | ||
1429 | // create a new site_credential | |
1430 | $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
1431 | $credential = new SiteCredential($user); | |
1432 | $credential->setHost('monde-diplomatique.fr'); | |
1433 | $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo')); | |
1434 | $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); | |
1435 | ||
1436 | $em->persist($credential); | |
1437 | $em->flush(); | |
1438 | ||
1439 | $crawler = $client->request('GET', '/new'); | |
1440 | ||
1441 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1442 | ||
1443 | $form = $crawler->filter('form[name=entry]')->form(); | |
1444 | ||
1445 | $data = [ | |
1446 | 'entry[url]' => $url, | |
1447 | ]; | |
1448 | ||
1449 | $client->submit($form, $data); | |
1450 | ||
1451 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1452 | ||
1453 | $crawler = $client->followRedirect(); | |
1454 | ||
1455 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1456 | $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); | |
1457 | ||
1458 | $content = $em | |
1459 | ->getRepository('WallabagCoreBundle:Entry') | |
1460 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1461 | ||
1462 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
1463 | $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle()); | |
1464 | ||
1465 | $client->getContainer()->get('craue_config')->set('restricted_access', 0); | |
1466 | } | |
1467 | ||
1468 | public function testPostEntryWhenFetchFails() | |
1469 | { | |
1470 | $url = 'http://example.com/papers/email_tracking.pdf'; | |
1471 | $this->logInAs('admin'); | |
1472 | $client = $this->getClient(); | |
1473 | ||
1474 | $container = $client->getContainer(); | |
1475 | $contentProxy = $this->getMockBuilder(ContentProxy::class) | |
1476 | ->disableOriginalConstructor() | |
1477 | ->setMethods(['updateEntry']) | |
1478 | ->getMock(); | |
1479 | $contentProxy->expects($this->any()) | |
1480 | ->method('updateEntry') | |
1481 | ->willThrowException(new \Exception('Test Fetch content fails')); | |
1482 | ||
1483 | $crawler = $client->request('GET', '/new'); | |
1484 | ||
1485 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1486 | ||
1487 | $form = $crawler->filter('form[name=entry]')->form(); | |
1488 | ||
1489 | $data = [ | |
1490 | 'entry[url]' => $url, | |
1491 | ]; | |
1492 | ||
1493 | /** | |
1494 | * We generate a new client to be able to use Mock ContentProxy | |
1495 | * Also we reinject the cookie from the previous client to keep the | |
1496 | * session. | |
1497 | */ | |
1498 | $cookie = $client->getCookieJar()->all(); | |
1499 | $client = $this->getNewClient(); | |
1500 | $client->getCookieJar()->set($cookie[0]); | |
1501 | $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy); | |
1502 | $client->submit($form, $data); | |
1503 | ||
1504 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1505 | ||
1506 | $content = $client->getContainer() | |
1507 | ->get('doctrine.orm.entity_manager') | |
1508 | ->getRepository('WallabagCoreBundle:Entry') | |
1509 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
1510 | ||
1511 | $authors = $content->getPublishedBy(); | |
1512 | $this->assertSame('email_tracking.pdf', $content->getTitle()); | |
1513 | $this->assertSame('example.com', $content->getDomainName()); | |
1514 | } | |
1515 | ||
1516 | public function testEntryDeleteTagLink() | |
1517 | { | |
1518 | $this->logInAs('admin'); | |
1519 | $client = $this->getClient(); | |
1520 | ||
1521 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1522 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | |
1523 | $tag = $entry->getTags()[0]; | |
1524 | ||
1525 | $crawler = $client->request('GET', '/view/' . $entry->getId()); | |
1526 | ||
1527 | // As long as the deletion link of a tag is following | |
1528 | // a link to the tag view, we take the second one to retrieve | |
1529 | // the deletion link of the first tag | |
1530 | $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1]; | |
1531 | ||
1532 | $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); | |
1533 | } | |
1534 | ||
1535 | public function testRandom() | |
1536 | { | |
1537 | $this->logInAs('admin'); | |
1538 | $client = $this->getClient(); | |
1539 | ||
1540 | $client->request('GET', '/unread/random'); | |
1541 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1542 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random'); | |
1543 | ||
1544 | $client->request('GET', '/starred/random'); | |
1545 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1546 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random'); | |
1547 | ||
1548 | $client->request('GET', '/archive/random'); | |
1549 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1550 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random'); | |
1551 | ||
1552 | $client->request('GET', '/untagged/random'); | |
1553 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1554 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random'); | |
1555 | ||
1556 | $client->request('GET', '/all/random'); | |
1557 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1558 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random'); | |
1559 | } | |
1560 | ||
1561 | public function testMass() | |
1562 | { | |
1563 | $this->logInAs('admin'); | |
1564 | $client = $this->getClient(); | |
1565 | ||
1566 | $entry1 = new Entry($this->getLoggedInUser()); | |
1567 | $entry1->setUrl($this->url); | |
1568 | $this->getEntityManager()->persist($entry1); | |
1569 | ||
1570 | $entry2 = new Entry($this->getLoggedInUser()); | |
1571 | $entry2->setUrl($this->url); | |
1572 | $this->getEntityManager()->persist($entry2); | |
1573 | ||
1574 | $this->getEntityManager()->flush(); | |
1575 | $this->getEntityManager()->clear(); | |
1576 | ||
1577 | $entries = []; | |
1578 | $entries[] = $entry1->getId(); | |
1579 | $entries[] = $entry2->getId(); | |
1580 | ||
1581 | // Mass actions : archive | |
1582 | $client->request('POST', '/mass', [ | |
1583 | 'toggle-archive' => '', | |
1584 | 'entry-checkbox' => $entries, | |
1585 | ]); | |
1586 | ||
1587 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1588 | ||
1589 | $res = $client->getContainer() | |
1590 | ->get('doctrine.orm.entity_manager') | |
1591 | ->getRepository('WallabagCoreBundle:Entry') | |
1592 | ->find($entry1->getId()); | |
1593 | ||
1594 | $this->assertSame(1, $res->isArchived()); | |
1595 | ||
1596 | $res = $client->getContainer() | |
1597 | ->get('doctrine.orm.entity_manager') | |
1598 | ->getRepository('WallabagCoreBundle:Entry') | |
1599 | ->find($entry2->getId()); | |
1600 | ||
1601 | $this->assertSame(1, $res->isArchived()); | |
1602 | ||
1603 | // Mass actions : star | |
1604 | $client->request('POST', '/mass', [ | |
1605 | 'toggle-star' => '', | |
1606 | 'entry-checkbox' => $entries, | |
1607 | ]); | |
1608 | ||
1609 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1610 | ||
1611 | $res = $client->getContainer() | |
1612 | ->get('doctrine.orm.entity_manager') | |
1613 | ->getRepository('WallabagCoreBundle:Entry') | |
1614 | ->find($entry1->getId()); | |
1615 | ||
1616 | $this->assertSame(1, $res->isStarred()); | |
1617 | ||
1618 | $res = $client->getContainer() | |
1619 | ->get('doctrine.orm.entity_manager') | |
1620 | ->getRepository('WallabagCoreBundle:Entry') | |
1621 | ->find($entry2->getId()); | |
1622 | ||
1623 | $this->assertSame(1, $res->isStarred()); | |
1624 | ||
1625 | // Mass actions : delete | |
1626 | $client->request('POST', '/mass', [ | |
1627 | 'delete' => '', | |
1628 | 'entry-checkbox' => $entries, | |
1629 | ]); | |
1630 | ||
1631 | $client->request('GET', '/delete/' . $entry1->getId()); | |
1632 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
1633 | ||
1634 | $client->request('GET', '/delete/' . $entry2->getId()); | |
1635 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | |
1636 | } | |
1637 | } |