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