]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Liberation goes https
[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;
65cd8a4a 6use Wallabag\CoreBundle\Entity\Config;
2863bf2a 7use Wallabag\CoreBundle\Entity\Entry;
9de9f1e5 8use Wallabag\CoreBundle\Entity\SiteCredential;
b8568662 9use Wallabag\CoreBundle\Entity\Tag;
300f293c 10use Wallabag\CoreBundle\Helper\ContentProxy;
93fd4692 11
769e19dc 12class EntryControllerTest extends WallabagCoreTestCase
93fd4692 13{
77854331 14 const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
be085c3d 15 public $downloadImagesEnabled = false;
77854331 16 public $url = 'https://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';
02d17813 17
be085c3d
JB
18 /**
19 * @after
20 *
21 * Ensure download_images_enabled is disabled after each script
22 */
23 public function tearDownImagesEnabled()
24 {
25 if ($this->downloadImagesEnabled) {
26 $client = static::createClient();
27 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
28
29 $this->downloadImagesEnabled = false;
30 }
31 }
32
3b815d2d
J
33 public function testLogin()
34 {
35 $client = $this->getClient();
36
eb3bd7ef 37 $client->request('GET', '/new');
3b815d2d 38
f808b016 39 $this->assertSame(302, $client->getResponse()->getStatusCode());
3b815d2d
J
40 $this->assertContains('login', $client->getResponse()->headers->get('location'));
41 }
42
5c072d2b
NL
43 public function testQuickstart()
44 {
45 $this->logInAs('empty');
46 $client = $this->getClient();
47
48 $client->request('GET', '/unread/list');
38520658 49 $this->assertSame(302, $client->getResponse()->getStatusCode());
4f9cf232 50 $crawler = $client->followRedirect();
5c072d2b 51
f808b016 52 $this->assertSame(200, $client->getResponse()->getStatusCode());
4094ea47 53 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
24ad330b 54 $this->assertContains('quickstart.intro.title', $body[0]);
5c072d2b
NL
55
56 // Test if quickstart is disabled when user has 1 entry
57 $crawler = $client->request('GET', '/new');
58
f808b016 59 $this->assertSame(200, $client->getResponse()->getStatusCode());
5c072d2b 60
0d42217e 61 $form = $crawler->filter('form[name=entry]')->form();
5c072d2b 62
4094ea47 63 $data = [
78833672 64 'entry[url]' => $this->url,
4094ea47 65 ];
5c072d2b
NL
66
67 $client->submit($form, $data);
f808b016 68 $this->assertSame(302, $client->getResponse()->getStatusCode());
5c072d2b
NL
69 $client->followRedirect();
70
4f9cf232 71 $crawler = $client->request('GET', '/unread/list');
4094ea47 72 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4f9cf232 73 $this->assertContains('entry.list.number_on_the_page', $body[0]);
5c072d2b
NL
74 }
75
9c0c8820 76 public function testGetNew()
93fd4692 77 {
eb3bd7ef 78 $this->logInAs('admin');
7ab5eb95 79 $this->useTheme('baggy');
3b815d2d 80 $client = $this->getClient();
93fd4692 81
aa6e27cf 82 $crawler = $client->request('GET', '/new');
93fd4692 83
f808b016 84 $this->assertSame(200, $client->getResponse()->getStatusCode());
9c0c8820
J
85
86 $this->assertCount(1, $crawler->filter('input[type=url]'));
0d42217e 87 $this->assertCount(1, $crawler->filter('form[name=entry]'));
9c0c8820
J
88 }
89
880a0e1c
NL
90 public function testPostNewViaBookmarklet()
91 {
92 $this->logInAs('admin');
7ab5eb95 93 $this->useTheme('baggy');
880a0e1c
NL
94 $client = $this->getClient();
95
96 $crawler = $client->request('GET', '/');
97
98 $this->assertCount(4, $crawler->filter('div[class=entry]'));
99
100 // Good URL
4094ea47 101 $client->request('GET', '/bookmarklet', ['url' => $this->url]);
f808b016 102 $this->assertSame(302, $client->getResponse()->getStatusCode());
5c072d2b 103 $client->followRedirect();
880a0e1c
NL
104 $crawler = $client->request('GET', '/');
105 $this->assertCount(5, $crawler->filter('div[class=entry]'));
106
107 $em = $client->getContainer()
108 ->get('doctrine.orm.entity_manager');
109 $entry = $em
110 ->getRepository('WallabagCoreBundle:Entry')
78833672 111 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
880a0e1c
NL
112 $em->remove($entry);
113 $em->flush();
114 }
115
9c0c8820
J
116 public function testPostNewEmpty()
117 {
eb3bd7ef 118 $this->logInAs('admin');
3b815d2d 119 $client = $this->getClient();
9c0c8820
J
120
121 $crawler = $client->request('GET', '/new');
122
f808b016 123 $this->assertSame(200, $client->getResponse()->getStatusCode());
9c0c8820 124
0d42217e 125 $form = $crawler->filter('form[name=entry]')->form();
9c0c8820
J
126
127 $crawler = $client->submit($form);
128
f808b016 129 $this->assertSame(200, $client->getResponse()->getStatusCode());
4094ea47 130 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
f808b016 131 $this->assertSame('This value should not be blank.', $alert[0]);
9c0c8820
J
132 }
133
8a493541 134 /**
75c48e3a 135 * This test will require an internet connection.
8a493541 136 */
9c0c8820
J
137 public function testPostNewOk()
138 {
eb3bd7ef 139 $this->logInAs('admin');
3b815d2d 140 $client = $this->getClient();
9c0c8820 141
8a219854
NL
142 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
143
9c0c8820
J
144 $crawler = $client->request('GET', '/new');
145
f808b016 146 $this->assertSame(200, $client->getResponse()->getStatusCode());
9c0c8820 147
0d42217e 148 $form = $crawler->filter('form[name=entry]')->form();
9c0c8820 149
4094ea47 150 $data = [
02d17813 151 'entry[url]' => $this->url,
4094ea47 152 ];
9c0c8820
J
153
154 $client->submit($form, $data);
155
f808b016 156 $this->assertSame(302, $client->getResponse()->getStatusCode());
9c0c8820 157
a0d6ccc5
JB
158 $content = $client->getContainer()
159 ->get('doctrine.orm.entity_manager')
160 ->getRepository('WallabagCoreBundle:Entry')
161 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
162
7b0b3622
NL
163 $author = $content->getPublishedBy();
164
a0d6ccc5 165 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
f808b016 166 $this->assertSame($this->url, $content->getUrl());
a0d6ccc5 167 $this->assertContains('Google', $content->getTitle());
f808b016 168 $this->assertSame('fr', $content->getLanguage());
d81bf605 169 $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
f808b016 170 $this->assertSame('Morgane Tual', $author[0]);
dda6a6ad 171 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
8a219854 172 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
a0d6ccc5 173 }
9c0c8820 174
e9c80c99
NL
175 public function testPostWithMultipleAuthors()
176 {
84b3bdaa 177 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
e9c80c99
NL
178 $this->logInAs('admin');
179 $client = $this->getClient();
180
181 $crawler = $client->request('GET', '/new');
182
f808b016 183 $this->assertSame(200, $client->getResponse()->getStatusCode());
e9c80c99
NL
184
185 $form = $crawler->filter('form[name=entry]')->form();
186
187 $data = [
188 'entry[url]' => $url,
189 ];
190
191 $client->submit($form, $data);
192
f808b016 193 $this->assertSame(302, $client->getResponse()->getStatusCode());
e9c80c99
NL
194
195 $content = $client->getContainer()
196 ->get('doctrine.orm.entity_manager')
197 ->getRepository('WallabagCoreBundle:Entry')
198 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
199
84b3bdaa 200 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
e9c80c99 201 $authors = $content->getPublishedBy();
f808b016
JB
202 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
203 $this->assertSame('fr', $content->getLanguage());
204 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
205 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
e9c80c99
NL
206 }
207
a0d6ccc5
JB
208 public function testPostNewOkUrlExist()
209 {
210 $this->logInAs('admin');
7ab5eb95 211
212 $entry = new Entry($this->getLoggedInUser());
213 $entry->setUrl($this->url);
214 $this->getEntityManager()->persist($entry);
215 $this->getEntityManager()->flush();
216
a0d6ccc5
JB
217 $client = $this->getClient();
218
219 $crawler = $client->request('GET', '/new');
220
f808b016 221 $this->assertSame(200, $client->getResponse()->getStatusCode());
a0d6ccc5 222
0d42217e 223 $form = $crawler->filter('form[name=entry]')->form();
a0d6ccc5 224
4094ea47 225 $data = [
a0d6ccc5 226 'entry[url]' => $this->url,
4094ea47 227 ];
a0d6ccc5
JB
228
229 $client->submit($form, $data);
230
f808b016 231 $this->assertSame(302, $client->getResponse()->getStatusCode());
a0d6ccc5 232 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
9c0c8820
J
233 }
234
19ca0b2f
JB
235 public function testPostNewOkUrlExistWithAccent()
236 {
237 $this->logInAs('admin');
238 $client = $this->getClient();
239
240 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
241
242 $crawler = $client->request('GET', '/new');
243
f808b016 244 $this->assertSame(200, $client->getResponse()->getStatusCode());
19ca0b2f
JB
245
246 $form = $crawler->filter('form[name=entry]')->form();
247
248 $data = [
249 'entry[url]' => $url,
250 ];
251
252 $client->submit($form, $data);
253
254 $crawler = $client->request('GET', '/new');
255
f808b016 256 $this->assertSame(200, $client->getResponse()->getStatusCode());
19ca0b2f
JB
257
258 $form = $crawler->filter('form[name=entry]')->form();
259
260 $data = [
261 'entry[url]' => $url,
262 ];
a0d6ccc5
JB
263
264 $client->submit($form, $data);
265
f808b016 266 $this->assertSame(302, $client->getResponse()->getStatusCode());
a0d6ccc5 267 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
9c0c8820
J
268 }
269
958671a7
KG
270 /**
271 * This test will require an internet connection.
272 */
3be04745 273 public function testPostNewThatWillBeTagged()
958671a7
KG
274 {
275 $this->logInAs('admin');
276 $client = $this->getClient();
277
278 $crawler = $client->request('GET', '/new');
279
f808b016 280 $this->assertSame(200, $client->getResponse()->getStatusCode());
958671a7 281
0d42217e 282 $form = $crawler->filter('form[name=entry]')->form();
958671a7 283
4094ea47 284 $data = [
958671a7 285 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
4094ea47 286 ];
958671a7
KG
287
288 $client->submit($form, $data);
289
f808b016 290 $this->assertSame(302, $client->getResponse()->getStatusCode());
3be04745 291 $this->assertContains('/', $client->getResponse()->getTargetUrl());
958671a7
KG
292
293 $em = $client->getContainer()
294 ->get('doctrine.orm.entity_manager');
295 $entry = $em
296 ->getRepository('WallabagCoreBundle:Entry')
297 ->findOneByUrl($url);
69edb774
KG
298 $tags = $entry->getTags();
299
fdd725f5 300 $this->assertCount(2, $tags);
7ab5eb95 301 $this->assertContains('wallabag', $tags);
f808b016 302 $this->assertSame('en', $entry->getLanguage());
958671a7
KG
303
304 $em->remove($entry);
305 $em->flush();
3be04745
JB
306
307 // and now re-submit it to test the cascade persistence for tags after entry removal
308 // related https://github.com/wallabag/wallabag/issues/2121
309 $crawler = $client->request('GET', '/new');
310
f808b016 311 $this->assertSame(200, $client->getResponse()->getStatusCode());
3be04745
JB
312
313 $form = $crawler->filter('form[name=entry]')->form();
314
315 $data = [
316 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
317 ];
318
319 $client->submit($form, $data);
320
f808b016 321 $this->assertSame(302, $client->getResponse()->getStatusCode());
3be04745
JB
322 $this->assertContains('/', $client->getResponse()->getTargetUrl());
323
324 $entry = $em
325 ->getRepository('WallabagCoreBundle:Entry')
326 ->findOneByUrl($url);
327
328 $tags = $entry->getTags();
329
fdd725f5 330 $this->assertCount(2, $tags);
7ab5eb95 331 $this->assertContains('wallabag', $tags);
3be04745
JB
332
333 $em->remove($entry);
334 $em->flush();
958671a7
KG
335 }
336
9c0c8820
J
337 public function testArchive()
338 {
eb3bd7ef 339 $this->logInAs('admin');
3b815d2d 340 $client = $this->getClient();
9c0c8820 341
9fb6ac83 342 $client->request('GET', '/archive/list');
9c0c8820 343
f808b016 344 $this->assertSame(200, $client->getResponse()->getStatusCode());
9c0c8820
J
345 }
346
d5d16121
NL
347 public function testUntagged()
348 {
349 $this->logInAs('admin');
350 $client = $this->getClient();
351
352 $client->request('GET', '/untagged/list');
353
f808b016 354 $this->assertSame(200, $client->getResponse()->getStatusCode());
d5d16121
NL
355 }
356
9c0c8820
J
357 public function testStarred()
358 {
eb3bd7ef 359 $this->logInAs('admin');
3b815d2d 360 $client = $this->getClient();
9c0c8820 361
9fb6ac83 362 $client->request('GET', '/starred/list');
9c0c8820 363
f808b016 364 $this->assertSame(200, $client->getResponse()->getStatusCode());
9c0c8820
J
365 }
366
671a2b88
ML
367 public function testRangeException()
368 {
369 $this->logInAs('admin');
370 $client = $this->getClient();
371
372 $client->request('GET', '/all/list/900');
373
f808b016
JB
374 $this->assertSame(302, $client->getResponse()->getStatusCode());
375 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
671a2b88
ML
376 }
377
9c0c8820
J
378 public function testView()
379 {
eb3bd7ef 380 $this->logInAs('admin');
3b815d2d 381 $client = $this->getClient();
9c0c8820 382
7ab5eb95 383 $entry = new Entry($this->getLoggedInUser());
384 $entry->setUrl('http://example.com/foo');
385 $entry->setTitle('title foo');
386 $entry->setContent('foo bar baz');
387 $this->getEntityManager()->persist($entry);
388 $this->getEntityManager()->flush();
9c0c8820 389
f808b016 390 $crawler = $client->request('GET', '/view/' . $entry->getId());
9c0c8820 391
f808b016 392 $this->assertSame(200, $client->getResponse()->getStatusCode());
4094ea47 393 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
7ab5eb95 394 $this->assertContains($entry->getTitle(), $body[0]);
93fd4692 395 }
eb3bd7ef 396
831b02aa 397 /**
831b02aa
JB
398 * This test will require an internet connection.
399 */
400 public function testReload()
401 {
402 $this->logInAs('admin');
403 $client = $this->getClient();
404
7ab5eb95 405 $entry = new Entry($this->getLoggedInUser());
406 $entry->setUrl($this->url);
407 $entry->setTitle('title foo');
408 $entry->setContent('');
409 $this->getEntityManager()->persist($entry);
410 $this->getEntityManager()->flush();
411 $this->getEntityManager()->clear();
ac8cf632 412
f808b016 413 $client->request('GET', '/reload/' . $entry->getId());
831b02aa 414
f808b016 415 $this->assertSame(302, $client->getResponse()->getStatusCode());
831b02aa 416
7ab5eb95 417 $entry = $this->getEntityManager()
831b02aa 418 ->getRepository('WallabagCoreBundle:Entry')
7ab5eb95 419 ->find($entry->getId());
831b02aa 420
7ab5eb95 421 $this->assertNotEmpty($entry->getContent());
831b02aa
JB
422 }
423
2297d60f
JB
424 public function testReloadWithFetchingFailed()
425 {
426 $this->logInAs('admin');
427 $client = $this->getClient();
428
7ab5eb95 429 $entry = new Entry($this->getLoggedInUser());
430 $entry->setUrl('http://0.0.0.0/failed.html');
431 $this->getEntityManager()->persist($entry);
432 $this->getEntityManager()->flush();
2297d60f 433
f808b016 434 $client->request('GET', '/reload/' . $entry->getId());
2297d60f 435
f808b016 436 $this->assertSame(302, $client->getResponse()->getStatusCode());
2297d60f
JB
437
438 // force EntityManager to clear previous entity
439 // otherwise, retrieve the same entity will retrieve change from the previous request :0
7ab5eb95 440 $this->getEntityManager()->clear();
441 $newContent = $this->getEntityManager()
2297d60f 442 ->getRepository('WallabagCoreBundle:Entry')
7ab5eb95 443 ->find($entry->getId());
2297d60f 444
f808b016 445 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
2297d60f
JB
446 }
447
82d6d9cb
JB
448 public function testEdit()
449 {
450 $this->logInAs('admin');
451 $client = $this->getClient();
452
7ab5eb95 453 $entry = new Entry($this->getLoggedInUser());
454 $entry->setUrl($this->url);
455 $this->getEntityManager()->persist($entry);
456 $this->getEntityManager()->flush();
82d6d9cb 457
f808b016 458 $crawler = $client->request('GET', '/edit/' . $entry->getId());
82d6d9cb 459
f808b016 460 $this->assertSame(200, $client->getResponse()->getStatusCode());
82d6d9cb
JB
461
462 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
463 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
464 }
465
466 public function testEditUpdate()
467 {
468 $this->logInAs('admin');
469 $client = $this->getClient();
470
7ab5eb95 471 $entry = new Entry($this->getLoggedInUser());
472 $entry->setUrl($this->url);
473 $this->getEntityManager()->persist($entry);
474 $this->getEntityManager()->flush();
82d6d9cb 475
f808b016 476 $crawler = $client->request('GET', '/edit/' . $entry->getId());
82d6d9cb 477
f808b016 478 $this->assertSame(200, $client->getResponse()->getStatusCode());
82d6d9cb 479
5614df19 480 $form = $crawler->filter('button[id=entry_save]')->form();
82d6d9cb 481
4094ea47 482 $data = [
82d6d9cb 483 'entry[title]' => 'My updated title hehe :)',
97444566 484 'entry[origin_url]' => 'https://example.io',
4094ea47 485 ];
82d6d9cb
JB
486
487 $client->submit($form, $data);
488
f808b016 489 $this->assertSame(302, $client->getResponse()->getStatusCode());
82d6d9cb
JB
490
491 $crawler = $client->followRedirect();
492
97444566
KD
493 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
494 $this->assertContains('My updated title hehe :)', $title[0]);
495 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
496 $this->assertContains('example.io', trim($stats[1]));
497 }
498
499 public function testEditRemoveOriginUrl()
500 {
501 $this->logInAs('admin');
502 $client = $this->getClient();
503
504 $entry = new Entry($this->getLoggedInUser());
505 $entry->setUrl($this->url);
506 $this->getEntityManager()->persist($entry);
507 $this->getEntityManager()->flush();
508
509 $crawler = $client->request('GET', '/edit/' . $entry->getId());
510
511 $this->assertSame(200, $client->getResponse()->getStatusCode());
512
5614df19 513 $form = $crawler->filter('button[id=entry_save]')->form();
97444566
KD
514
515 $data = [
516 'entry[title]' => 'My updated title hehe :)',
517 'entry[origin_url]' => '',
518 ];
519
520 $client->submit($form, $data);
521
522 $this->assertSame(302, $client->getResponse()->getStatusCode());
523
524 $crawler = $client->followRedirect();
525
526 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
527 $this->assertContains('My updated title hehe :)', $title[0]);
2a1ceb67 528 $this->assertSame(1, \count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
97444566 529 $this->assertNotContains('example.io', trim($stats[0]));
82d6d9cb
JB
530 }
531
eb3bd7ef
J
532 public function testToggleArchive()
533 {
534 $this->logInAs('admin');
535 $client = $this->getClient();
536
7ab5eb95 537 $entry = new Entry($this->getLoggedInUser());
538 $entry->setUrl($this->url);
539 $this->getEntityManager()->persist($entry);
540 $this->getEntityManager()->flush();
541 $this->getEntityManager()->clear();
eb3bd7ef 542
f808b016 543 $client->request('GET', '/archive/' . $entry->getId());
eb3bd7ef 544
f808b016 545 $this->assertSame(302, $client->getResponse()->getStatusCode());
eb3bd7ef
J
546
547 $res = $client->getContainer()
548 ->get('doctrine.orm.entity_manager')
549 ->getRepository('WallabagCoreBundle:Entry')
7ab5eb95 550 ->find($entry->getId());
eb3bd7ef 551
38520658 552 $this->assertSame(1, $res->isArchived());
eb3bd7ef
J
553 }
554
555 public function testToggleStar()
556 {
557 $this->logInAs('admin');
558 $client = $this->getClient();
559
7ab5eb95 560 $entry = new Entry($this->getLoggedInUser());
561 $entry->setUrl($this->url);
562 $this->getEntityManager()->persist($entry);
563 $this->getEntityManager()->flush();
564 $this->getEntityManager()->clear();
eb3bd7ef 565
f808b016 566 $client->request('GET', '/star/' . $entry->getId());
eb3bd7ef 567
f808b016 568 $this->assertSame(302, $client->getResponse()->getStatusCode());
eb3bd7ef
J
569
570 $res = $client->getContainer()
571 ->get('doctrine.orm.entity_manager')
572 ->getRepository('WallabagCoreBundle:Entry')
7ab5eb95 573 ->findOneById($entry->getId());
eb3bd7ef 574
38520658 575 $this->assertSame(1, $res->isStarred());
eb3bd7ef
J
576 }
577
578 public function testDelete()
579 {
580 $this->logInAs('admin');
581 $client = $this->getClient();
582
7ab5eb95 583 $entry = new Entry($this->getLoggedInUser());
584 $entry->setUrl($this->url);
585 $this->getEntityManager()->persist($entry);
586 $this->getEntityManager()->flush();
eb3bd7ef 587
f808b016 588 $client->request('GET', '/delete/' . $entry->getId());
eb3bd7ef 589
f808b016 590 $this->assertSame(302, $client->getResponse()->getStatusCode());
eb3bd7ef 591
f808b016 592 $client->request('GET', '/delete/' . $entry->getId());
eb3bd7ef 593
f808b016 594 $this->assertSame(404, $client->getResponse()->getStatusCode());
eb3bd7ef 595 }
3d2b2d62 596
2863bf2a
JB
597 /**
598 * It will create a new entry.
599 * Browse to it.
600 * Then remove it.
601 *
602 * And it'll check that user won't be redirected to the view page of the content when it had been removed
603 */
604 public function testViewAndDelete()
605 {
606 $this->logInAs('admin');
607 $client = $this->getClient();
608
ac8cf632
JB
609 $em = $client->getContainer()
610 ->get('doctrine.orm.entity_manager');
611
2863bf2a 612 // add a new content to be removed later
ac8cf632 613 $user = $em
2863bf2a
JB
614 ->getRepository('WallabagUserBundle:User')
615 ->findOneByUserName('admin');
616
617 $content = new Entry($user);
618 $content->setUrl('http://1.1.1.1/entry');
619 $content->setReadingTime(12);
620 $content->setDomainName('domain.io');
621 $content->setMimetype('text/html');
622 $content->setTitle('test title entry');
623 $content->setContent('This is my content /o/');
624 $content->setArchived(true);
625 $content->setLanguage('fr');
626
ac8cf632
JB
627 $em->persist($content);
628 $em->flush();
2863bf2a 629
f808b016
JB
630 $client->request('GET', '/view/' . $content->getId());
631 $this->assertSame(200, $client->getResponse()->getStatusCode());
2863bf2a 632
f808b016
JB
633 $client->request('GET', '/delete/' . $content->getId());
634 $this->assertSame(302, $client->getResponse()->getStatusCode());
2863bf2a
JB
635
636 $client->followRedirect();
f808b016 637 $this->assertSame(200, $client->getResponse()->getStatusCode());
2863bf2a
JB
638 }
639
3d2b2d62
J
640 public function testViewOtherUserEntry()
641 {
159986c4 642 $this->logInAs('admin');
3d2b2d62
J
643 $client = $this->getClient();
644
645 $content = $client->getContainer()
646 ->get('doctrine.orm.entity_manager')
647 ->getRepository('WallabagCoreBundle:Entry')
159986c4 648 ->findOneByUsernameAndNotArchived('bob');
3d2b2d62 649
f808b016 650 $client->request('GET', '/view/' . $content->getId());
3d2b2d62 651
f808b016 652 $this->assertSame(403, $client->getResponse()->getStatusCode());
3d2b2d62 653 }
26864574 654
3f357ee2 655 public function testFilterOnReadingTime()
26864574
NL
656 {
657 $this->logInAs('admin');
7ab5eb95 658 $this->useTheme('baggy');
26864574 659 $client = $this->getClient();
7ab5eb95 660 $entry = new Entry($this->getLoggedInUser());
661 $entry->setUrl($this->url);
662 $entry->setReadingTime(22);
663 $this->getEntityManager()->persist($entry);
664 $this->getEntityManager()->flush();
26864574
NL
665
666 $crawler = $client->request('GET', '/unread/list');
667
668 $form = $crawler->filter('button[id=submit-filter]')->form();
669
4094ea47 670 $data = [
d6a9e139
NL
671 'entry_filter[readingTime][right_number]' => 22,
672 'entry_filter[readingTime][left_number]' => 22,
4094ea47 673 ];
26864574
NL
674
675 $crawler = $client->submit($form, $data);
676
677 $this->assertCount(1, $crawler->filter('div[class=entry]'));
678 }
ab2c93c7 679
1b164717
JB
680 public function testFilterOnReadingTimeWithNegativeValue()
681 {
682 $this->logInAs('admin');
683 $client = $this->getClient();
684
685 $crawler = $client->request('GET', '/unread/list');
686
687 $form = $crawler->filter('button[id=submit-filter]')->form();
688
689 $data = [
690 'entry_filter[readingTime][right_number]' => -22,
691 'entry_filter[readingTime][left_number]' => -22,
692 ];
693
694 $crawler = $client->submit($form, $data);
695
696 // forcing negative value results in no entry displayed
697 $this->assertCount(0, $crawler->filter('div[class=entry]'));
698 }
699
95859e54
JB
700 public function testFilterOnReadingTimeOnlyUpper()
701 {
702 $this->logInAs('admin');
7ab5eb95 703 $this->useTheme('baggy');
95859e54
JB
704 $client = $this->getClient();
705
7ab5eb95 706 $crawler = $client->request('GET', '/all/list');
707 $this->assertCount(5, $crawler->filter('div[class=entry]'));
708
709 $entry = new Entry($this->getLoggedInUser());
710 $entry->setUrl($this->url);
711 $entry->setReadingTime(23);
712 $this->getEntityManager()->persist($entry);
713 $this->getEntityManager()->flush();
714
715 $crawler = $client->request('GET', '/all/list');
716 $this->assertCount(6, $crawler->filter('div[class=entry]'));
95859e54
JB
717
718 $form = $crawler->filter('button[id=submit-filter]')->form();
719
720 $data = [
721 'entry_filter[readingTime][right_number]' => 22,
722 ];
723
724 $crawler = $client->submit($form, $data);
725
7ab5eb95 726 $this->assertCount(5, $crawler->filter('div[class=entry]'));
95859e54
JB
727 }
728
729 public function testFilterOnReadingTimeOnlyLower()
730 {
731 $this->logInAs('admin');
7ab5eb95 732 $this->useTheme('baggy');
95859e54
JB
733 $client = $this->getClient();
734
735 $crawler = $client->request('GET', '/unread/list');
736
737 $form = $crawler->filter('button[id=submit-filter]')->form();
738
739 $data = [
740 'entry_filter[readingTime][left_number]' => 22,
741 ];
742
743 $crawler = $client->submit($form, $data);
744
7ab5eb95 745 $this->assertCount(0, $crawler->filter('div[class=entry]'));
746
747 $entry = new Entry($this->getLoggedInUser());
748 $entry->setUrl($this->url);
749 $entry->setReadingTime(23);
750 $this->getEntityManager()->persist($entry);
751 $this->getEntityManager()->flush();
752
753 $crawler = $client->submit($form, $data);
754 $this->assertCount(1, $crawler->filter('div[class=entry]'));
95859e54
JB
755 }
756
30334567
DB
757 public function testFilterOnUnreadStatus()
758 {
759 $this->logInAs('admin');
7ab5eb95 760 $this->useTheme('baggy');
30334567
DB
761 $client = $this->getClient();
762
763 $crawler = $client->request('GET', '/all/list');
764
765 $form = $crawler->filter('button[id=submit-filter]')->form();
766
767 $data = [
768 'entry_filter[isUnread]' => true,
769 ];
770
771 $crawler = $client->submit($form, $data);
772
7ab5eb95 773 $this->assertCount(4, $crawler->filter('div[class=entry]'));
774
775 $entry = new Entry($this->getLoggedInUser());
776 $entry->setUrl($this->url);
777 $entry->setArchived(false);
778 $this->getEntityManager()->persist($entry);
779 $this->getEntityManager()->flush();
780
781 $crawler = $client->submit($form, $data);
782
e9c80c99 783 $this->assertCount(5, $crawler->filter('div[class=entry]'));
30334567
DB
784 }
785
3f357ee2
NL
786 public function testFilterOnCreationDate()
787 {
788 $this->logInAs('admin');
7ab5eb95 789 $this->useTheme('baggy');
3f357ee2
NL
790 $client = $this->getClient();
791
792 $crawler = $client->request('GET', '/unread/list');
793
794 $form = $crawler->filter('button[id=submit-filter]')->form();
795
4094ea47 796 $data = [
3f357ee2 797 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
8ce32af6 798 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
4094ea47 799 ];
3f357ee2
NL
800
801 $crawler = $client->submit($form, $data);
802
7ab5eb95 803 $this->assertCount(5, $crawler->filter('div[class=entry]'));
3f357ee2 804
4094ea47 805 $data = [
f90af145
JB
806 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
807 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
4094ea47 808 ];
f90af145
JB
809
810 $crawler = $client->submit($form, $data);
811
7ab5eb95 812 $this->assertCount(5, $crawler->filter('div[class=entry]'));
f90af145 813
4094ea47 814 $data = [
3f357ee2 815 'entry_filter[createdAt][left_date]' => '01/01/1970',
8ce32af6 816 'entry_filter[createdAt][right_date]' => '01/01/1970',
4094ea47 817 ];
3f357ee2
NL
818
819 $crawler = $client->submit($form, $data);
820
821 $this->assertCount(0, $crawler->filter('div[class=entry]'));
3f357ee2
NL
822 }
823
ab2c93c7
NL
824 public function testPaginationWithFilter()
825 {
826 $this->logInAs('admin');
827 $client = $this->getClient();
ab2c93c7
NL
828 $crawler = $client->request('GET', '/config');
829
830 $form = $crawler->filter('button[id=config_save]')->form();
831
4094ea47 832 $data = [
ab2c93c7 833 'config[items_per_page]' => '1',
4094ea47 834 ];
ab2c93c7
NL
835
836 $client->submit($form, $data);
837
76cd8dbb 838 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
ab2c93c7 839
f808b016 840 $client->request('GET', 'unread/list' . $parameters);
ab2c93c7
NL
841
842 $this->assertContains($parameters, $client->getResponse()->getContent());
e1779760
NL
843
844 // reset pagination
845 $crawler = $client->request('GET', '/config');
846 $form = $crawler->filter('button[id=config_save]')->form();
4094ea47 847 $data = [
e1779760 848 'config[items_per_page]' => '12',
4094ea47 849 ];
e1779760 850 $client->submit($form, $data);
ab2c93c7 851 }
443cecd2
NL
852
853 public function testFilterOnDomainName()
854 {
855 $this->logInAs('admin');
7ab5eb95 856 $this->useTheme('baggy');
443cecd2
NL
857 $client = $this->getClient();
858
859 $crawler = $client->request('GET', '/unread/list');
860 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 861 $data = [
02d17813 862 'entry_filter[domainName]' => 'domain',
4094ea47 863 ];
443cecd2
NL
864
865 $crawler = $client->submit($form, $data);
02d17813 866 $this->assertCount(5, $crawler->filter('div[class=entry]'));
443cecd2 867
00fc2b44
KD
868 $crawler = $client->request('GET', '/unread/list');
869 $form = $crawler->filter('button[id=submit-filter]')->form();
870 $data = [
871 'entry_filter[domainName]' => 'dOmain',
872 ];
873
874 $crawler = $client->submit($form, $data);
875 $this->assertCount(5, $crawler->filter('div[class=entry]'));
876
443cecd2 877 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 878 $data = [
8ce32af6 879 'entry_filter[domainName]' => 'wallabag',
4094ea47 880 ];
443cecd2
NL
881
882 $crawler = $client->submit($form, $data);
883 $this->assertCount(0, $crawler->filter('div[class=entry]'));
884 }
e1779760
NL
885
886 public function testFilterOnStatus()
887 {
888 $this->logInAs('admin');
7ab5eb95 889 $this->useTheme('baggy');
e1779760
NL
890 $client = $this->getClient();
891
892 $crawler = $client->request('GET', '/unread/list');
893 $form = $crawler->filter('button[id=submit-filter]')->form();
894 $form['entry_filter[isArchived]']->tick();
895 $form['entry_filter[isStarred]']->untick();
896
897 $crawler = $client->submit($form);
159986c4 898 $this->assertCount(1, $crawler->filter('div[class=entry]'));
e1779760
NL
899
900 $form = $crawler->filter('button[id=submit-filter]')->form();
901 $form['entry_filter[isArchived]']->untick();
902 $form['entry_filter[isStarred]']->tick();
903
904 $crawler = $client->submit($form);
02d17813 905 $this->assertCount(1, $crawler->filter('div[class=entry]'));
e1779760 906 }
497e0cad 907
e8911f7c
JB
908 public function testFilterOnIsPublic()
909 {
910 $this->logInAs('admin');
911 $this->useTheme('baggy');
912 $client = $this->getClient();
913
914 $crawler = $client->request('GET', '/unread/list');
915 $form = $crawler->filter('button[id=submit-filter]')->form();
916 $form['entry_filter[isPublic]']->tick();
917
918 $crawler = $client->submit($form);
919 $this->assertCount(0, $crawler->filter('div[class=entry]'));
920 }
921
497e0cad
NL
922 public function testPreviewPictureFilter()
923 {
924 $this->logInAs('admin');
7ab5eb95 925 $this->useTheme('baggy');
497e0cad
NL
926 $client = $this->getClient();
927
928 $crawler = $client->request('GET', '/unread/list');
929 $form = $crawler->filter('button[id=submit-filter]')->form();
930 $form['entry_filter[previewPicture]']->tick();
931
932 $crawler = $client->submit($form);
7ab5eb95 933 $this->assertCount(1, $crawler->filter('div[class=entry]'));
497e0cad 934 }
d4ebe5c5
JB
935
936 public function testFilterOnLanguage()
937 {
938 $this->logInAs('admin');
7ab5eb95 939 $this->useTheme('baggy');
d4ebe5c5
JB
940 $client = $this->getClient();
941
7ab5eb95 942 $entry = new Entry($this->getLoggedInUser());
943 $entry->setUrl($this->url);
944 $entry->setLanguage('fr');
945 $this->getEntityManager()->persist($entry);
946 $this->getEntityManager()->flush();
947
d4ebe5c5
JB
948 $crawler = $client->request('GET', '/unread/list');
949 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 950 $data = [
159986c4 951 'entry_filter[language]' => 'fr',
4094ea47 952 ];
d4ebe5c5
JB
953
954 $crawler = $client->submit($form, $data);
e9c80c99 955 $this->assertCount(3, $crawler->filter('div[class=entry]'));
d4ebe5c5
JB
956
957 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 958 $data = [
d4ebe5c5 959 'entry_filter[language]' => 'en',
4094ea47 960 ];
d4ebe5c5
JB
961
962 $crawler = $client->submit($form, $data);
963 $this->assertCount(2, $crawler->filter('div[class=entry]'));
964 }
a7e2218e 965
21d82c3c 966 public function testShareEntryPublicly()
a7e2218e
NL
967 {
968 $this->logInAs('admin');
969 $client = $this->getClient();
970
7ab5eb95 971 // sharing is enabled
972 $client->getContainer()->get('craue_config')->set('share_public', 1);
973
974 $content = new Entry($this->getLoggedInUser());
975 $content->setUrl($this->url);
976 $this->getEntityManager()->persist($content);
977 $this->getEntityManager()->flush();
978 $this->getEntityManager()->clear();
a7e2218e 979
7239082a 980 // no uid
f808b016
JB
981 $client->request('GET', '/share/' . $content->getUid());
982 $this->assertSame(404, $client->getResponse()->getStatusCode());
eddda878 983
7239082a 984 // generating the uid
f808b016
JB
985 $client->request('GET', '/share/' . $content->getId());
986 $this->assertSame(302, $client->getResponse()->getStatusCode());
eddda878 987
7239082a 988 // follow link with uid
eddda878 989 $crawler = $client->followRedirect();
f808b016 990 $this->assertSame(200, $client->getResponse()->getStatusCode());
eddda878
JB
991 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
992 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
993 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
a7e2218e 994 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
21d82c3c
NL
995 $this->assertContains('og:title', $client->getResponse()->getContent());
996 $this->assertContains('og:type', $client->getResponse()->getContent());
997 $this->assertContains('og:url', $client->getResponse()->getContent());
d5c45d52 998 $this->assertContains('og:image', $client->getResponse()->getContent());
a7e2218e 999
eddda878
JB
1000 // sharing is now disabled
1001 $client->getContainer()->get('craue_config')->set('share_public', 0);
f808b016
JB
1002 $client->request('GET', '/share/' . $content->getUid());
1003 $this->assertSame(404, $client->getResponse()->getStatusCode());
eddda878 1004
f808b016 1005 $client->request('GET', '/view/' . $content->getId());
a7e2218e 1006 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
eddda878
JB
1007
1008 // removing the share
f808b016
JB
1009 $client->request('GET', '/share/delete/' . $content->getId());
1010 $this->assertSame(302, $client->getResponse()->getStatusCode());
eddda878
JB
1011
1012 // share is now disable
f808b016
JB
1013 $client->request('GET', '/share/' . $content->getUid());
1014 $this->assertSame(404, $client->getResponse()->getStatusCode());
a7e2218e 1015 }
d1495dd0
JB
1016
1017 public function testNewEntryWithDownloadImagesEnabled()
1018 {
be085c3d 1019 $this->downloadImagesEnabled = true;
d1495dd0
JB
1020 $this->logInAs('admin');
1021 $client = $this->getClient();
1022
26e2f074 1023 $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
d1495dd0
JB
1024 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1025
1026 $crawler = $client->request('GET', '/new');
1027
f808b016 1028 $this->assertSame(200, $client->getResponse()->getStatusCode());
d1495dd0
JB
1029
1030 $form = $crawler->filter('form[name=entry]')->form();
1031
1032 $data = [
1033 'entry[url]' => $url,
1034 ];
1035
1036 $client->submit($form, $data);
1037
f808b016 1038 $this->assertSame(302, $client->getResponse()->getStatusCode());
d1495dd0
JB
1039
1040 $em = $client->getContainer()
1041 ->get('doctrine.orm.entity_manager');
1042
1043 $entry = $em
1044 ->getRepository('WallabagCoreBundle:Entry')
1045 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1046
1047 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
f808b016 1048 $this->assertSame($url, $entry->getUrl());
d81bf605 1049 $this->assertContains('Judo', $entry->getTitle());
be085c3d 1050 // instead of checking for the filename (which might change) check that the image is now local
d81bf605 1051 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
d1495dd0 1052
e0597476
JB
1053 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1054 }
1055
1056 /**
1057 * @depends testNewEntryWithDownloadImagesEnabled
1058 */
1059 public function testRemoveEntryWithDownloadImagesEnabled()
1060 {
be085c3d 1061 $this->downloadImagesEnabled = true;
e0597476
JB
1062 $this->logInAs('admin');
1063 $client = $this->getClient();
1064
26e2f074 1065 $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
e0597476
JB
1066 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1067
7ab5eb95 1068 $crawler = $client->request('GET', '/new');
1069
f808b016 1070 $this->assertSame(200, $client->getResponse()->getStatusCode());
7ab5eb95 1071
1072 $form = $crawler->filter('form[name=entry]')->form();
1073
1074 $data = [
1075 'entry[url]' => $url,
1076 ];
1077
1078 $client->submit($form, $data);
1079
f808b016 1080 $this->assertSame(302, $client->getResponse()->getStatusCode());
7ab5eb95 1081
e0597476
JB
1082 $content = $client->getContainer()
1083 ->get('doctrine.orm.entity_manager')
1084 ->getRepository('WallabagCoreBundle:Entry')
1085 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1086
f808b016 1087 $client->request('GET', '/delete/' . $content->getId());
e0597476 1088
f808b016 1089 $this->assertSame(302, $client->getResponse()->getStatusCode());
d1495dd0
JB
1090
1091 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1092 }
65cd8a4a
NL
1093
1094 public function testRedirectToHomepage()
1095 {
1096 $this->logInAs('empty');
1097 $client = $this->getClient();
1098
65cd8a4a 1099 // Redirect to homepage
7ab5eb95 1100 $config = $this->getLoggedInUser()->getConfig();
65cd8a4a 1101 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
7ab5eb95 1102 $this->getEntityManager()->persist($config);
65cd8a4a 1103
7ab5eb95 1104 $entry = new Entry($this->getLoggedInUser());
1105 $entry->setUrl($this->url);
1106 $this->getEntityManager()->persist($entry);
65cd8a4a 1107
7ab5eb95 1108 $this->getEntityManager()->flush();
1109
f808b016
JB
1110 $client->request('GET', '/view/' . $entry->getId());
1111 $client->request('GET', '/archive/' . $entry->getId());
65cd8a4a 1112
f808b016
JB
1113 $this->assertSame(302, $client->getResponse()->getStatusCode());
1114 $this->assertSame('/', $client->getResponse()->headers->get('location'));
65cd8a4a
NL
1115 }
1116
1117 public function testRedirectToCurrentPage()
1118 {
1119 $this->logInAs('empty');
1120 $client = $this->getClient();
1121
65cd8a4a 1122 // Redirect to current page
7ab5eb95 1123 $config = $this->getLoggedInUser()->getConfig();
65cd8a4a 1124 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
7ab5eb95 1125 $this->getEntityManager()->persist($config);
65cd8a4a 1126
7ab5eb95 1127 $entry = new Entry($this->getLoggedInUser());
1128 $entry->setUrl($this->url);
1129 $this->getEntityManager()->persist($entry);
65cd8a4a 1130
7ab5eb95 1131 $this->getEntityManager()->flush();
1132
f808b016
JB
1133 $client->request('GET', '/view/' . $entry->getId());
1134 $client->request('GET', '/archive/' . $entry->getId());
65cd8a4a 1135
f808b016
JB
1136 $this->assertSame(302, $client->getResponse()->getStatusCode());
1137 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers->get('location'));
65cd8a4a 1138 }
10b35097
NL
1139
1140 public function testFilterOnHttpStatus()
1141 {
1142 $this->logInAs('admin');
7ab5eb95 1143 $this->useTheme('baggy');
10b35097
NL
1144 $client = $this->getClient();
1145
7ab5eb95 1146 $entry = new Entry($this->getLoggedInUser());
77854331 1147 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
7ab5eb95 1148 $entry->setHttpStatus(404);
1149 $this->getEntityManager()->persist($entry);
10b35097 1150
7ab5eb95 1151 $this->getEntityManager()->flush();
10b35097
NL
1152
1153 $crawler = $client->request('GET', '/all/list');
1154 $form = $crawler->filter('button[id=submit-filter]')->form();
1155
1156 $data = [
1157 'entry_filter[httpStatus]' => 404,
1158 ];
1159
1160 $crawler = $client->submit($form, $data);
1161
1162 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1163
7ab5eb95 1164 $entry = new Entry($this->getLoggedInUser());
1165 $entry->setUrl($this->url);
1166 $entry->setHttpStatus(200);
1167 $this->getEntityManager()->persist($entry);
10b35097 1168
7ab5eb95 1169 $entry = new Entry($this->getLoggedInUser());
1170 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1171 $entry->setHttpStatus(200);
1172 $this->getEntityManager()->persist($entry);
10b35097 1173
7ab5eb95 1174 $this->getEntityManager()->flush();
10b35097
NL
1175
1176 $crawler = $client->request('GET', '/all/list');
1177 $form = $crawler->filter('button[id=submit-filter]')->form();
1178
1179 $data = [
1180 'entry_filter[httpStatus]' => 200,
1181 ];
1182
1183 $crawler = $client->submit($form, $data);
1184
e9c80c99 1185 $this->assertCount(2, $crawler->filter('div[class=entry]'));
d215273c
NL
1186
1187 $crawler = $client->request('GET', '/all/list');
1188 $form = $crawler->filter('button[id=submit-filter]')->form();
1189
1190 $data = [
1191 'entry_filter[httpStatus]' => 1024,
1192 ];
1193
1194 $crawler = $client->submit($form, $data);
1195
e9c80c99 1196 $this->assertCount(8, $crawler->filter('div[class=entry]'));
10b35097 1197 }
32f455c1
NL
1198
1199 public function testSearch()
1200 {
1201 $this->logInAs('admin');
7ab5eb95 1202 $this->useTheme('baggy');
32f455c1
NL
1203 $client = $this->getClient();
1204
7ab5eb95 1205 $entry = new Entry($this->getLoggedInUser());
1206 $entry->setUrl($this->url);
1207 $entry->setTitle('test');
1208 $this->getEntityManager()->persist($entry);
1209 $this->getEntityManager()->flush();
1210
32f455c1
NL
1211 // Search on unread list
1212 $crawler = $client->request('GET', '/unread/list');
1213
1214 $form = $crawler->filter('form[name=search]')->form();
1215 $data = [
1216 'search_entry[term]' => 'title',
1217 ];
1218
1219 $crawler = $client->submit($form, $data);
1220
7ab5eb95 1221 $this->assertCount(4, $crawler->filter('div[class=entry]'));
32f455c1
NL
1222
1223 // Search on starred list
1224 $crawler = $client->request('GET', '/starred/list');
1225
7ab5eb95 1226 $entry = new Entry($this->getLoggedInUser());
1227 $entry->setUrl('http://localhost/foo/bar');
1228 $entry->setTitle('testeur');
1229 $entry->setStarred(true);
1230 $this->getEntityManager()->persist($entry);
1231 $this->getEntityManager()->flush();
1232
32f455c1
NL
1233 $form = $crawler->filter('form[name=search]')->form();
1234 $data = [
7ab5eb95 1235 'search_entry[term]' => 'testeur',
32f455c1
NL
1236 ];
1237
1238 $crawler = $client->submit($form, $data);
1239
1240 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1241
32f455c1
NL
1242 $crawler = $client->request('GET', '/archive/list');
1243
7ab5eb95 1244 // Added new article to test on archive list
1245 $entry = new Entry($this->getLoggedInUser());
1246 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1247 $entry->setTitle('Le manège');
1248 $entry->setArchived(true);
1249 $this->getEntityManager()->persist($entry);
1250 $this->getEntityManager()->flush();
1251
32f455c1
NL
1252 $form = $crawler->filter('form[name=search]')->form();
1253 $data = [
1254 'search_entry[term]' => 'manège',
1255 ];
1256
1257 $crawler = $client->submit($form, $data);
1258
1259 $this->assertCount(1, $crawler->filter('div[class=entry]'));
f808b016 1260 $client->request('GET', '/delete/' . $entry->getId());
32f455c1
NL
1261
1262 // test on list of all articles
1263 $crawler = $client->request('GET', '/all/list');
1264
1265 $form = $crawler->filter('form[name=search]')->form();
1266 $data = [
995c2044 1267 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
32f455c1
NL
1268 ];
1269
1270 $crawler = $client->submit($form, $data);
1271
1272 $this->assertCount(0, $crawler->filter('div[class=entry]'));
eac09b48
KD
1273
1274 // test url search on list of all articles
7ab5eb95 1275 $entry = new Entry($this->getLoggedInUser());
1276 $entry->setUrl('http://domain/qux');
1277 $entry->setTitle('Le manège');
1278 $entry->setArchived(true);
1279 $this->getEntityManager()->persist($entry);
1280 $this->getEntityManager()->flush();
1281
eac09b48
KD
1282 $crawler = $client->request('GET', '/all/list');
1283
1284 $form = $crawler->filter('form[name=search]')->form();
1285 $data = [
1286 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1287 ];
1288
1289 $crawler = $client->submit($form, $data);
1290
1291 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1292
1293 // same as previous test but for case-sensitivity
1294 $crawler = $client->request('GET', '/all/list');
1295
1296 $form = $crawler->filter('form[name=search]')->form();
1297 $data = [
1298 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1299 ];
1300
1301 $crawler = $client->submit($form, $data);
1302
1303 $this->assertCount(1, $crawler->filter('div[class=entry]'));
32f455c1 1304 }
42f3bb2c
JB
1305
1306 public function dataForLanguage()
1307 {
1308 return [
1309 'ru' => [
1310 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1311 'ru',
1312 ],
739a4024
FB
1313 'fr' => [
1314 'https://fr.wikipedia.org/wiki/Wallabag',
1315 'fr',
42f3bb2c
JB
1316 ],
1317 'de' => [
3be96dcb 1318 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
42f3bb2c
JB
1319 'de',
1320 ],
1321 'it' => [
1322 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1323 'it',
1324 ],
1325 'zh_CN' => [
1326 'http://www.hao123.com/shequ?__noscript__-=1',
1327 'zh_CN',
1328 ],
4408ebd4
JB
1329 'ru' => [
1330 'https://www.kp.ru/daily/26879.7/3921982/',
1331 'ru',
42f3bb2c
JB
1332 ],
1333 'pt_BR' => [
4408ebd4 1334 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
42f3bb2c
JB
1335 'pt_BR',
1336 ],
80e49ba7 1337 'fucked_list_of_languages' => [
42f3bb2c 1338 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
38520658 1339 null,
42f3bb2c 1340 ],
80e49ba7 1341 'es-ES' => [
77854331
JB
1342 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1343 'es',
80e49ba7 1344 ],
42f3bb2c
JB
1345 ];
1346 }
1347
1348 /**
1349 * @dataProvider dataForLanguage
1350 */
1351 public function testLanguageValidation($url, $expectedLanguage)
1352 {
1353 $this->logInAs('admin');
1354 $client = $this->getClient();
1355
1356 $crawler = $client->request('GET', '/new');
1357
f808b016 1358 $this->assertSame(200, $client->getResponse()->getStatusCode());
42f3bb2c
JB
1359
1360 $form = $crawler->filter('form[name=entry]')->form();
1361
1362 $data = [
1363 'entry[url]' => $url,
1364 ];
1365
1366 $client->submit($form, $data);
1367
f808b016 1368 $this->assertSame(302, $client->getResponse()->getStatusCode());
42f3bb2c
JB
1369
1370 $content = $client->getContainer()
1371 ->get('doctrine.orm.entity_manager')
1372 ->getRepository('WallabagCoreBundle:Entry')
1373 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1374
1375 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
f808b016
JB
1376 $this->assertSame($url, $content->getUrl());
1377 $this->assertSame($expectedLanguage, $content->getLanguage());
42f3bb2c 1378 }
9de9f1e5
JB
1379
1380 /**
1381 * This test will require an internet connection.
1382 */
1383 public function testRestrictedArticle()
1384 {
f645d371 1385 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
9de9f1e5
JB
1386 $this->logInAs('admin');
1387 $client = $this->getClient();
1388 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1389
1390 // enable restricted access
1391 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1392
1393 // create a new site_credential
1394 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1395 $credential = new SiteCredential($user);
1396 $credential->setHost('monde-diplomatique.fr');
bead8b42 1397 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
906424c1 1398 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
9de9f1e5
JB
1399
1400 $em->persist($credential);
1401 $em->flush();
1402
1403 $crawler = $client->request('GET', '/new');
1404
f808b016 1405 $this->assertSame(200, $client->getResponse()->getStatusCode());
9de9f1e5
JB
1406
1407 $form = $crawler->filter('form[name=entry]')->form();
1408
1409 $data = [
1410 'entry[url]' => $url,
1411 ];
1412
1413 $client->submit($form, $data);
1414
f808b016 1415 $this->assertSame(302, $client->getResponse()->getStatusCode());
9de9f1e5
JB
1416
1417 $crawler = $client->followRedirect();
1418
f808b016 1419 $this->assertSame(200, $client->getResponse()->getStatusCode());
9de9f1e5
JB
1420 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1421
1422 $content = $em
1423 ->getRepository('WallabagCoreBundle:Entry')
1424 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1425
1426 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1427 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1428
1429 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1430 }
300f293c
KD
1431
1432 public function testPostEntryWhenFetchFails()
1433 {
1434 $url = 'http://example.com/papers/email_tracking.pdf';
1435 $this->logInAs('admin');
1436 $client = $this->getClient();
1437
1438 $container = $client->getContainer();
1439 $contentProxy = $this->getMockBuilder(ContentProxy::class)
1440 ->disableOriginalConstructor()
1441 ->setMethods(['updateEntry'])
1442 ->getMock();
1443 $contentProxy->expects($this->any())
1444 ->method('updateEntry')
1445 ->willThrowException(new \Exception('Test Fetch content fails'));
1446
1447 $crawler = $client->request('GET', '/new');
1448
1449 $this->assertSame(200, $client->getResponse()->getStatusCode());
1450
1451 $form = $crawler->filter('form[name=entry]')->form();
1452
1453 $data = [
1454 'entry[url]' => $url,
1455 ];
1456
1457 /**
1458 * We generate a new client to be able to use Mock ContentProxy
1459 * Also we reinject the cookie from the previous client to keep the
1460 * session.
1461 */
1462 $cookie = $client->getCookieJar()->all();
1463 $client = $this->getNewClient();
1464 $client->getCookieJar()->set($cookie[0]);
1465 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1466 $client->submit($form, $data);
1467
1468 $this->assertSame(302, $client->getResponse()->getStatusCode());
1469
1470 $content = $client->getContainer()
1471 ->get('doctrine.orm.entity_manager')
1472 ->getRepository('WallabagCoreBundle:Entry')
1473 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1474
1475 $authors = $content->getPublishedBy();
1476 $this->assertSame('email_tracking.pdf', $content->getTitle());
1477 $this->assertSame('example.com', $content->getDomainName());
1478 }
e0a862b6
KD
1479
1480 public function testEntryDeleteTagLink()
1481 {
1482 $this->logInAs('admin');
1483 $client = $this->getClient();
1484
1485 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1486 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1487 $tag = $entry->getTags()[0];
1488
1489 $crawler = $client->request('GET', '/view/' . $entry->getId());
1490
1491 // As long as the deletion link of a tag is following
1492 // a link to the tag view, we take the second one to retrieve
1493 // the deletion link of the first tag
1494 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1495
1496 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1497 }
93fd4692 1498}