]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Lock deps for FOSUser
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / EntryControllerTest.php
CommitLineData
93fd4692
NL
1<?php
2
23634d5d 3namespace Tests\Wallabag\CoreBundle\Controller;
93fd4692 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
2863bf2a 6use Wallabag\CoreBundle\Entity\Entry;
93fd4692 7
769e19dc 8class EntryControllerTest extends WallabagCoreTestCase
93fd4692 9{
02d17813
JB
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
3b815d2d
J
12 public function testLogin()
13 {
14 $client = $this->getClient();
15
eb3bd7ef 16 $client->request('GET', '/new');
3b815d2d
J
17
18 $this->assertEquals(302, $client->getResponse()->getStatusCode());
19 $this->assertContains('login', $client->getResponse()->headers->get('location'));
20 }
21
5c072d2b
NL
22 public function testQuickstart()
23 {
24 $this->logInAs('empty');
25 $client = $this->getClient();
26
27 $client->request('GET', '/unread/list');
4f9cf232 28 $crawler = $client->followRedirect();
5c072d2b
NL
29
30 $this->assertEquals(200, $client->getResponse()->getStatusCode());
4094ea47 31 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
24ad330b 32 $this->assertContains('quickstart.intro.title', $body[0]);
5c072d2b
NL
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
0d42217e 39 $form = $crawler->filter('form[name=entry]')->form();
5c072d2b 40
4094ea47 41 $data = [
78833672 42 'entry[url]' => $this->url,
4094ea47 43 ];
5c072d2b
NL
44
45 $client->submit($form, $data);
46 $this->assertEquals(302, $client->getResponse()->getStatusCode());
47 $client->followRedirect();
48
4f9cf232 49 $crawler = $client->request('GET', '/unread/list');
4094ea47 50 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4f9cf232 51 $this->assertContains('entry.list.number_on_the_page', $body[0]);
5c072d2b
NL
52 }
53
9c0c8820 54 public function testGetNew()
93fd4692 55 {
eb3bd7ef 56 $this->logInAs('admin');
3b815d2d 57 $client = $this->getClient();
93fd4692 58
aa6e27cf 59 $crawler = $client->request('GET', '/new');
93fd4692
NL
60
61 $this->assertEquals(200, $client->getResponse()->getStatusCode());
9c0c8820
J
62
63 $this->assertCount(1, $crawler->filter('input[type=url]'));
0d42217e 64 $this->assertCount(1, $crawler->filter('form[name=entry]'));
9c0c8820
J
65 }
66
880a0e1c
NL
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
4094ea47 77 $client->request('GET', '/bookmarklet', ['url' => $this->url]);
880a0e1c 78 $this->assertEquals(302, $client->getResponse()->getStatusCode());
5c072d2b 79 $client->followRedirect();
880a0e1c
NL
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')
78833672 87 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
880a0e1c
NL
88 $em->remove($entry);
89 $em->flush();
90 }
91
9c0c8820
J
92 public function testPostNewEmpty()
93 {
eb3bd7ef 94 $this->logInAs('admin');
3b815d2d 95 $client = $this->getClient();
9c0c8820
J
96
97 $crawler = $client->request('GET', '/new');
98
99 $this->assertEquals(200, $client->getResponse()->getStatusCode());
100
0d42217e 101 $form = $crawler->filter('form[name=entry]')->form();
9c0c8820
J
102
103 $crawler = $client->submit($form);
104
105 $this->assertEquals(200, $client->getResponse()->getStatusCode());
4094ea47 106 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
9c0c8820
J
107 $this->assertEquals('This value should not be blank.', $alert[0]);
108 }
109
8a493541 110 /**
75c48e3a 111 * This test will require an internet connection.
8a493541 112 */
9c0c8820
J
113 public function testPostNewOk()
114 {
eb3bd7ef 115 $this->logInAs('admin');
3b815d2d 116 $client = $this->getClient();
9c0c8820
J
117
118 $crawler = $client->request('GET', '/new');
119
120 $this->assertEquals(200, $client->getResponse()->getStatusCode());
121
0d42217e 122 $form = $crawler->filter('form[name=entry]')->form();
9c0c8820 123
4094ea47 124 $data = [
02d17813 125 'entry[url]' => $this->url,
4094ea47 126 ];
9c0c8820
J
127
128 $client->submit($form, $data);
129
130 $this->assertEquals(302, $client->getResponse()->getStatusCode());
131
a0d6ccc5
JB
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 }
9c0c8820 141
a0d6ccc5
JB
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
0d42217e 151 $form = $crawler->filter('form[name=entry]')->form();
a0d6ccc5 152
4094ea47 153 $data = [
a0d6ccc5 154 'entry[url]' => $this->url,
4094ea47 155 ];
a0d6ccc5
JB
156
157 $client->submit($form, $data);
158
159 $this->assertEquals(302, $client->getResponse()->getStatusCode());
160 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
9c0c8820
J
161 }
162
19ca0b2f
JB
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 ];
a0d6ccc5
JB
191
192 $client->submit($form, $data);
193
194 $this->assertEquals(302, $client->getResponse()->getStatusCode());
195 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
d6d3fb6e
JB
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();
9c0c8820
J
205 }
206
958671a7
KG
207 /**
208 * This test will require an internet connection.
209 */
3be04745 210 public function testPostNewThatWillBeTagged()
958671a7
KG
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
0d42217e 219 $form = $crawler->filter('form[name=entry]')->form();
958671a7 220
4094ea47 221 $data = [
958671a7 222 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
4094ea47 223 ];
958671a7
KG
224
225 $client->submit($form, $data);
226
227 $this->assertEquals(302, $client->getResponse()->getStatusCode());
3be04745 228 $this->assertContains('/', $client->getResponse()->getTargetUrl());
958671a7
KG
229
230 $em = $client->getContainer()
231 ->get('doctrine.orm.entity_manager');
232 $entry = $em
233 ->getRepository('WallabagCoreBundle:Entry')
234 ->findOneByUrl($url);
69edb774
KG
235 $tags = $entry->getTags();
236
237 $this->assertCount(1, $tags);
238 $this->assertEquals('wallabag', $tags[0]->getLabel());
958671a7
KG
239
240 $em->remove($entry);
241 $em->flush();
3be04745
JB
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();
958671a7
KG
271 }
272
9c0c8820
J
273 public function testArchive()
274 {
eb3bd7ef 275 $this->logInAs('admin');
3b815d2d 276 $client = $this->getClient();
9c0c8820 277
9fb6ac83 278 $client->request('GET', '/archive/list');
9c0c8820
J
279
280 $this->assertEquals(200, $client->getResponse()->getStatusCode());
281 }
282
d5d16121
NL
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
9c0c8820
J
293 public function testStarred()
294 {
eb3bd7ef 295 $this->logInAs('admin');
3b815d2d 296 $client = $this->getClient();
9c0c8820 297
9fb6ac83 298 $client->request('GET', '/starred/list');
9c0c8820
J
299
300 $this->assertEquals(200, $client->getResponse()->getStatusCode());
301 }
302
671a2b88
ML
303 public function testRangeException()
304 {
305 $this->logInAs('admin');
306 $client = $this->getClient();
307
308 $client->request('GET', '/all/list/900');
309
1880da74
NL
310 $this->assertEquals(302, $client->getResponse()->getStatusCode());
311 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
671a2b88
ML
312 }
313
8a493541
JB
314 /**
315 * @depends testPostNewOk
316 */
9c0c8820
J
317 public function testView()
318 {
eb3bd7ef 319 $this->logInAs('admin');
3b815d2d 320 $client = $this->getClient();
9c0c8820
J
321
322 $content = $client->getContainer()
323 ->get('doctrine.orm.entity_manager')
324 ->getRepository('WallabagCoreBundle:Entry')
78833672 325 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
9c0c8820 326
4f9cf232 327 $crawler = $client->request('GET', '/view/'.$content->getId());
9c0c8820
J
328
329 $this->assertEquals(200, $client->getResponse()->getStatusCode());
4094ea47 330 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4f9cf232 331 $this->assertContains($content->getTitle(), $body[0]);
93fd4692 332 }
eb3bd7ef 333
831b02aa
JB
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
ac8cf632
JB
344 $em = $client->getContainer()
345 ->get('doctrine.orm.entity_manager');
346
347 $content = $em
831b02aa 348 ->getRepository('WallabagCoreBundle:Entry')
78833672 349 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
831b02aa
JB
350
351 // empty content
352 $content->setContent('');
ac8cf632
JB
353 $em->persist($content);
354 $em->flush();
831b02aa
JB
355
356 $client->request('GET', '/reload/'.$content->getId());
357
358 $this->assertEquals(302, $client->getResponse()->getStatusCode());
359
ac8cf632 360 $content = $em
831b02aa 361 ->getRepository('WallabagCoreBundle:Entry')
78833672 362 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
831b02aa
JB
363
364 $this->assertNotEmpty($content->getContent());
365 }
366
82d6d9cb
JB
367 public function testEdit()
368 {
369 $this->logInAs('admin');
370 $client = $this->getClient();
371
372 $content = $client->getContainer()
373 ->get('doctrine.orm.entity_manager')
374 ->getRepository('WallabagCoreBundle:Entry')
78833672 375 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
82d6d9cb
JB
376
377 $crawler = $client->request('GET', '/edit/'.$content->getId());
378
379 $this->assertEquals(200, $client->getResponse()->getStatusCode());
380
381 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
382 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
383 }
384
385 public function testEditUpdate()
386 {
387 $this->logInAs('admin');
388 $client = $this->getClient();
389
390 $content = $client->getContainer()
391 ->get('doctrine.orm.entity_manager')
392 ->getRepository('WallabagCoreBundle:Entry')
78833672 393 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
82d6d9cb
JB
394
395 $crawler = $client->request('GET', '/edit/'.$content->getId());
396
397 $this->assertEquals(200, $client->getResponse()->getStatusCode());
398
399 $form = $crawler->filter('button[type=submit]')->form();
400
4094ea47 401 $data = [
82d6d9cb 402 'entry[title]' => 'My updated title hehe :)',
4094ea47 403 ];
82d6d9cb
JB
404
405 $client->submit($form, $data);
406
407 $this->assertEquals(302, $client->getResponse()->getStatusCode());
408
409 $crawler = $client->followRedirect();
410
4094ea47 411 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
82d6d9cb
JB
412 $this->assertContains('My updated title hehe :)', $alert[0]);
413 }
414
eb3bd7ef
J
415 public function testToggleArchive()
416 {
417 $this->logInAs('admin');
418 $client = $this->getClient();
419
420 $content = $client->getContainer()
421 ->get('doctrine.orm.entity_manager')
422 ->getRepository('WallabagCoreBundle:Entry')
78833672 423 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
eb3bd7ef
J
424
425 $client->request('GET', '/archive/'.$content->getId());
426
427 $this->assertEquals(302, $client->getResponse()->getStatusCode());
428
429 $res = $client->getContainer()
430 ->get('doctrine.orm.entity_manager')
431 ->getRepository('WallabagCoreBundle:Entry')
159986c4 432 ->find($content->getId());
eb3bd7ef
J
433
434 $this->assertEquals($res->isArchived(), true);
435 }
436
437 public function testToggleStar()
438 {
439 $this->logInAs('admin');
440 $client = $this->getClient();
441
442 $content = $client->getContainer()
443 ->get('doctrine.orm.entity_manager')
444 ->getRepository('WallabagCoreBundle:Entry')
78833672 445 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
eb3bd7ef
J
446
447 $client->request('GET', '/star/'.$content->getId());
448
449 $this->assertEquals(302, $client->getResponse()->getStatusCode());
450
451 $res = $client->getContainer()
452 ->get('doctrine.orm.entity_manager')
453 ->getRepository('WallabagCoreBundle:Entry')
454 ->findOneById($content->getId());
455
456 $this->assertEquals($res->isStarred(), true);
457 }
458
459 public function testDelete()
460 {
461 $this->logInAs('admin');
462 $client = $this->getClient();
463
464 $content = $client->getContainer()
465 ->get('doctrine.orm.entity_manager')
466 ->getRepository('WallabagCoreBundle:Entry')
78833672 467 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
eb3bd7ef
J
468
469 $client->request('GET', '/delete/'.$content->getId());
470
471 $this->assertEquals(302, $client->getResponse()->getStatusCode());
472
1d147791 473 $client->request('GET', '/delete/'.$content->getId());
eb3bd7ef 474
1d147791 475 $this->assertEquals(404, $client->getResponse()->getStatusCode());
eb3bd7ef 476 }
3d2b2d62 477
2863bf2a
JB
478 /**
479 * It will create a new entry.
480 * Browse to it.
481 * Then remove it.
482 *
483 * And it'll check that user won't be redirected to the view page of the content when it had been removed
484 */
485 public function testViewAndDelete()
486 {
487 $this->logInAs('admin');
488 $client = $this->getClient();
489
ac8cf632
JB
490 $em = $client->getContainer()
491 ->get('doctrine.orm.entity_manager');
492
2863bf2a 493 // add a new content to be removed later
ac8cf632 494 $user = $em
2863bf2a
JB
495 ->getRepository('WallabagUserBundle:User')
496 ->findOneByUserName('admin');
497
498 $content = new Entry($user);
499 $content->setUrl('http://1.1.1.1/entry');
500 $content->setReadingTime(12);
501 $content->setDomainName('domain.io');
502 $content->setMimetype('text/html');
503 $content->setTitle('test title entry');
504 $content->setContent('This is my content /o/');
505 $content->setArchived(true);
506 $content->setLanguage('fr');
507
ac8cf632
JB
508 $em->persist($content);
509 $em->flush();
2863bf2a
JB
510
511 $client->request('GET', '/view/'.$content->getId());
512 $this->assertEquals(200, $client->getResponse()->getStatusCode());
513
514 $client->request('GET', '/delete/'.$content->getId());
515 $this->assertEquals(302, $client->getResponse()->getStatusCode());
516
517 $client->followRedirect();
518 $this->assertEquals(200, $client->getResponse()->getStatusCode());
519 }
520
3d2b2d62
J
521 public function testViewOtherUserEntry()
522 {
159986c4 523 $this->logInAs('admin');
3d2b2d62
J
524 $client = $this->getClient();
525
526 $content = $client->getContainer()
527 ->get('doctrine.orm.entity_manager')
528 ->getRepository('WallabagCoreBundle:Entry')
159986c4 529 ->findOneByUsernameAndNotArchived('bob');
3d2b2d62 530
159986c4 531 $client->request('GET', '/view/'.$content->getId());
3d2b2d62
J
532
533 $this->assertEquals(403, $client->getResponse()->getStatusCode());
534 }
26864574 535
3f357ee2 536 public function testFilterOnReadingTime()
26864574
NL
537 {
538 $this->logInAs('admin');
539 $client = $this->getClient();
540
541 $crawler = $client->request('GET', '/unread/list');
542
543 $form = $crawler->filter('button[id=submit-filter]')->form();
544
4094ea47 545 $data = [
d6a9e139
NL
546 'entry_filter[readingTime][right_number]' => 22,
547 'entry_filter[readingTime][left_number]' => 22,
4094ea47 548 ];
26864574
NL
549
550 $crawler = $client->submit($form, $data);
551
552 $this->assertCount(1, $crawler->filter('div[class=entry]'));
553 }
ab2c93c7 554
95859e54
JB
555 public function testFilterOnReadingTimeOnlyUpper()
556 {
557 $this->logInAs('admin');
558 $client = $this->getClient();
559
560 $crawler = $client->request('GET', '/unread/list');
561
562 $form = $crawler->filter('button[id=submit-filter]')->form();
563
564 $data = [
565 'entry_filter[readingTime][right_number]' => 22,
566 ];
567
568 $crawler = $client->submit($form, $data);
569
570 $this->assertCount(2, $crawler->filter('div[class=entry]'));
571 }
572
573 public function testFilterOnReadingTimeOnlyLower()
574 {
575 $this->logInAs('admin');
576 $client = $this->getClient();
577
578 $crawler = $client->request('GET', '/unread/list');
579
580 $form = $crawler->filter('button[id=submit-filter]')->form();
581
582 $data = [
583 'entry_filter[readingTime][left_number]' => 22,
584 ];
585
586 $crawler = $client->submit($form, $data);
587
588 $this->assertCount(4, $crawler->filter('div[class=entry]'));
589 }
590
30334567
DB
591 public function testFilterOnUnreadStatus()
592 {
593 $this->logInAs('admin');
594 $client = $this->getClient();
595
596 $crawler = $client->request('GET', '/all/list');
597
598 $form = $crawler->filter('button[id=submit-filter]')->form();
599
600 $data = [
601 'entry_filter[isUnread]' => true,
602 ];
603
604 $crawler = $client->submit($form, $data);
605
606 $this->assertCount(4, $crawler->filter('div[class=entry]'));
607 }
608
3f357ee2
NL
609 public function testFilterOnCreationDate()
610 {
611 $this->logInAs('admin');
612 $client = $this->getClient();
613
614 $crawler = $client->request('GET', '/unread/list');
615
616 $form = $crawler->filter('button[id=submit-filter]')->form();
617
4094ea47 618 $data = [
3f357ee2 619 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
8ce32af6 620 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
4094ea47 621 ];
3f357ee2
NL
622
623 $crawler = $client->submit($form, $data);
624
e1779760 625 $this->assertCount(5, $crawler->filter('div[class=entry]'));
3f357ee2 626
4094ea47 627 $data = [
f90af145
JB
628 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
629 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
4094ea47 630 ];
f90af145
JB
631
632 $crawler = $client->submit($form, $data);
633
634 $this->assertCount(5, $crawler->filter('div[class=entry]'));
635
4094ea47 636 $data = [
3f357ee2 637 'entry_filter[createdAt][left_date]' => '01/01/1970',
8ce32af6 638 'entry_filter[createdAt][right_date]' => '01/01/1970',
4094ea47 639 ];
3f357ee2
NL
640
641 $crawler = $client->submit($form, $data);
642
643 $this->assertCount(0, $crawler->filter('div[class=entry]'));
3f357ee2
NL
644 }
645
ab2c93c7
NL
646 public function testPaginationWithFilter()
647 {
648 $this->logInAs('admin');
649 $client = $this->getClient();
ab2c93c7
NL
650 $crawler = $client->request('GET', '/config');
651
652 $form = $crawler->filter('button[id=config_save]')->form();
653
4094ea47 654 $data = [
ab2c93c7 655 'config[items_per_page]' => '1',
4094ea47 656 ];
ab2c93c7
NL
657
658 $client->submit($form, $data);
659
76cd8dbb 660 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
ab2c93c7 661
5c072d2b 662 $client->request('GET', 'unread/list'.$parameters);
ab2c93c7
NL
663
664 $this->assertContains($parameters, $client->getResponse()->getContent());
e1779760
NL
665
666 // reset pagination
667 $crawler = $client->request('GET', '/config');
668 $form = $crawler->filter('button[id=config_save]')->form();
4094ea47 669 $data = [
e1779760 670 'config[items_per_page]' => '12',
4094ea47 671 ];
e1779760 672 $client->submit($form, $data);
ab2c93c7 673 }
443cecd2
NL
674
675 public function testFilterOnDomainName()
676 {
677 $this->logInAs('admin');
678 $client = $this->getClient();
679
680 $crawler = $client->request('GET', '/unread/list');
681 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 682 $data = [
02d17813 683 'entry_filter[domainName]' => 'domain',
4094ea47 684 ];
443cecd2
NL
685
686 $crawler = $client->submit($form, $data);
02d17813 687 $this->assertCount(5, $crawler->filter('div[class=entry]'));
443cecd2
NL
688
689 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 690 $data = [
8ce32af6 691 'entry_filter[domainName]' => 'wallabag',
4094ea47 692 ];
443cecd2
NL
693
694 $crawler = $client->submit($form, $data);
695 $this->assertCount(0, $crawler->filter('div[class=entry]'));
696 }
e1779760
NL
697
698 public function testFilterOnStatus()
699 {
700 $this->logInAs('admin');
701 $client = $this->getClient();
702
703 $crawler = $client->request('GET', '/unread/list');
704 $form = $crawler->filter('button[id=submit-filter]')->form();
705 $form['entry_filter[isArchived]']->tick();
706 $form['entry_filter[isStarred]']->untick();
707
708 $crawler = $client->submit($form);
159986c4 709 $this->assertCount(1, $crawler->filter('div[class=entry]'));
e1779760
NL
710
711 $form = $crawler->filter('button[id=submit-filter]')->form();
712 $form['entry_filter[isArchived]']->untick();
713 $form['entry_filter[isStarred]']->tick();
714
715 $crawler = $client->submit($form);
02d17813 716 $this->assertCount(1, $crawler->filter('div[class=entry]'));
e1779760 717 }
497e0cad
NL
718
719 public function testPreviewPictureFilter()
720 {
721 $this->logInAs('admin');
722 $client = $this->getClient();
723
724 $crawler = $client->request('GET', '/unread/list');
725 $form = $crawler->filter('button[id=submit-filter]')->form();
726 $form['entry_filter[previewPicture]']->tick();
727
728 $crawler = $client->submit($form);
729 $this->assertCount(1, $crawler->filter('div[class=entry]'));
730 }
d4ebe5c5
JB
731
732 public function testFilterOnLanguage()
733 {
734 $this->logInAs('admin');
735 $client = $this->getClient();
736
737 $crawler = $client->request('GET', '/unread/list');
738 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 739 $data = [
159986c4 740 'entry_filter[language]' => 'fr',
4094ea47 741 ];
d4ebe5c5
JB
742
743 $crawler = $client->submit($form, $data);
02d17813 744 $this->assertCount(2, $crawler->filter('div[class=entry]'));
d4ebe5c5
JB
745
746 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 747 $data = [
d4ebe5c5 748 'entry_filter[language]' => 'en',
4094ea47 749 ];
d4ebe5c5
JB
750
751 $crawler = $client->submit($form, $data);
752 $this->assertCount(2, $crawler->filter('div[class=entry]'));
753 }
a7e2218e 754
21d82c3c 755 public function testShareEntryPublicly()
a7e2218e
NL
756 {
757 $this->logInAs('admin');
758 $client = $this->getClient();
759
760 $content = $client->getContainer()
761 ->get('doctrine.orm.entity_manager')
762 ->getRepository('WallabagCoreBundle:Entry')
763 ->findOneByUser($this->getLoggedInUserId());
764
eddda878 765 // no uuid
a7e2218e 766 $client->request('GET', '/share/'.$content->getUuid());
eddda878
JB
767 $this->assertEquals(404, $client->getResponse()->getStatusCode());
768
769 // generating the uuid
770 $client->request('GET', '/share/'.$content->getId());
771 $this->assertEquals(302, $client->getResponse()->getStatusCode());
772
773 // follow link with uuid
774 $crawler = $client->followRedirect();
775 $this->assertEquals(200, $client->getResponse()->getStatusCode());
776 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
777 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
778 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
a7e2218e 779 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
21d82c3c
NL
780 $this->assertContains('og:title', $client->getResponse()->getContent());
781 $this->assertContains('og:type', $client->getResponse()->getContent());
782 $this->assertContains('og:url', $client->getResponse()->getContent());
d5c45d52 783 $this->assertContains('og:image', $client->getResponse()->getContent());
a7e2218e 784
eddda878
JB
785 // sharing is now disabled
786 $client->getContainer()->get('craue_config')->set('share_public', 0);
787 $client->request('GET', '/share/'.$content->getUuid());
788 $this->assertEquals(404, $client->getResponse()->getStatusCode());
789
a7e2218e
NL
790 $client->request('GET', '/view/'.$content->getId());
791 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
eddda878
JB
792
793 // removing the share
794 $client->request('GET', '/share/delete/'.$content->getId());
795 $this->assertEquals(302, $client->getResponse()->getStatusCode());
796
797 // share is now disable
798 $client->request('GET', '/share/'.$content->getUuid());
799 $this->assertEquals(404, $client->getResponse()->getStatusCode());
a7e2218e 800 }
93fd4692 801}