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