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