]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Convert - to _ in language
[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
NL
862
863 public function testPreviewPictureFilter()
864 {
865 $this->logInAs('admin');
7ab5eb95 866 $this->useTheme('baggy');
497e0cad
NL
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[previewPicture]']->tick();
872
873 $crawler = $client->submit($form);
7ab5eb95 874 $this->assertCount(1, $crawler->filter('div[class=entry]'));
497e0cad 875 }
d4ebe5c5
JB
876
877 public function testFilterOnLanguage()
878 {
879 $this->logInAs('admin');
7ab5eb95 880 $this->useTheme('baggy');
d4ebe5c5
JB
881 $client = $this->getClient();
882
7ab5eb95 883 $entry = new Entry($this->getLoggedInUser());
884 $entry->setUrl($this->url);
885 $entry->setLanguage('fr');
886 $this->getEntityManager()->persist($entry);
887 $this->getEntityManager()->flush();
888
d4ebe5c5
JB
889 $crawler = $client->request('GET', '/unread/list');
890 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 891 $data = [
159986c4 892 'entry_filter[language]' => 'fr',
4094ea47 893 ];
d4ebe5c5
JB
894
895 $crawler = $client->submit($form, $data);
e9c80c99 896 $this->assertCount(3, $crawler->filter('div[class=entry]'));
d4ebe5c5
JB
897
898 $form = $crawler->filter('button[id=submit-filter]')->form();
4094ea47 899 $data = [
d4ebe5c5 900 'entry_filter[language]' => 'en',
4094ea47 901 ];
d4ebe5c5
JB
902
903 $crawler = $client->submit($form, $data);
904 $this->assertCount(2, $crawler->filter('div[class=entry]'));
905 }
a7e2218e 906
21d82c3c 907 public function testShareEntryPublicly()
a7e2218e
NL
908 {
909 $this->logInAs('admin');
910 $client = $this->getClient();
911
7ab5eb95 912 // sharing is enabled
913 $client->getContainer()->get('craue_config')->set('share_public', 1);
914
915 $content = new Entry($this->getLoggedInUser());
916 $content->setUrl($this->url);
917 $this->getEntityManager()->persist($content);
918 $this->getEntityManager()->flush();
919 $this->getEntityManager()->clear();
a7e2218e 920
7239082a
NL
921 // no uid
922 $client->request('GET', '/share/'.$content->getUid());
eddda878
JB
923 $this->assertEquals(404, $client->getResponse()->getStatusCode());
924
7239082a 925 // generating the uid
eddda878
JB
926 $client->request('GET', '/share/'.$content->getId());
927 $this->assertEquals(302, $client->getResponse()->getStatusCode());
928
7239082a 929 // follow link with uid
eddda878
JB
930 $crawler = $client->followRedirect();
931 $this->assertEquals(200, $client->getResponse()->getStatusCode());
932 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
933 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
934 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
a7e2218e 935 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
21d82c3c
NL
936 $this->assertContains('og:title', $client->getResponse()->getContent());
937 $this->assertContains('og:type', $client->getResponse()->getContent());
938 $this->assertContains('og:url', $client->getResponse()->getContent());
d5c45d52 939 $this->assertContains('og:image', $client->getResponse()->getContent());
a7e2218e 940
eddda878
JB
941 // sharing is now disabled
942 $client->getContainer()->get('craue_config')->set('share_public', 0);
7239082a 943 $client->request('GET', '/share/'.$content->getUid());
eddda878
JB
944 $this->assertEquals(404, $client->getResponse()->getStatusCode());
945
a7e2218e
NL
946 $client->request('GET', '/view/'.$content->getId());
947 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
eddda878
JB
948
949 // removing the share
950 $client->request('GET', '/share/delete/'.$content->getId());
951 $this->assertEquals(302, $client->getResponse()->getStatusCode());
952
953 // share is now disable
7239082a 954 $client->request('GET', '/share/'.$content->getUid());
eddda878 955 $this->assertEquals(404, $client->getResponse()->getStatusCode());
a7e2218e 956 }
d1495dd0
JB
957
958 public function testNewEntryWithDownloadImagesEnabled()
959 {
be085c3d 960 $this->downloadImagesEnabled = true;
d1495dd0
JB
961 $this->logInAs('admin');
962 $client = $this->getClient();
963
964 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
965 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
966
967 $crawler = $client->request('GET', '/new');
968
969 $this->assertEquals(200, $client->getResponse()->getStatusCode());
970
971 $form = $crawler->filter('form[name=entry]')->form();
972
973 $data = [
974 'entry[url]' => $url,
975 ];
976
977 $client->submit($form, $data);
978
979 $this->assertEquals(302, $client->getResponse()->getStatusCode());
980
981 $em = $client->getContainer()
982 ->get('doctrine.orm.entity_manager');
983
984 $entry = $em
985 ->getRepository('WallabagCoreBundle:Entry')
986 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
987
988 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
989 $this->assertEquals($url, $entry->getUrl());
990 $this->assertContains('Perpignan', $entry->getTitle());
be085c3d
JB
991 // instead of checking for the filename (which might change) check that the image is now local
992 $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent());
42f3bb2c 993 $this->assertEquals('fr', $entry->getLanguage());
d1495dd0 994
e0597476
JB
995 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
996 }
997
998 /**
999 * @depends testNewEntryWithDownloadImagesEnabled
1000 */
1001 public function testRemoveEntryWithDownloadImagesEnabled()
1002 {
be085c3d 1003 $this->downloadImagesEnabled = true;
e0597476
JB
1004 $this->logInAs('admin');
1005 $client = $this->getClient();
1006
1007 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
1008 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1009
7ab5eb95 1010 $crawler = $client->request('GET', '/new');
1011
1012 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1013
1014 $form = $crawler->filter('form[name=entry]')->form();
1015
1016 $data = [
1017 'entry[url]' => $url,
1018 ];
1019
1020 $client->submit($form, $data);
1021
1022 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1023
e0597476
JB
1024 $content = $client->getContainer()
1025 ->get('doctrine.orm.entity_manager')
1026 ->getRepository('WallabagCoreBundle:Entry')
1027 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1028
1029 $client->request('GET', '/delete/'.$content->getId());
1030
1031 $this->assertEquals(302, $client->getResponse()->getStatusCode());
d1495dd0
JB
1032
1033 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1034 }
65cd8a4a
NL
1035
1036 public function testRedirectToHomepage()
1037 {
1038 $this->logInAs('empty');
1039 $client = $this->getClient();
1040
65cd8a4a 1041 // Redirect to homepage
7ab5eb95 1042 $config = $this->getLoggedInUser()->getConfig();
65cd8a4a 1043 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
7ab5eb95 1044 $this->getEntityManager()->persist($config);
65cd8a4a 1045
7ab5eb95 1046 $entry = new Entry($this->getLoggedInUser());
1047 $entry->setUrl($this->url);
1048 $this->getEntityManager()->persist($entry);
65cd8a4a 1049
7ab5eb95 1050 $this->getEntityManager()->flush();
1051
1052 $client->request('GET', '/view/'.$entry->getId());
1053 $client->request('GET', '/archive/'.$entry->getId());
65cd8a4a
NL
1054
1055 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1056 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
1057 }
1058
1059 public function testRedirectToCurrentPage()
1060 {
1061 $this->logInAs('empty');
1062 $client = $this->getClient();
1063
65cd8a4a 1064 // Redirect to current page
7ab5eb95 1065 $config = $this->getLoggedInUser()->getConfig();
65cd8a4a 1066 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
7ab5eb95 1067 $this->getEntityManager()->persist($config);
65cd8a4a 1068
7ab5eb95 1069 $entry = new Entry($this->getLoggedInUser());
1070 $entry->setUrl($this->url);
1071 $this->getEntityManager()->persist($entry);
65cd8a4a 1072
7ab5eb95 1073 $this->getEntityManager()->flush();
1074
1075 $client->request('GET', '/view/'.$entry->getId());
1076 $client->request('GET', '/archive/'.$entry->getId());
65cd8a4a
NL
1077
1078 $this->assertEquals(302, $client->getResponse()->getStatusCode());
7ab5eb95 1079 $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location'));
65cd8a4a 1080 }
10b35097
NL
1081
1082 public function testFilterOnHttpStatus()
1083 {
1084 $this->logInAs('admin');
7ab5eb95 1085 $this->useTheme('baggy');
10b35097
NL
1086 $client = $this->getClient();
1087
7ab5eb95 1088 $entry = new Entry($this->getLoggedInUser());
1089 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1090 $entry->setHttpStatus(404);
1091 $this->getEntityManager()->persist($entry);
10b35097 1092
7ab5eb95 1093 $this->getEntityManager()->flush();
10b35097
NL
1094
1095 $crawler = $client->request('GET', '/all/list');
1096 $form = $crawler->filter('button[id=submit-filter]')->form();
1097
1098 $data = [
1099 'entry_filter[httpStatus]' => 404,
1100 ];
1101
1102 $crawler = $client->submit($form, $data);
1103
1104 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1105
7ab5eb95 1106 $entry = new Entry($this->getLoggedInUser());
1107 $entry->setUrl($this->url);
1108 $entry->setHttpStatus(200);
1109 $this->getEntityManager()->persist($entry);
10b35097 1110
7ab5eb95 1111 $entry = new Entry($this->getLoggedInUser());
1112 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1113 $entry->setHttpStatus(200);
1114 $this->getEntityManager()->persist($entry);
10b35097 1115
7ab5eb95 1116 $this->getEntityManager()->flush();
10b35097
NL
1117
1118 $crawler = $client->request('GET', '/all/list');
1119 $form = $crawler->filter('button[id=submit-filter]')->form();
1120
1121 $data = [
1122 'entry_filter[httpStatus]' => 200,
1123 ];
1124
1125 $crawler = $client->submit($form, $data);
1126
e9c80c99 1127 $this->assertCount(2, $crawler->filter('div[class=entry]'));
d215273c
NL
1128
1129 $crawler = $client->request('GET', '/all/list');
1130 $form = $crawler->filter('button[id=submit-filter]')->form();
1131
1132 $data = [
1133 'entry_filter[httpStatus]' => 1024,
1134 ];
1135
1136 $crawler = $client->submit($form, $data);
1137
e9c80c99 1138 $this->assertCount(8, $crawler->filter('div[class=entry]'));
10b35097 1139 }
32f455c1
NL
1140
1141 public function testSearch()
1142 {
1143 $this->logInAs('admin');
7ab5eb95 1144 $this->useTheme('baggy');
32f455c1
NL
1145 $client = $this->getClient();
1146
7ab5eb95 1147 $entry = new Entry($this->getLoggedInUser());
1148 $entry->setUrl($this->url);
1149 $entry->setTitle('test');
1150 $this->getEntityManager()->persist($entry);
1151 $this->getEntityManager()->flush();
1152
32f455c1
NL
1153 // Search on unread list
1154 $crawler = $client->request('GET', '/unread/list');
1155
1156 $form = $crawler->filter('form[name=search]')->form();
1157 $data = [
1158 'search_entry[term]' => 'title',
1159 ];
1160
1161 $crawler = $client->submit($form, $data);
1162
7ab5eb95 1163 $this->assertCount(4, $crawler->filter('div[class=entry]'));
32f455c1
NL
1164
1165 // Search on starred list
1166 $crawler = $client->request('GET', '/starred/list');
1167
7ab5eb95 1168 $entry = new Entry($this->getLoggedInUser());
1169 $entry->setUrl('http://localhost/foo/bar');
1170 $entry->setTitle('testeur');
1171 $entry->setStarred(true);
1172 $this->getEntityManager()->persist($entry);
1173 $this->getEntityManager()->flush();
1174
32f455c1
NL
1175 $form = $crawler->filter('form[name=search]')->form();
1176 $data = [
7ab5eb95 1177 'search_entry[term]' => 'testeur',
32f455c1
NL
1178 ];
1179
1180 $crawler = $client->submit($form, $data);
1181
1182 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1183
32f455c1
NL
1184 $crawler = $client->request('GET', '/archive/list');
1185
7ab5eb95 1186 // Added new article to test on archive list
1187 $entry = new Entry($this->getLoggedInUser());
1188 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1189 $entry->setTitle('Le manège');
1190 $entry->setArchived(true);
1191 $this->getEntityManager()->persist($entry);
1192 $this->getEntityManager()->flush();
1193
32f455c1
NL
1194 $form = $crawler->filter('form[name=search]')->form();
1195 $data = [
1196 'search_entry[term]' => 'manège',
1197 ];
1198
1199 $crawler = $client->submit($form, $data);
1200
1201 $this->assertCount(1, $crawler->filter('div[class=entry]'));
7ab5eb95 1202 $client->request('GET', '/delete/'.$entry->getId());
32f455c1
NL
1203
1204 // test on list of all articles
1205 $crawler = $client->request('GET', '/all/list');
1206
1207 $form = $crawler->filter('form[name=search]')->form();
1208 $data = [
995c2044 1209 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
32f455c1
NL
1210 ];
1211
1212 $crawler = $client->submit($form, $data);
1213
1214 $this->assertCount(0, $crawler->filter('div[class=entry]'));
eac09b48
KD
1215
1216 // test url search on list of all articles
7ab5eb95 1217 $entry = new Entry($this->getLoggedInUser());
1218 $entry->setUrl('http://domain/qux');
1219 $entry->setTitle('Le manège');
1220 $entry->setArchived(true);
1221 $this->getEntityManager()->persist($entry);
1222 $this->getEntityManager()->flush();
1223
eac09b48
KD
1224 $crawler = $client->request('GET', '/all/list');
1225
1226 $form = $crawler->filter('form[name=search]')->form();
1227 $data = [
1228 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1229 ];
1230
1231 $crawler = $client->submit($form, $data);
1232
1233 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1234
1235 // same as previous test but for case-sensitivity
1236 $crawler = $client->request('GET', '/all/list');
1237
1238 $form = $crawler->filter('form[name=search]')->form();
1239 $data = [
1240 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1241 ];
1242
1243 $crawler = $client->submit($form, $data);
1244
1245 $this->assertCount(1, $crawler->filter('div[class=entry]'));
32f455c1 1246 }
42f3bb2c
JB
1247
1248 public function dataForLanguage()
1249 {
1250 return [
1251 'ru' => [
1252 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1253 'ru',
1254 ],
80e49ba7
JB
1255 'fr-FR' => [
1256 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1257 'fr_FR',
42f3bb2c
JB
1258 ],
1259 'de' => [
1260 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1261 'de',
1262 ],
1263 'it' => [
1264 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1265 'it',
1266 ],
1267 'zh_CN' => [
1268 'http://www.hao123.com/shequ?__noscript__-=1',
1269 'zh_CN',
1270 ],
1271 'de_AT' => [
1272 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1273 'de_AT',
1274 ],
1275 'ru_RU' => [
1276 'http://netler.ru/ikt/windows-error-reporting.htm',
1277 'ru_RU',
1278 ],
1279 'pt_BR' => [
1280 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1281 'pt_BR',
1282 ],
80e49ba7 1283 'fucked_list_of_languages' => [
42f3bb2c
JB
1284 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1285 '',
1286 ],
80e49ba7
JB
1287 'es-ES' => [
1288 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google',
1289 'es_ES',
1290 ],
42f3bb2c
JB
1291 ];
1292 }
1293
1294 /**
1295 * @dataProvider dataForLanguage
1296 */
1297 public function testLanguageValidation($url, $expectedLanguage)
1298 {
1299 $this->logInAs('admin');
1300 $client = $this->getClient();
1301
1302 $crawler = $client->request('GET', '/new');
1303
1304 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1305
1306 $form = $crawler->filter('form[name=entry]')->form();
1307
1308 $data = [
1309 'entry[url]' => $url,
1310 ];
1311
1312 $client->submit($form, $data);
1313
1314 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1315
1316 $content = $client->getContainer()
1317 ->get('doctrine.orm.entity_manager')
1318 ->getRepository('WallabagCoreBundle:Entry')
1319 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1320
1321 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1322 $this->assertEquals($url, $content->getUrl());
1323 $this->assertEquals($expectedLanguage, $content->getLanguage());
1324 }
93fd4692 1325}