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