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