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