]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |
6 | use Wallabag\CoreBundle\Entity\Entry; | |
7 | ||
8 | class EntryControllerTest extends WallabagCoreTestCase | |
9 | { | |
10 | 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'; | |
11 | ||
12 | public function testLogin() | |
13 | { | |
14 | $client = $this->getClient(); | |
15 | ||
16 | $client->request('GET', '/new'); | |
17 | ||
18 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
19 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
20 | } | |
21 | ||
22 | public function testQuickstart() | |
23 | { | |
24 | $this->logInAs('empty'); | |
25 | $client = $this->getClient(); | |
26 | ||
27 | $client->request('GET', '/unread/list'); | |
28 | $crawler = $client->followRedirect(); | |
29 | ||
30 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
31 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
32 | $this->assertContains('quickstart.intro.title', $body[0]); | |
33 | ||
34 | // Test if quickstart is disabled when user has 1 entry | |
35 | $crawler = $client->request('GET', '/new'); | |
36 | ||
37 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
38 | ||
39 | $form = $crawler->filter('form[name=entry]')->form(); | |
40 | ||
41 | $data = [ | |
42 | 'entry[url]' => $this->url, | |
43 | ]; | |
44 | ||
45 | $client->submit($form, $data); | |
46 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
47 | $client->followRedirect(); | |
48 | ||
49 | $crawler = $client->request('GET', '/unread/list'); | |
50 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
51 | $this->assertContains('entry.list.number_on_the_page', $body[0]); | |
52 | } | |
53 | ||
54 | public function testGetNew() | |
55 | { | |
56 | $this->logInAs('admin'); | |
57 | $client = $this->getClient(); | |
58 | ||
59 | $crawler = $client->request('GET', '/new'); | |
60 | ||
61 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
62 | ||
63 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
64 | $this->assertCount(1, $crawler->filter('form[name=entry]')); | |
65 | } | |
66 | ||
67 | public function testPostNewViaBookmarklet() | |
68 | { | |
69 | $this->logInAs('admin'); | |
70 | $client = $this->getClient(); | |
71 | ||
72 | $crawler = $client->request('GET', '/'); | |
73 | ||
74 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
75 | ||
76 | // Good URL | |
77 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); | |
78 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
79 | $client->followRedirect(); | |
80 | $crawler = $client->request('GET', '/'); | |
81 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
82 | ||
83 | $em = $client->getContainer() | |
84 | ->get('doctrine.orm.entity_manager'); | |
85 | $entry = $em | |
86 | ->getRepository('WallabagCoreBundle:Entry') | |
87 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
88 | $em->remove($entry); | |
89 | $em->flush(); | |
90 | } | |
91 | ||
92 | public function testPostNewEmpty() | |
93 | { | |
94 | $this->logInAs('admin'); | |
95 | $client = $this->getClient(); | |
96 | ||
97 | $crawler = $client->request('GET', '/new'); | |
98 | ||
99 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
100 | ||
101 | $form = $crawler->filter('form[name=entry]')->form(); | |
102 | ||
103 | $crawler = $client->submit($form); | |
104 | ||
105 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
106 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); | |
107 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
108 | } | |
109 | ||
110 | /** | |
111 | * This test will require an internet connection. | |
112 | */ | |
113 | public function testPostNewOk() | |
114 | { | |
115 | $this->logInAs('admin'); | |
116 | $client = $this->getClient(); | |
117 | ||
118 | $crawler = $client->request('GET', '/new'); | |
119 | ||
120 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
121 | ||
122 | $form = $crawler->filter('form[name=entry]')->form(); | |
123 | ||
124 | $data = [ | |
125 | 'entry[url]' => $this->url, | |
126 | ]; | |
127 | ||
128 | $client->submit($form, $data); | |
129 | ||
130 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
131 | ||
132 | $content = $client->getContainer() | |
133 | ->get('doctrine.orm.entity_manager') | |
134 | ->getRepository('WallabagCoreBundle:Entry') | |
135 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
136 | ||
137 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
138 | $this->assertEquals($this->url, $content->getUrl()); | |
139 | $this->assertContains('Google', $content->getTitle()); | |
140 | } | |
141 | ||
142 | public function testPostNewOkUrlExist() | |
143 | { | |
144 | $this->logInAs('admin'); | |
145 | $client = $this->getClient(); | |
146 | ||
147 | $crawler = $client->request('GET', '/new'); | |
148 | ||
149 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
150 | ||
151 | $form = $crawler->filter('form[name=entry]')->form(); | |
152 | ||
153 | $data = [ | |
154 | 'entry[url]' => $this->url, | |
155 | ]; | |
156 | ||
157 | $client->submit($form, $data); | |
158 | ||
159 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
160 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
161 | } | |
162 | ||
163 | public function testPostNewOkUrlExistWithAccent() | |
164 | { | |
165 | $this->logInAs('admin'); | |
166 | $client = $this->getClient(); | |
167 | ||
168 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | |
169 | ||
170 | $crawler = $client->request('GET', '/new'); | |
171 | ||
172 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
173 | ||
174 | $form = $crawler->filter('form[name=entry]')->form(); | |
175 | ||
176 | $data = [ | |
177 | 'entry[url]' => $url, | |
178 | ]; | |
179 | ||
180 | $client->submit($form, $data); | |
181 | ||
182 | $crawler = $client->request('GET', '/new'); | |
183 | ||
184 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
185 | ||
186 | $form = $crawler->filter('form[name=entry]')->form(); | |
187 | ||
188 | $data = [ | |
189 | 'entry[url]' => $url, | |
190 | ]; | |
191 | ||
192 | $client->submit($form, $data); | |
193 | ||
194 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
195 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
196 | ||
197 | $em = $client->getContainer() | |
198 | ->get('doctrine.orm.entity_manager'); | |
199 | $entry = $em | |
200 | ->getRepository('WallabagCoreBundle:Entry') | |
201 | ->findOneByUrl(urldecode($url)); | |
202 | ||
203 | $em->remove($entry); | |
204 | $em->flush(); | |
205 | } | |
206 | ||
207 | /** | |
208 | * This test will require an internet connection. | |
209 | */ | |
210 | public function testPostNewThatWillBeTagged() | |
211 | { | |
212 | $this->logInAs('admin'); | |
213 | $client = $this->getClient(); | |
214 | ||
215 | $crawler = $client->request('GET', '/new'); | |
216 | ||
217 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
218 | ||
219 | $form = $crawler->filter('form[name=entry]')->form(); | |
220 | ||
221 | $data = [ | |
222 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
223 | ]; | |
224 | ||
225 | $client->submit($form, $data); | |
226 | ||
227 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
228 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
229 | ||
230 | $em = $client->getContainer() | |
231 | ->get('doctrine.orm.entity_manager'); | |
232 | $entry = $em | |
233 | ->getRepository('WallabagCoreBundle:Entry') | |
234 | ->findOneByUrl($url); | |
235 | $tags = $entry->getTags(); | |
236 | ||
237 | $this->assertCount(1, $tags); | |
238 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
239 | ||
240 | $em->remove($entry); | |
241 | $em->flush(); | |
242 | ||
243 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
244 | // related https://github.com/wallabag/wallabag/issues/2121 | |
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 = 'https://github.com/wallabag/wallabag/tree/master', | |
253 | ]; | |
254 | ||
255 | $client->submit($form, $data); | |
256 | ||
257 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
258 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
259 | ||
260 | $entry = $em | |
261 | ->getRepository('WallabagCoreBundle:Entry') | |
262 | ->findOneByUrl($url); | |
263 | ||
264 | $tags = $entry->getTags(); | |
265 | ||
266 | $this->assertCount(1, $tags); | |
267 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
268 | ||
269 | $em->remove($entry); | |
270 | $em->flush(); | |
271 | } | |
272 | ||
273 | public function testArchive() | |
274 | { | |
275 | $this->logInAs('admin'); | |
276 | $client = $this->getClient(); | |
277 | ||
278 | $client->request('GET', '/archive/list'); | |
279 | ||
280 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
281 | } | |
282 | ||
283 | public function testUntagged() | |
284 | { | |
285 | $this->logInAs('admin'); | |
286 | $client = $this->getClient(); | |
287 | ||
288 | $client->request('GET', '/untagged/list'); | |
289 | ||
290 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
291 | } | |
292 | ||
293 | public function testStarred() | |
294 | { | |
295 | $this->logInAs('admin'); | |
296 | $client = $this->getClient(); | |
297 | ||
298 | $client->request('GET', '/starred/list'); | |
299 | ||
300 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
301 | } | |
302 | ||
303 | public function testRangeException() | |
304 | { | |
305 | $this->logInAs('admin'); | |
306 | $client = $this->getClient(); | |
307 | ||
308 | $client->request('GET', '/all/list/900'); | |
309 | ||
310 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
311 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | |
312 | } | |
313 | ||
314 | /** | |
315 | * @depends testPostNewOk | |
316 | */ | |
317 | public function testView() | |
318 | { | |
319 | $this->logInAs('admin'); | |
320 | $client = $this->getClient(); | |
321 | ||
322 | $content = $client->getContainer() | |
323 | ->get('doctrine.orm.entity_manager') | |
324 | ->getRepository('WallabagCoreBundle:Entry') | |
325 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
326 | ||
327 | $crawler = $client->request('GET', '/view/'.$content->getId()); | |
328 | ||
329 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
330 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
331 | $this->assertContains($content->getTitle(), $body[0]); | |
332 | } | |
333 | ||
334 | /** | |
335 | * @depends testPostNewOk | |
336 | * | |
337 | * This test will require an internet connection. | |
338 | */ | |
339 | public function testReload() | |
340 | { | |
341 | $this->logInAs('admin'); | |
342 | $client = $this->getClient(); | |
343 | ||
344 | $em = $client->getContainer() | |
345 | ->get('doctrine.orm.entity_manager'); | |
346 | ||
347 | $content = $em | |
348 | ->getRepository('WallabagCoreBundle:Entry') | |
349 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
350 | ||
351 | // empty content | |
352 | $content->setContent(''); | |
353 | $em->persist($content); | |
354 | $em->flush(); | |
355 | ||
356 | $client->request('GET', '/reload/'.$content->getId()); | |
357 | ||
358 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
359 | ||
360 | $content = $em | |
361 | ->getRepository('WallabagCoreBundle:Entry') | |
362 | ->find($content->getId()); | |
363 | ||
364 | $this->assertNotEmpty($content->getContent()); | |
365 | } | |
366 | ||
367 | /** | |
368 | * @depends testPostNewOk | |
369 | */ | |
370 | public function testReloadWithFetchingFailed() | |
371 | { | |
372 | $this->logInAs('admin'); | |
373 | $client = $this->getClient(); | |
374 | ||
375 | $em = $client->getContainer() | |
376 | ->get('doctrine.orm.entity_manager'); | |
377 | ||
378 | $content = $em | |
379 | ->getRepository('WallabagCoreBundle:Entry') | |
380 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
381 | ||
382 | // put a known failed url | |
383 | $content->setUrl('http://0.0.0.0/failed.html'); | |
384 | $em->persist($content); | |
385 | $em->flush(); | |
386 | ||
387 | $client->request('GET', '/reload/'.$content->getId()); | |
388 | ||
389 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
390 | ||
391 | // force EntityManager to clear previous entity | |
392 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | |
393 | $em->clear(); | |
394 | $newContent = $em | |
395 | ->getRepository('WallabagCoreBundle:Entry') | |
396 | ->find($content->getId()); | |
397 | ||
398 | $newContent->setUrl($this->url); | |
399 | $em->persist($newContent); | |
400 | $em->flush(); | |
401 | ||
402 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | |
403 | } | |
404 | ||
405 | public function testEdit() | |
406 | { | |
407 | $this->logInAs('admin'); | |
408 | $client = $this->getClient(); | |
409 | ||
410 | $content = $client->getContainer() | |
411 | ->get('doctrine.orm.entity_manager') | |
412 | ->getRepository('WallabagCoreBundle:Entry') | |
413 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
414 | ||
415 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
416 | ||
417 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
418 | ||
419 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
420 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
421 | } | |
422 | ||
423 | public function testEditUpdate() | |
424 | { | |
425 | $this->logInAs('admin'); | |
426 | $client = $this->getClient(); | |
427 | ||
428 | $content = $client->getContainer() | |
429 | ->get('doctrine.orm.entity_manager') | |
430 | ->getRepository('WallabagCoreBundle:Entry') | |
431 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
432 | ||
433 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
434 | ||
435 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
436 | ||
437 | $form = $crawler->filter('button[type=submit]')->form(); | |
438 | ||
439 | $data = [ | |
440 | 'entry[title]' => 'My updated title hehe :)', | |
441 | ]; | |
442 | ||
443 | $client->submit($form, $data); | |
444 | ||
445 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
446 | ||
447 | $crawler = $client->followRedirect(); | |
448 | ||
449 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); | |
450 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
451 | } | |
452 | ||
453 | public function testToggleArchive() | |
454 | { | |
455 | $this->logInAs('admin'); | |
456 | $client = $this->getClient(); | |
457 | ||
458 | $content = $client->getContainer() | |
459 | ->get('doctrine.orm.entity_manager') | |
460 | ->getRepository('WallabagCoreBundle:Entry') | |
461 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
462 | ||
463 | $client->request('GET', '/archive/'.$content->getId()); | |
464 | ||
465 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
466 | ||
467 | $res = $client->getContainer() | |
468 | ->get('doctrine.orm.entity_manager') | |
469 | ->getRepository('WallabagCoreBundle:Entry') | |
470 | ->find($content->getId()); | |
471 | ||
472 | $this->assertEquals($res->isArchived(), true); | |
473 | } | |
474 | ||
475 | public function testToggleStar() | |
476 | { | |
477 | $this->logInAs('admin'); | |
478 | $client = $this->getClient(); | |
479 | ||
480 | $content = $client->getContainer() | |
481 | ->get('doctrine.orm.entity_manager') | |
482 | ->getRepository('WallabagCoreBundle:Entry') | |
483 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
484 | ||
485 | $client->request('GET', '/star/'.$content->getId()); | |
486 | ||
487 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
488 | ||
489 | $res = $client->getContainer() | |
490 | ->get('doctrine.orm.entity_manager') | |
491 | ->getRepository('WallabagCoreBundle:Entry') | |
492 | ->findOneById($content->getId()); | |
493 | ||
494 | $this->assertEquals($res->isStarred(), true); | |
495 | } | |
496 | ||
497 | public function testDelete() | |
498 | { | |
499 | $this->logInAs('admin'); | |
500 | $client = $this->getClient(); | |
501 | ||
502 | $content = $client->getContainer() | |
503 | ->get('doctrine.orm.entity_manager') | |
504 | ->getRepository('WallabagCoreBundle:Entry') | |
505 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
506 | ||
507 | $client->request('GET', '/delete/'.$content->getId()); | |
508 | ||
509 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
510 | ||
511 | $client->request('GET', '/delete/'.$content->getId()); | |
512 | ||
513 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
514 | } | |
515 | ||
516 | /** | |
517 | * It will create a new entry. | |
518 | * Browse to it. | |
519 | * Then remove it. | |
520 | * | |
521 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
522 | */ | |
523 | public function testViewAndDelete() | |
524 | { | |
525 | $this->logInAs('admin'); | |
526 | $client = $this->getClient(); | |
527 | ||
528 | $em = $client->getContainer() | |
529 | ->get('doctrine.orm.entity_manager'); | |
530 | ||
531 | // add a new content to be removed later | |
532 | $user = $em | |
533 | ->getRepository('WallabagUserBundle:User') | |
534 | ->findOneByUserName('admin'); | |
535 | ||
536 | $content = new Entry($user); | |
537 | $content->setUrl('http://1.1.1.1/entry'); | |
538 | $content->setReadingTime(12); | |
539 | $content->setDomainName('domain.io'); | |
540 | $content->setMimetype('text/html'); | |
541 | $content->setTitle('test title entry'); | |
542 | $content->setContent('This is my content /o/'); | |
543 | $content->setArchived(true); | |
544 | $content->setLanguage('fr'); | |
545 | ||
546 | $em->persist($content); | |
547 | $em->flush(); | |
548 | ||
549 | $client->request('GET', '/view/'.$content->getId()); | |
550 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
551 | ||
552 | $client->request('GET', '/delete/'.$content->getId()); | |
553 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
554 | ||
555 | $client->followRedirect(); | |
556 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
557 | } | |
558 | ||
559 | public function testViewOtherUserEntry() | |
560 | { | |
561 | $this->logInAs('admin'); | |
562 | $client = $this->getClient(); | |
563 | ||
564 | $content = $client->getContainer() | |
565 | ->get('doctrine.orm.entity_manager') | |
566 | ->getRepository('WallabagCoreBundle:Entry') | |
567 | ->findOneByUsernameAndNotArchived('bob'); | |
568 | ||
569 | $client->request('GET', '/view/'.$content->getId()); | |
570 | ||
571 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
572 | } | |
573 | ||
574 | public function testFilterOnReadingTime() | |
575 | { | |
576 | $this->logInAs('admin'); | |
577 | $client = $this->getClient(); | |
578 | ||
579 | $crawler = $client->request('GET', '/unread/list'); | |
580 | ||
581 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
582 | ||
583 | $data = [ | |
584 | 'entry_filter[readingTime][right_number]' => 22, | |
585 | 'entry_filter[readingTime][left_number]' => 22, | |
586 | ]; | |
587 | ||
588 | $crawler = $client->submit($form, $data); | |
589 | ||
590 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
591 | } | |
592 | ||
593 | public function testFilterOnReadingTimeOnlyUpper() | |
594 | { | |
595 | $this->logInAs('admin'); | |
596 | $client = $this->getClient(); | |
597 | ||
598 | $crawler = $client->request('GET', '/unread/list'); | |
599 | ||
600 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
601 | ||
602 | $data = [ | |
603 | 'entry_filter[readingTime][right_number]' => 22, | |
604 | ]; | |
605 | ||
606 | $crawler = $client->submit($form, $data); | |
607 | ||
608 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
609 | } | |
610 | ||
611 | public function testFilterOnReadingTimeOnlyLower() | |
612 | { | |
613 | $this->logInAs('admin'); | |
614 | $client = $this->getClient(); | |
615 | ||
616 | $crawler = $client->request('GET', '/unread/list'); | |
617 | ||
618 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
619 | ||
620 | $data = [ | |
621 | 'entry_filter[readingTime][left_number]' => 22, | |
622 | ]; | |
623 | ||
624 | $crawler = $client->submit($form, $data); | |
625 | ||
626 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
627 | } | |
628 | ||
629 | public function testFilterOnUnreadStatus() | |
630 | { | |
631 | $this->logInAs('admin'); | |
632 | $client = $this->getClient(); | |
633 | ||
634 | $crawler = $client->request('GET', '/all/list'); | |
635 | ||
636 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
637 | ||
638 | $data = [ | |
639 | 'entry_filter[isUnread]' => true, | |
640 | ]; | |
641 | ||
642 | $crawler = $client->submit($form, $data); | |
643 | ||
644 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
645 | } | |
646 | ||
647 | public function testFilterOnCreationDate() | |
648 | { | |
649 | $this->logInAs('admin'); | |
650 | $client = $this->getClient(); | |
651 | ||
652 | $crawler = $client->request('GET', '/unread/list'); | |
653 | ||
654 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
655 | ||
656 | $data = [ | |
657 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
658 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), | |
659 | ]; | |
660 | ||
661 | $crawler = $client->submit($form, $data); | |
662 | ||
663 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
664 | ||
665 | $data = [ | |
666 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
667 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
668 | ]; | |
669 | ||
670 | $crawler = $client->submit($form, $data); | |
671 | ||
672 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
673 | ||
674 | $data = [ | |
675 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
676 | 'entry_filter[createdAt][right_date]' => '01/01/1970', | |
677 | ]; | |
678 | ||
679 | $crawler = $client->submit($form, $data); | |
680 | ||
681 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
682 | } | |
683 | ||
684 | public function testPaginationWithFilter() | |
685 | { | |
686 | $this->logInAs('admin'); | |
687 | $client = $this->getClient(); | |
688 | $crawler = $client->request('GET', '/config'); | |
689 | ||
690 | $form = $crawler->filter('button[id=config_save]')->form(); | |
691 | ||
692 | $data = [ | |
693 | 'config[items_per_page]' => '1', | |
694 | ]; | |
695 | ||
696 | $client->submit($form, $data); | |
697 | ||
698 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
699 | ||
700 | $client->request('GET', 'unread/list'.$parameters); | |
701 | ||
702 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
703 | ||
704 | // reset pagination | |
705 | $crawler = $client->request('GET', '/config'); | |
706 | $form = $crawler->filter('button[id=config_save]')->form(); | |
707 | $data = [ | |
708 | 'config[items_per_page]' => '12', | |
709 | ]; | |
710 | $client->submit($form, $data); | |
711 | } | |
712 | ||
713 | public function testFilterOnDomainName() | |
714 | { | |
715 | $this->logInAs('admin'); | |
716 | $client = $this->getClient(); | |
717 | ||
718 | $crawler = $client->request('GET', '/unread/list'); | |
719 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
720 | $data = [ | |
721 | 'entry_filter[domainName]' => 'domain', | |
722 | ]; | |
723 | ||
724 | $crawler = $client->submit($form, $data); | |
725 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
726 | ||
727 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
728 | $data = [ | |
729 | 'entry_filter[domainName]' => 'wallabag', | |
730 | ]; | |
731 | ||
732 | $crawler = $client->submit($form, $data); | |
733 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
734 | } | |
735 | ||
736 | public function testFilterOnStatus() | |
737 | { | |
738 | $this->logInAs('admin'); | |
739 | $client = $this->getClient(); | |
740 | ||
741 | $crawler = $client->request('GET', '/unread/list'); | |
742 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
743 | $form['entry_filter[isArchived]']->tick(); | |
744 | $form['entry_filter[isStarred]']->untick(); | |
745 | ||
746 | $crawler = $client->submit($form); | |
747 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
748 | ||
749 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
750 | $form['entry_filter[isArchived]']->untick(); | |
751 | $form['entry_filter[isStarred]']->tick(); | |
752 | ||
753 | $crawler = $client->submit($form); | |
754 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
755 | } | |
756 | ||
757 | public function testPreviewPictureFilter() | |
758 | { | |
759 | $this->logInAs('admin'); | |
760 | $client = $this->getClient(); | |
761 | ||
762 | $crawler = $client->request('GET', '/unread/list'); | |
763 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
764 | $form['entry_filter[previewPicture]']->tick(); | |
765 | ||
766 | $crawler = $client->submit($form); | |
767 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
768 | } | |
769 | ||
770 | public function testFilterOnLanguage() | |
771 | { | |
772 | $this->logInAs('admin'); | |
773 | $client = $this->getClient(); | |
774 | ||
775 | $crawler = $client->request('GET', '/unread/list'); | |
776 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
777 | $data = [ | |
778 | 'entry_filter[language]' => 'fr', | |
779 | ]; | |
780 | ||
781 | $crawler = $client->submit($form, $data); | |
782 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
783 | ||
784 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
785 | $data = [ | |
786 | 'entry_filter[language]' => 'en', | |
787 | ]; | |
788 | ||
789 | $crawler = $client->submit($form, $data); | |
790 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
791 | } | |
792 | ||
793 | public function testShareEntryPublicly() | |
794 | { | |
795 | $this->logInAs('admin'); | |
796 | $client = $this->getClient(); | |
797 | ||
798 | $content = $client->getContainer() | |
799 | ->get('doctrine.orm.entity_manager') | |
800 | ->getRepository('WallabagCoreBundle:Entry') | |
801 | ->findOneByUser($this->getLoggedInUserId()); | |
802 | ||
803 | // no uuid | |
804 | $client->request('GET', '/share/'.$content->getUuid()); | |
805 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
806 | ||
807 | // generating the uuid | |
808 | $client->request('GET', '/share/'.$content->getId()); | |
809 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
810 | ||
811 | // follow link with uuid | |
812 | $crawler = $client->followRedirect(); | |
813 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
814 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
815 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
816 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
817 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
818 | $this->assertContains('og:title', $client->getResponse()->getContent()); | |
819 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
820 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
821 | $this->assertContains('og:image', $client->getResponse()->getContent()); | |
822 | ||
823 | // sharing is now disabled | |
824 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
825 | $client->request('GET', '/share/'.$content->getUuid()); | |
826 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
827 | ||
828 | $client->request('GET', '/view/'.$content->getId()); | |
829 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
830 | ||
831 | // removing the share | |
832 | $client->request('GET', '/share/delete/'.$content->getId()); | |
833 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
834 | ||
835 | // share is now disable | |
836 | $client->request('GET', '/share/'.$content->getUuid()); | |
837 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
838 | } | |
839 | } |