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