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