]>
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.paragraph_1', $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 | /** | |
164 | * This test will require an internet connection. | |
165 | */ | |
166 | public function testPostNewThatWillBeTagged() | |
167 | { | |
168 | $this->logInAs('admin'); | |
169 | $client = $this->getClient(); | |
170 | ||
171 | $crawler = $client->request('GET', '/new'); | |
172 | ||
173 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
174 | ||
175 | $form = $crawler->filter('form[name=entry]')->form(); | |
176 | ||
177 | $data = [ | |
178 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
179 | ]; | |
180 | ||
181 | $client->submit($form, $data); | |
182 | ||
183 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
184 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
185 | ||
186 | $em = $client->getContainer() | |
187 | ->get('doctrine.orm.entity_manager'); | |
188 | $entry = $em | |
189 | ->getRepository('WallabagCoreBundle:Entry') | |
190 | ->findOneByUrl($url); | |
191 | $tags = $entry->getTags(); | |
192 | ||
193 | $this->assertCount(1, $tags); | |
194 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
195 | ||
196 | $em->remove($entry); | |
197 | $em->flush(); | |
198 | ||
199 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
200 | // related https://github.com/wallabag/wallabag/issues/2121 | |
201 | $crawler = $client->request('GET', '/new'); | |
202 | ||
203 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
204 | ||
205 | $form = $crawler->filter('form[name=entry]')->form(); | |
206 | ||
207 | $data = [ | |
208 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
209 | ]; | |
210 | ||
211 | $client->submit($form, $data); | |
212 | ||
213 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
214 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
215 | ||
216 | $entry = $em | |
217 | ->getRepository('WallabagCoreBundle:Entry') | |
218 | ->findOneByUrl($url); | |
219 | ||
220 | $tags = $entry->getTags(); | |
221 | ||
222 | $this->assertCount(1, $tags); | |
223 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
224 | ||
225 | $em->remove($entry); | |
226 | $em->flush(); | |
227 | } | |
228 | ||
229 | public function testArchive() | |
230 | { | |
231 | $this->logInAs('admin'); | |
232 | $client = $this->getClient(); | |
233 | ||
234 | $client->request('GET', '/archive/list'); | |
235 | ||
236 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
237 | } | |
238 | ||
239 | public function testUntagged() | |
240 | { | |
241 | $this->logInAs('admin'); | |
242 | $client = $this->getClient(); | |
243 | ||
244 | $client->request('GET', '/untagged/list'); | |
245 | ||
246 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
247 | } | |
248 | ||
249 | public function testStarred() | |
250 | { | |
251 | $this->logInAs('admin'); | |
252 | $client = $this->getClient(); | |
253 | ||
254 | $client->request('GET', '/starred/list'); | |
255 | ||
256 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
257 | } | |
258 | ||
259 | public function testRangeException() | |
260 | { | |
261 | $this->logInAs('admin'); | |
262 | $client = $this->getClient(); | |
263 | ||
264 | $client->request('GET', '/all/list/900'); | |
265 | ||
266 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
267 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | |
268 | } | |
269 | ||
270 | /** | |
271 | * @depends testPostNewOk | |
272 | */ | |
273 | public function testView() | |
274 | { | |
275 | $this->logInAs('admin'); | |
276 | $client = $this->getClient(); | |
277 | ||
278 | $content = $client->getContainer() | |
279 | ->get('doctrine.orm.entity_manager') | |
280 | ->getRepository('WallabagCoreBundle:Entry') | |
281 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
282 | ||
283 | $crawler = $client->request('GET', '/view/'.$content->getId()); | |
284 | ||
285 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
286 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
287 | $this->assertContains($content->getTitle(), $body[0]); | |
288 | } | |
289 | ||
290 | /** | |
291 | * @depends testPostNewOk | |
292 | * | |
293 | * This test will require an internet connection. | |
294 | */ | |
295 | public function testReload() | |
296 | { | |
297 | $this->logInAs('admin'); | |
298 | $client = $this->getClient(); | |
299 | ||
300 | $content = $client->getContainer() | |
301 | ->get('doctrine.orm.entity_manager') | |
302 | ->getRepository('WallabagCoreBundle:Entry') | |
303 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
304 | ||
305 | // empty content | |
306 | $content->setContent(''); | |
307 | $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content); | |
308 | $client->getContainer()->get('doctrine.orm.entity_manager')->flush(); | |
309 | ||
310 | $client->request('GET', '/reload/'.$content->getId()); | |
311 | ||
312 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
313 | ||
314 | $content = $client->getContainer() | |
315 | ->get('doctrine.orm.entity_manager') | |
316 | ->getRepository('WallabagCoreBundle:Entry') | |
317 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
318 | ||
319 | $this->assertNotEmpty($content->getContent()); | |
320 | } | |
321 | ||
322 | public function testEdit() | |
323 | { | |
324 | $this->logInAs('admin'); | |
325 | $client = $this->getClient(); | |
326 | ||
327 | $content = $client->getContainer() | |
328 | ->get('doctrine.orm.entity_manager') | |
329 | ->getRepository('WallabagCoreBundle:Entry') | |
330 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
331 | ||
332 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
333 | ||
334 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
335 | ||
336 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
337 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
338 | } | |
339 | ||
340 | public function testEditUpdate() | |
341 | { | |
342 | $this->logInAs('admin'); | |
343 | $client = $this->getClient(); | |
344 | ||
345 | $content = $client->getContainer() | |
346 | ->get('doctrine.orm.entity_manager') | |
347 | ->getRepository('WallabagCoreBundle:Entry') | |
348 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
349 | ||
350 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
351 | ||
352 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
353 | ||
354 | $form = $crawler->filter('button[type=submit]')->form(); | |
355 | ||
356 | $data = [ | |
357 | 'entry[title]' => 'My updated title hehe :)', | |
358 | ]; | |
359 | ||
360 | $client->submit($form, $data); | |
361 | ||
362 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
363 | ||
364 | $crawler = $client->followRedirect(); | |
365 | ||
366 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); | |
367 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
368 | } | |
369 | ||
370 | public function testToggleArchive() | |
371 | { | |
372 | $this->logInAs('admin'); | |
373 | $client = $this->getClient(); | |
374 | ||
375 | $content = $client->getContainer() | |
376 | ->get('doctrine.orm.entity_manager') | |
377 | ->getRepository('WallabagCoreBundle:Entry') | |
378 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
379 | ||
380 | $client->request('GET', '/archive/'.$content->getId()); | |
381 | ||
382 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
383 | ||
384 | $res = $client->getContainer() | |
385 | ->get('doctrine.orm.entity_manager') | |
386 | ->getRepository('WallabagCoreBundle:Entry') | |
387 | ->find($content->getId()); | |
388 | ||
389 | $this->assertEquals($res->isArchived(), true); | |
390 | } | |
391 | ||
392 | public function testToggleStar() | |
393 | { | |
394 | $this->logInAs('admin'); | |
395 | $client = $this->getClient(); | |
396 | ||
397 | $content = $client->getContainer() | |
398 | ->get('doctrine.orm.entity_manager') | |
399 | ->getRepository('WallabagCoreBundle:Entry') | |
400 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
401 | ||
402 | $client->request('GET', '/star/'.$content->getId()); | |
403 | ||
404 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
405 | ||
406 | $res = $client->getContainer() | |
407 | ->get('doctrine.orm.entity_manager') | |
408 | ->getRepository('WallabagCoreBundle:Entry') | |
409 | ->findOneById($content->getId()); | |
410 | ||
411 | $this->assertEquals($res->isStarred(), true); | |
412 | } | |
413 | ||
414 | public function testDelete() | |
415 | { | |
416 | $this->logInAs('admin'); | |
417 | $client = $this->getClient(); | |
418 | ||
419 | $content = $client->getContainer() | |
420 | ->get('doctrine.orm.entity_manager') | |
421 | ->getRepository('WallabagCoreBundle:Entry') | |
422 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
423 | ||
424 | $client->request('GET', '/delete/'.$content->getId()); | |
425 | ||
426 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
427 | ||
428 | $client->request('GET', '/delete/'.$content->getId()); | |
429 | ||
430 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
431 | } | |
432 | ||
433 | /** | |
434 | * It will create a new entry. | |
435 | * Browse to it. | |
436 | * Then remove it. | |
437 | * | |
438 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
439 | */ | |
440 | public function testViewAndDelete() | |
441 | { | |
442 | $this->logInAs('admin'); | |
443 | $client = $this->getClient(); | |
444 | ||
445 | // add a new content to be removed later | |
446 | $user = $client->getContainer() | |
447 | ->get('doctrine.orm.entity_manager') | |
448 | ->getRepository('WallabagUserBundle:User') | |
449 | ->findOneByUserName('admin'); | |
450 | ||
451 | $content = new Entry($user); | |
452 | $content->setUrl('http://1.1.1.1/entry'); | |
453 | $content->setReadingTime(12); | |
454 | $content->setDomainName('domain.io'); | |
455 | $content->setMimetype('text/html'); | |
456 | $content->setTitle('test title entry'); | |
457 | $content->setContent('This is my content /o/'); | |
458 | $content->setArchived(true); | |
459 | $content->setLanguage('fr'); | |
460 | ||
461 | $client->getContainer() | |
462 | ->get('doctrine.orm.entity_manager') | |
463 | ->persist($content); | |
464 | $client->getContainer() | |
465 | ->get('doctrine.orm.entity_manager') | |
466 | ->flush(); | |
467 | ||
468 | $client->request('GET', '/view/'.$content->getId()); | |
469 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
470 | ||
471 | $client->request('GET', '/delete/'.$content->getId()); | |
472 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
473 | ||
474 | $client->followRedirect(); | |
475 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
476 | } | |
477 | ||
478 | public function testViewOtherUserEntry() | |
479 | { | |
480 | $this->logInAs('admin'); | |
481 | $client = $this->getClient(); | |
482 | ||
483 | $content = $client->getContainer() | |
484 | ->get('doctrine.orm.entity_manager') | |
485 | ->getRepository('WallabagCoreBundle:Entry') | |
486 | ->findOneByUsernameAndNotArchived('bob'); | |
487 | ||
488 | $client->request('GET', '/view/'.$content->getId()); | |
489 | ||
490 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
491 | } | |
492 | ||
493 | public function testFilterOnReadingTime() | |
494 | { | |
495 | $this->logInAs('admin'); | |
496 | $client = $this->getClient(); | |
497 | ||
498 | $crawler = $client->request('GET', '/unread/list'); | |
499 | ||
500 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
501 | ||
502 | $data = [ | |
503 | 'entry_filter[readingTime][right_number]' => 22, | |
504 | 'entry_filter[readingTime][left_number]' => 22, | |
505 | ]; | |
506 | ||
507 | $crawler = $client->submit($form, $data); | |
508 | ||
509 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
510 | } | |
511 | ||
512 | public function testFilterOnReadingTimeOnlyUpper() | |
513 | { | |
514 | $this->logInAs('admin'); | |
515 | $client = $this->getClient(); | |
516 | ||
517 | $crawler = $client->request('GET', '/unread/list'); | |
518 | ||
519 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
520 | ||
521 | $data = [ | |
522 | 'entry_filter[readingTime][right_number]' => 22, | |
523 | ]; | |
524 | ||
525 | $crawler = $client->submit($form, $data); | |
526 | ||
527 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
528 | } | |
529 | ||
530 | public function testFilterOnReadingTimeOnlyLower() | |
531 | { | |
532 | $this->logInAs('admin'); | |
533 | $client = $this->getClient(); | |
534 | ||
535 | $crawler = $client->request('GET', '/unread/list'); | |
536 | ||
537 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
538 | ||
539 | $data = [ | |
540 | 'entry_filter[readingTime][left_number]' => 22, | |
541 | ]; | |
542 | ||
543 | $crawler = $client->submit($form, $data); | |
544 | ||
545 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
546 | } | |
547 | ||
548 | public function testFilterOnUnreadStatus() | |
549 | { | |
550 | $this->logInAs('admin'); | |
551 | $client = $this->getClient(); | |
552 | ||
553 | $crawler = $client->request('GET', '/all/list'); | |
554 | ||
555 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
556 | ||
557 | $data = [ | |
558 | 'entry_filter[isUnread]' => true, | |
559 | ]; | |
560 | ||
561 | $crawler = $client->submit($form, $data); | |
562 | ||
563 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
564 | } | |
565 | ||
566 | public function testFilterOnCreationDate() | |
567 | { | |
568 | $this->logInAs('admin'); | |
569 | $client = $this->getClient(); | |
570 | ||
571 | $crawler = $client->request('GET', '/unread/list'); | |
572 | ||
573 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
574 | ||
575 | $data = [ | |
576 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
577 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), | |
578 | ]; | |
579 | ||
580 | $crawler = $client->submit($form, $data); | |
581 | ||
582 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
583 | ||
584 | $data = [ | |
585 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
586 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
587 | ]; | |
588 | ||
589 | $crawler = $client->submit($form, $data); | |
590 | ||
591 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
592 | ||
593 | $data = [ | |
594 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
595 | 'entry_filter[createdAt][right_date]' => '01/01/1970', | |
596 | ]; | |
597 | ||
598 | $crawler = $client->submit($form, $data); | |
599 | ||
600 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
601 | } | |
602 | ||
603 | public function testPaginationWithFilter() | |
604 | { | |
605 | $this->logInAs('admin'); | |
606 | $client = $this->getClient(); | |
607 | $crawler = $client->request('GET', '/config'); | |
608 | ||
609 | $form = $crawler->filter('button[id=config_save]')->form(); | |
610 | ||
611 | $data = [ | |
612 | 'config[items_per_page]' => '1', | |
613 | ]; | |
614 | ||
615 | $client->submit($form, $data); | |
616 | ||
617 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
618 | ||
619 | $client->request('GET', 'unread/list'.$parameters); | |
620 | ||
621 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
622 | ||
623 | // reset pagination | |
624 | $crawler = $client->request('GET', '/config'); | |
625 | $form = $crawler->filter('button[id=config_save]')->form(); | |
626 | $data = [ | |
627 | 'config[items_per_page]' => '12', | |
628 | ]; | |
629 | $client->submit($form, $data); | |
630 | } | |
631 | ||
632 | public function testFilterOnDomainName() | |
633 | { | |
634 | $this->logInAs('admin'); | |
635 | $client = $this->getClient(); | |
636 | ||
637 | $crawler = $client->request('GET', '/unread/list'); | |
638 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
639 | $data = [ | |
640 | 'entry_filter[domainName]' => 'domain', | |
641 | ]; | |
642 | ||
643 | $crawler = $client->submit($form, $data); | |
644 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
645 | ||
646 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
647 | $data = [ | |
648 | 'entry_filter[domainName]' => 'wallabag', | |
649 | ]; | |
650 | ||
651 | $crawler = $client->submit($form, $data); | |
652 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
653 | } | |
654 | ||
655 | public function testFilterOnStatus() | |
656 | { | |
657 | $this->logInAs('admin'); | |
658 | $client = $this->getClient(); | |
659 | ||
660 | $crawler = $client->request('GET', '/unread/list'); | |
661 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
662 | $form['entry_filter[isArchived]']->tick(); | |
663 | $form['entry_filter[isStarred]']->untick(); | |
664 | ||
665 | $crawler = $client->submit($form); | |
666 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
667 | ||
668 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
669 | $form['entry_filter[isArchived]']->untick(); | |
670 | $form['entry_filter[isStarred]']->tick(); | |
671 | ||
672 | $crawler = $client->submit($form); | |
673 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
674 | } | |
675 | ||
676 | public function testPreviewPictureFilter() | |
677 | { | |
678 | $this->logInAs('admin'); | |
679 | $client = $this->getClient(); | |
680 | ||
681 | $crawler = $client->request('GET', '/unread/list'); | |
682 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
683 | $form['entry_filter[previewPicture]']->tick(); | |
684 | ||
685 | $crawler = $client->submit($form); | |
686 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
687 | } | |
688 | ||
689 | public function testFilterOnLanguage() | |
690 | { | |
691 | $this->logInAs('admin'); | |
692 | $client = $this->getClient(); | |
693 | ||
694 | $crawler = $client->request('GET', '/unread/list'); | |
695 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
696 | $data = [ | |
697 | 'entry_filter[language]' => 'fr', | |
698 | ]; | |
699 | ||
700 | $crawler = $client->submit($form, $data); | |
701 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
702 | ||
703 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
704 | $data = [ | |
705 | 'entry_filter[language]' => 'en', | |
706 | ]; | |
707 | ||
708 | $crawler = $client->submit($form, $data); | |
709 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
710 | } | |
711 | ||
712 | public function testCache() | |
713 | { | |
714 | $this->logInAs('admin'); | |
715 | $client = $this->getClient(); | |
716 | ||
717 | $content = $client->getContainer() | |
718 | ->get('doctrine.orm.entity_manager') | |
719 | ->getRepository('WallabagCoreBundle:Entry') | |
720 | ->findOneByUser($this->getLoggedInUserId()); | |
721 | ||
722 | // no uuid | |
723 | $client->request('GET', '/share/'.$content->getUuid()); | |
724 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
725 | ||
726 | // generating the uuid | |
727 | $client->request('GET', '/share/'.$content->getId()); | |
728 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
729 | ||
730 | // follow link with uuid | |
731 | $crawler = $client->followRedirect(); | |
732 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
733 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
734 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
735 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
736 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
737 | ||
738 | // sharing is now disabled | |
739 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
740 | $client->request('GET', '/share/'.$content->getUuid()); | |
741 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
742 | ||
743 | $client->request('GET', '/view/'.$content->getId()); | |
744 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
745 | ||
746 | // removing the share | |
747 | $client->request('GET', '/share/delete/'.$content->getId()); | |
748 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
749 | ||
750 | // share is now disable | |
751 | $client->request('GET', '/share/'.$content->getUuid()); | |
752 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
753 | } | |
754 | } |