aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php582
1 files changed, 416 insertions, 166 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 7db4cf1f..7cf28bfe 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -5,11 +5,28 @@ namespace Tests\Wallabag\CoreBundle\Controller;
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config; 6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\SiteCredential;
8 9
9class EntryControllerTest extends WallabagCoreTestCase 10class EntryControllerTest extends WallabagCoreTestCase
10{ 11{
12 public $downloadImagesEnabled = false;
11 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 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';
12 14
15 /**
16 * @after
17 *
18 * Ensure download_images_enabled is disabled after each script
19 */
20 public function tearDownImagesEnabled()
21 {
22 if ($this->downloadImagesEnabled) {
23 $client = static::createClient();
24 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
25
26 $this->downloadImagesEnabled = false;
27 }
28 }
29
13 public function testLogin() 30 public function testLogin()
14 { 31 {
15 $client = $this->getClient(); 32 $client = $this->getClient();
@@ -55,6 +72,7 @@ class EntryControllerTest extends WallabagCoreTestCase
55 public function testGetNew() 72 public function testGetNew()
56 { 73 {
57 $this->logInAs('admin'); 74 $this->logInAs('admin');
75 $this->useTheme('baggy');
58 $client = $this->getClient(); 76 $client = $this->getClient();
59 77
60 $crawler = $client->request('GET', '/new'); 78 $crawler = $client->request('GET', '/new');
@@ -68,6 +86,7 @@ class EntryControllerTest extends WallabagCoreTestCase
68 public function testPostNewViaBookmarklet() 86 public function testPostNewViaBookmarklet()
69 { 87 {
70 $this->logInAs('admin'); 88 $this->logInAs('admin');
89 $this->useTheme('baggy');
71 $client = $this->getClient(); 90 $client = $this->getClient();
72 91
73 $crawler = $client->request('GET', '/'); 92 $crawler = $client->request('GET', '/');
@@ -135,14 +154,58 @@ class EntryControllerTest extends WallabagCoreTestCase
135 ->getRepository('WallabagCoreBundle:Entry') 154 ->getRepository('WallabagCoreBundle:Entry')
136 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 155 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
137 156
157 $author = $content->getPublishedBy();
158
138 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); 159 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
139 $this->assertEquals($this->url, $content->getUrl()); 160 $this->assertEquals($this->url, $content->getUrl());
140 $this->assertContains('Google', $content->getTitle()); 161 $this->assertContains('Google', $content->getTitle());
162 $this->assertEquals('fr', $content->getLanguage());
163 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
164 $this->assertEquals('Morgane Tual', $author[0]);
165 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
166 }
167
168 public function testPostWithMultipleAuthors()
169 {
170 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
171 $this->logInAs('admin');
172 $client = $this->getClient();
173
174 $crawler = $client->request('GET', '/new');
175
176 $this->assertEquals(200, $client->getResponse()->getStatusCode());
177
178 $form = $crawler->filter('form[name=entry]')->form();
179
180 $data = [
181 'entry[url]' => $url,
182 ];
183
184 $client->submit($form, $data);
185
186 $this->assertEquals(302, $client->getResponse()->getStatusCode());
187
188 $content = $client->getContainer()
189 ->get('doctrine.orm.entity_manager')
190 ->getRepository('WallabagCoreBundle:Entry')
191 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
192
193 $authors = $content->getPublishedBy();
194 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
195 $this->assertEquals('fr', $content->getLanguage());
196 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
197 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
141 } 198 }
142 199
143 public function testPostNewOkUrlExist() 200 public function testPostNewOkUrlExist()
144 { 201 {
145 $this->logInAs('admin'); 202 $this->logInAs('admin');
203
204 $entry = new Entry($this->getLoggedInUser());
205 $entry->setUrl($this->url);
206 $this->getEntityManager()->persist($entry);
207 $this->getEntityManager()->flush();
208
146 $client = $this->getClient(); 209 $client = $this->getClient();
147 210
148 $crawler = $client->request('GET', '/new'); 211 $crawler = $client->request('GET', '/new');
@@ -194,15 +257,6 @@ class EntryControllerTest extends WallabagCoreTestCase
194 257
195 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 258 $this->assertEquals(302, $client->getResponse()->getStatusCode());
196 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 259 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
197
198 $em = $client->getContainer()
199 ->get('doctrine.orm.entity_manager');
200 $entry = $em
201 ->getRepository('WallabagCoreBundle:Entry')
202 ->findOneByUrl(urldecode($url));
203
204 $em->remove($entry);
205 $em->flush();
206 } 260 }
207 261
208 /** 262 /**
@@ -235,8 +289,9 @@ class EntryControllerTest extends WallabagCoreTestCase
235 ->findOneByUrl($url); 289 ->findOneByUrl($url);
236 $tags = $entry->getTags(); 290 $tags = $entry->getTags();
237 291
238 $this->assertCount(1, $tags); 292 $this->assertCount(2, $tags);
239 $this->assertEquals('wallabag', $tags[0]->getLabel()); 293 $this->assertContains('wallabag', $tags);
294 $this->assertEquals('en', $entry->getLanguage());
240 295
241 $em->remove($entry); 296 $em->remove($entry);
242 $em->flush(); 297 $em->flush();
@@ -264,8 +319,8 @@ class EntryControllerTest extends WallabagCoreTestCase
264 319
265 $tags = $entry->getTags(); 320 $tags = $entry->getTags();
266 321
267 $this->assertCount(1, $tags); 322 $this->assertCount(2, $tags);
268 $this->assertEquals('wallabag', $tags[0]->getLabel()); 323 $this->assertContains('wallabag', $tags);
269 324
270 $em->remove($entry); 325 $em->remove($entry);
271 $em->flush(); 326 $em->flush();
@@ -312,29 +367,26 @@ class EntryControllerTest extends WallabagCoreTestCase
312 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); 367 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
313 } 368 }
314 369
315 /**
316 * @depends testPostNewOk
317 */
318 public function testView() 370 public function testView()
319 { 371 {
320 $this->logInAs('admin'); 372 $this->logInAs('admin');
321 $client = $this->getClient(); 373 $client = $this->getClient();
322 374
323 $content = $client->getContainer() 375 $entry = new Entry($this->getLoggedInUser());
324 ->get('doctrine.orm.entity_manager') 376 $entry->setUrl('http://example.com/foo');
325 ->getRepository('WallabagCoreBundle:Entry') 377 $entry->setTitle('title foo');
326 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 378 $entry->setContent('foo bar baz');
379 $this->getEntityManager()->persist($entry);
380 $this->getEntityManager()->flush();
327 381
328 $crawler = $client->request('GET', '/view/'.$content->getId()); 382 $crawler = $client->request('GET', '/view/'.$entry->getId());
329 383
330 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 384 $this->assertEquals(200, $client->getResponse()->getStatusCode());
331 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 385 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
332 $this->assertContains($content->getTitle(), $body[0]); 386 $this->assertContains($entry->getTitle(), $body[0]);
333 } 387 }
334 388
335 /** 389 /**
336 * @depends testPostNewOk
337 *
338 * This test will require an internet connection. 390 * This test will require an internet connection.
339 */ 391 */
340 public function testReload() 392 public function testReload()
@@ -342,63 +394,45 @@ class EntryControllerTest extends WallabagCoreTestCase
342 $this->logInAs('admin'); 394 $this->logInAs('admin');
343 $client = $this->getClient(); 395 $client = $this->getClient();
344 396
345 $em = $client->getContainer() 397 $entry = new Entry($this->getLoggedInUser());
346 ->get('doctrine.orm.entity_manager'); 398 $entry->setUrl($this->url);
347 399 $entry->setTitle('title foo');
348 $content = $em 400 $entry->setContent('');
349 ->getRepository('WallabagCoreBundle:Entry') 401 $this->getEntityManager()->persist($entry);
350 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 402 $this->getEntityManager()->flush();
403 $this->getEntityManager()->clear();
351 404
352 // empty content 405 $client->request('GET', '/reload/'.$entry->getId());
353 $content->setContent('');
354 $em->persist($content);
355 $em->flush();
356
357 $client->request('GET', '/reload/'.$content->getId());
358 406
359 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 407 $this->assertEquals(302, $client->getResponse()->getStatusCode());
360 408
361 $content = $em 409 $entry = $this->getEntityManager()
362 ->getRepository('WallabagCoreBundle:Entry') 410 ->getRepository('WallabagCoreBundle:Entry')
363 ->find($content->getId()); 411 ->find($entry->getId());
364 412
365 $this->assertNotEmpty($content->getContent()); 413 $this->assertNotEmpty($entry->getContent());
366 } 414 }
367 415
368 /**
369 * @depends testPostNewOk
370 */
371 public function testReloadWithFetchingFailed() 416 public function testReloadWithFetchingFailed()
372 { 417 {
373 $this->logInAs('admin'); 418 $this->logInAs('admin');
374 $client = $this->getClient(); 419 $client = $this->getClient();
375 420
376 $em = $client->getContainer() 421 $entry = new Entry($this->getLoggedInUser());
377 ->get('doctrine.orm.entity_manager'); 422 $entry->setUrl('http://0.0.0.0/failed.html');
378 423 $this->getEntityManager()->persist($entry);
379 $content = $em 424 $this->getEntityManager()->flush();
380 ->getRepository('WallabagCoreBundle:Entry')
381 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
382
383 // put a known failed url
384 $content->setUrl('http://0.0.0.0/failed.html');
385 $em->persist($content);
386 $em->flush();
387 425
388 $client->request('GET', '/reload/'.$content->getId()); 426 $client->request('GET', '/reload/'.$entry->getId());
389 427
390 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 428 $this->assertEquals(302, $client->getResponse()->getStatusCode());
391 429
392 // force EntityManager to clear previous entity 430 // force EntityManager to clear previous entity
393 // otherwise, retrieve the same entity will retrieve change from the previous request :0 431 // otherwise, retrieve the same entity will retrieve change from the previous request :0
394 $em->clear(); 432 $this->getEntityManager()->clear();
395 $newContent = $em 433 $newContent = $this->getEntityManager()
396 ->getRepository('WallabagCoreBundle:Entry') 434 ->getRepository('WallabagCoreBundle:Entry')
397 ->find($content->getId()); 435 ->find($entry->getId());
398
399 $newContent->setUrl($this->url);
400 $em->persist($newContent);
401 $em->flush();
402 436
403 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); 437 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
404 } 438 }
@@ -408,12 +442,12 @@ class EntryControllerTest extends WallabagCoreTestCase
408 $this->logInAs('admin'); 442 $this->logInAs('admin');
409 $client = $this->getClient(); 443 $client = $this->getClient();
410 444
411 $content = $client->getContainer() 445 $entry = new Entry($this->getLoggedInUser());
412 ->get('doctrine.orm.entity_manager') 446 $entry->setUrl($this->url);
413 ->getRepository('WallabagCoreBundle:Entry') 447 $this->getEntityManager()->persist($entry);
414 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 448 $this->getEntityManager()->flush();
415 449
416 $crawler = $client->request('GET', '/edit/'.$content->getId()); 450 $crawler = $client->request('GET', '/edit/'.$entry->getId());
417 451
418 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 452 $this->assertEquals(200, $client->getResponse()->getStatusCode());
419 453
@@ -426,12 +460,12 @@ class EntryControllerTest extends WallabagCoreTestCase
426 $this->logInAs('admin'); 460 $this->logInAs('admin');
427 $client = $this->getClient(); 461 $client = $this->getClient();
428 462
429 $content = $client->getContainer() 463 $entry = new Entry($this->getLoggedInUser());
430 ->get('doctrine.orm.entity_manager') 464 $entry->setUrl($this->url);
431 ->getRepository('WallabagCoreBundle:Entry') 465 $this->getEntityManager()->persist($entry);
432 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 466 $this->getEntityManager()->flush();
433 467
434 $crawler = $client->request('GET', '/edit/'.$content->getId()); 468 $crawler = $client->request('GET', '/edit/'.$entry->getId());
435 469
436 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 470 $this->assertEquals(200, $client->getResponse()->getStatusCode());
437 471
@@ -456,19 +490,20 @@ class EntryControllerTest extends WallabagCoreTestCase
456 $this->logInAs('admin'); 490 $this->logInAs('admin');
457 $client = $this->getClient(); 491 $client = $this->getClient();
458 492
459 $content = $client->getContainer() 493 $entry = new Entry($this->getLoggedInUser());
460 ->get('doctrine.orm.entity_manager') 494 $entry->setUrl($this->url);
461 ->getRepository('WallabagCoreBundle:Entry') 495 $this->getEntityManager()->persist($entry);
462 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 496 $this->getEntityManager()->flush();
497 $this->getEntityManager()->clear();
463 498
464 $client->request('GET', '/archive/'.$content->getId()); 499 $client->request('GET', '/archive/'.$entry->getId());
465 500
466 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 501 $this->assertEquals(302, $client->getResponse()->getStatusCode());
467 502
468 $res = $client->getContainer() 503 $res = $client->getContainer()
469 ->get('doctrine.orm.entity_manager') 504 ->get('doctrine.orm.entity_manager')
470 ->getRepository('WallabagCoreBundle:Entry') 505 ->getRepository('WallabagCoreBundle:Entry')
471 ->find($content->getId()); 506 ->find($entry->getId());
472 507
473 $this->assertEquals($res->isArchived(), true); 508 $this->assertEquals($res->isArchived(), true);
474 } 509 }
@@ -478,19 +513,20 @@ class EntryControllerTest extends WallabagCoreTestCase
478 $this->logInAs('admin'); 513 $this->logInAs('admin');
479 $client = $this->getClient(); 514 $client = $this->getClient();
480 515
481 $content = $client->getContainer() 516 $entry = new Entry($this->getLoggedInUser());
482 ->get('doctrine.orm.entity_manager') 517 $entry->setUrl($this->url);
483 ->getRepository('WallabagCoreBundle:Entry') 518 $this->getEntityManager()->persist($entry);
484 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 519 $this->getEntityManager()->flush();
520 $this->getEntityManager()->clear();
485 521
486 $client->request('GET', '/star/'.$content->getId()); 522 $client->request('GET', '/star/'.$entry->getId());
487 523
488 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 524 $this->assertEquals(302, $client->getResponse()->getStatusCode());
489 525
490 $res = $client->getContainer() 526 $res = $client->getContainer()
491 ->get('doctrine.orm.entity_manager') 527 ->get('doctrine.orm.entity_manager')
492 ->getRepository('WallabagCoreBundle:Entry') 528 ->getRepository('WallabagCoreBundle:Entry')
493 ->findOneById($content->getId()); 529 ->findOneById($entry->getId());
494 530
495 $this->assertEquals($res->isStarred(), true); 531 $this->assertEquals($res->isStarred(), true);
496 } 532 }
@@ -500,16 +536,16 @@ class EntryControllerTest extends WallabagCoreTestCase
500 $this->logInAs('admin'); 536 $this->logInAs('admin');
501 $client = $this->getClient(); 537 $client = $this->getClient();
502 538
503 $content = $client->getContainer() 539 $entry = new Entry($this->getLoggedInUser());
504 ->get('doctrine.orm.entity_manager') 540 $entry->setUrl($this->url);
505 ->getRepository('WallabagCoreBundle:Entry') 541 $this->getEntityManager()->persist($entry);
506 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 542 $this->getEntityManager()->flush();
507 543
508 $client->request('GET', '/delete/'.$content->getId()); 544 $client->request('GET', '/delete/'.$entry->getId());
509 545
510 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 546 $this->assertEquals(302, $client->getResponse()->getStatusCode());
511 547
512 $client->request('GET', '/delete/'.$content->getId()); 548 $client->request('GET', '/delete/'.$entry->getId());
513 549
514 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 550 $this->assertEquals(404, $client->getResponse()->getStatusCode());
515 } 551 }
@@ -575,7 +611,13 @@ class EntryControllerTest extends WallabagCoreTestCase
575 public function testFilterOnReadingTime() 611 public function testFilterOnReadingTime()
576 { 612 {
577 $this->logInAs('admin'); 613 $this->logInAs('admin');
614 $this->useTheme('baggy');
578 $client = $this->getClient(); 615 $client = $this->getClient();
616 $entry = new Entry($this->getLoggedInUser());
617 $entry->setUrl($this->url);
618 $entry->setReadingTime(22);
619 $this->getEntityManager()->persist($entry);
620 $this->getEntityManager()->flush();
579 621
580 $crawler = $client->request('GET', '/unread/list'); 622 $crawler = $client->request('GET', '/unread/list');
581 623
@@ -614,9 +656,20 @@ class EntryControllerTest extends WallabagCoreTestCase
614 public function testFilterOnReadingTimeOnlyUpper() 656 public function testFilterOnReadingTimeOnlyUpper()
615 { 657 {
616 $this->logInAs('admin'); 658 $this->logInAs('admin');
659 $this->useTheme('baggy');
617 $client = $this->getClient(); 660 $client = $this->getClient();
618 661
619 $crawler = $client->request('GET', '/unread/list'); 662 $crawler = $client->request('GET', '/all/list');
663 $this->assertCount(5, $crawler->filter('div[class=entry]'));
664
665 $entry = new Entry($this->getLoggedInUser());
666 $entry->setUrl($this->url);
667 $entry->setReadingTime(23);
668 $this->getEntityManager()->persist($entry);
669 $this->getEntityManager()->flush();
670
671 $crawler = $client->request('GET', '/all/list');
672 $this->assertCount(6, $crawler->filter('div[class=entry]'));
620 673
621 $form = $crawler->filter('button[id=submit-filter]')->form(); 674 $form = $crawler->filter('button[id=submit-filter]')->form();
622 675
@@ -626,12 +679,13 @@ class EntryControllerTest extends WallabagCoreTestCase
626 679
627 $crawler = $client->submit($form, $data); 680 $crawler = $client->submit($form, $data);
628 681
629 $this->assertCount(2, $crawler->filter('div[class=entry]')); 682 $this->assertCount(5, $crawler->filter('div[class=entry]'));
630 } 683 }
631 684
632 public function testFilterOnReadingTimeOnlyLower() 685 public function testFilterOnReadingTimeOnlyLower()
633 { 686 {
634 $this->logInAs('admin'); 687 $this->logInAs('admin');
688 $this->useTheme('baggy');
635 $client = $this->getClient(); 689 $client = $this->getClient();
636 690
637 $crawler = $client->request('GET', '/unread/list'); 691 $crawler = $client->request('GET', '/unread/list');
@@ -644,12 +698,22 @@ class EntryControllerTest extends WallabagCoreTestCase
644 698
645 $crawler = $client->submit($form, $data); 699 $crawler = $client->submit($form, $data);
646 700
647 $this->assertCount(4, $crawler->filter('div[class=entry]')); 701 $this->assertCount(0, $crawler->filter('div[class=entry]'));
702
703 $entry = new Entry($this->getLoggedInUser());
704 $entry->setUrl($this->url);
705 $entry->setReadingTime(23);
706 $this->getEntityManager()->persist($entry);
707 $this->getEntityManager()->flush();
708
709 $crawler = $client->submit($form, $data);
710 $this->assertCount(1, $crawler->filter('div[class=entry]'));
648 } 711 }
649 712
650 public function testFilterOnUnreadStatus() 713 public function testFilterOnUnreadStatus()
651 { 714 {
652 $this->logInAs('admin'); 715 $this->logInAs('admin');
716 $this->useTheme('baggy');
653 $client = $this->getClient(); 717 $client = $this->getClient();
654 718
655 $crawler = $client->request('GET', '/all/list'); 719 $crawler = $client->request('GET', '/all/list');
@@ -663,11 +727,22 @@ class EntryControllerTest extends WallabagCoreTestCase
663 $crawler = $client->submit($form, $data); 727 $crawler = $client->submit($form, $data);
664 728
665 $this->assertCount(4, $crawler->filter('div[class=entry]')); 729 $this->assertCount(4, $crawler->filter('div[class=entry]'));
730
731 $entry = new Entry($this->getLoggedInUser());
732 $entry->setUrl($this->url);
733 $entry->setArchived(false);
734 $this->getEntityManager()->persist($entry);
735 $this->getEntityManager()->flush();
736
737 $crawler = $client->submit($form, $data);
738
739 $this->assertCount(5, $crawler->filter('div[class=entry]'));
666 } 740 }
667 741
668 public function testFilterOnCreationDate() 742 public function testFilterOnCreationDate()
669 { 743 {
670 $this->logInAs('admin'); 744 $this->logInAs('admin');
745 $this->useTheme('baggy');
671 $client = $this->getClient(); 746 $client = $this->getClient();
672 747
673 $crawler = $client->request('GET', '/unread/list'); 748 $crawler = $client->request('GET', '/unread/list');
@@ -734,6 +809,7 @@ class EntryControllerTest extends WallabagCoreTestCase
734 public function testFilterOnDomainName() 809 public function testFilterOnDomainName()
735 { 810 {
736 $this->logInAs('admin'); 811 $this->logInAs('admin');
812 $this->useTheme('baggy');
737 $client = $this->getClient(); 813 $client = $this->getClient();
738 814
739 $crawler = $client->request('GET', '/unread/list'); 815 $crawler = $client->request('GET', '/unread/list');
@@ -766,6 +842,7 @@ class EntryControllerTest extends WallabagCoreTestCase
766 public function testFilterOnStatus() 842 public function testFilterOnStatus()
767 { 843 {
768 $this->logInAs('admin'); 844 $this->logInAs('admin');
845 $this->useTheme('baggy');
769 $client = $this->getClient(); 846 $client = $this->getClient();
770 847
771 $crawler = $client->request('GET', '/unread/list'); 848 $crawler = $client->request('GET', '/unread/list');
@@ -784,9 +861,24 @@ class EntryControllerTest extends WallabagCoreTestCase
784 $this->assertCount(1, $crawler->filter('div[class=entry]')); 861 $this->assertCount(1, $crawler->filter('div[class=entry]'));
785 } 862 }
786 863
864 public function testFilterOnIsPublic()
865 {
866 $this->logInAs('admin');
867 $this->useTheme('baggy');
868 $client = $this->getClient();
869
870 $crawler = $client->request('GET', '/unread/list');
871 $form = $crawler->filter('button[id=submit-filter]')->form();
872 $form['entry_filter[isPublic]']->tick();
873
874 $crawler = $client->submit($form);
875 $this->assertCount(0, $crawler->filter('div[class=entry]'));
876 }
877
787 public function testPreviewPictureFilter() 878 public function testPreviewPictureFilter()
788 { 879 {
789 $this->logInAs('admin'); 880 $this->logInAs('admin');
881 $this->useTheme('baggy');
790 $client = $this->getClient(); 882 $client = $this->getClient();
791 883
792 $crawler = $client->request('GET', '/unread/list'); 884 $crawler = $client->request('GET', '/unread/list');
@@ -800,8 +892,15 @@ class EntryControllerTest extends WallabagCoreTestCase
800 public function testFilterOnLanguage() 892 public function testFilterOnLanguage()
801 { 893 {
802 $this->logInAs('admin'); 894 $this->logInAs('admin');
895 $this->useTheme('baggy');
803 $client = $this->getClient(); 896 $client = $this->getClient();
804 897
898 $entry = new Entry($this->getLoggedInUser());
899 $entry->setUrl($this->url);
900 $entry->setLanguage('fr');
901 $this->getEntityManager()->persist($entry);
902 $this->getEntityManager()->flush();
903
805 $crawler = $client->request('GET', '/unread/list'); 904 $crawler = $client->request('GET', '/unread/list');
806 $form = $crawler->filter('button[id=submit-filter]')->form(); 905 $form = $crawler->filter('button[id=submit-filter]')->form();
807 $data = [ 906 $data = [
@@ -809,7 +908,7 @@ class EntryControllerTest extends WallabagCoreTestCase
809 ]; 908 ];
810 909
811 $crawler = $client->submit($form, $data); 910 $crawler = $client->submit($form, $data);
812 $this->assertCount(2, $crawler->filter('div[class=entry]')); 911 $this->assertCount(3, $crawler->filter('div[class=entry]'));
813 912
814 $form = $crawler->filter('button[id=submit-filter]')->form(); 913 $form = $crawler->filter('button[id=submit-filter]')->form();
815 $data = [ 914 $data = [
@@ -825,10 +924,14 @@ class EntryControllerTest extends WallabagCoreTestCase
825 $this->logInAs('admin'); 924 $this->logInAs('admin');
826 $client = $this->getClient(); 925 $client = $this->getClient();
827 926
828 $content = $client->getContainer() 927 // sharing is enabled
829 ->get('doctrine.orm.entity_manager') 928 $client->getContainer()->get('craue_config')->set('share_public', 1);
830 ->getRepository('WallabagCoreBundle:Entry') 929
831 ->findOneByUser($this->getLoggedInUserId()); 930 $content = new Entry($this->getLoggedInUser());
931 $content->setUrl($this->url);
932 $this->getEntityManager()->persist($content);
933 $this->getEntityManager()->flush();
934 $this->getEntityManager()->clear();
832 935
833 // no uid 936 // no uid
834 $client->request('GET', '/share/'.$content->getUid()); 937 $client->request('GET', '/share/'.$content->getUid());
@@ -869,6 +972,7 @@ class EntryControllerTest extends WallabagCoreTestCase
869 972
870 public function testNewEntryWithDownloadImagesEnabled() 973 public function testNewEntryWithDownloadImagesEnabled()
871 { 974 {
975 $this->downloadImagesEnabled = true;
872 $this->logInAs('admin'); 976 $this->logInAs('admin');
873 $client = $this->getClient(); 977 $client = $this->getClient();
874 978
@@ -899,7 +1003,8 @@ class EntryControllerTest extends WallabagCoreTestCase
899 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); 1003 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
900 $this->assertEquals($url, $entry->getUrl()); 1004 $this->assertEquals($url, $entry->getUrl());
901 $this->assertContains('Perpignan', $entry->getTitle()); 1005 $this->assertContains('Perpignan', $entry->getTitle());
902 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); 1006 // instead of checking for the filename (which might change) check that the image is now local
1007 $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent());
903 1008
904 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); 1009 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
905 } 1010 }
@@ -909,12 +1014,27 @@ class EntryControllerTest extends WallabagCoreTestCase
909 */ 1014 */
910 public function testRemoveEntryWithDownloadImagesEnabled() 1015 public function testRemoveEntryWithDownloadImagesEnabled()
911 { 1016 {
1017 $this->downloadImagesEnabled = true;
912 $this->logInAs('admin'); 1018 $this->logInAs('admin');
913 $client = $this->getClient(); 1019 $client = $this->getClient();
914 1020
915 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; 1021 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
916 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); 1022 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
917 1023
1024 $crawler = $client->request('GET', '/new');
1025
1026 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1027
1028 $form = $crawler->filter('form[name=entry]')->form();
1029
1030 $data = [
1031 'entry[url]' => $url,
1032 ];
1033
1034 $client->submit($form, $data);
1035
1036 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1037
918 $content = $client->getContainer() 1038 $content = $client->getContainer()
919 ->get('doctrine.orm.entity_manager') 1039 ->get('doctrine.orm.entity_manager')
920 ->getRepository('WallabagCoreBundle:Entry') 1040 ->getRepository('WallabagCoreBundle:Entry')
@@ -932,28 +1052,19 @@ class EntryControllerTest extends WallabagCoreTestCase
932 $this->logInAs('empty'); 1052 $this->logInAs('empty');
933 $client = $this->getClient(); 1053 $client = $this->getClient();
934 1054
935 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
936 $user = $em
937 ->getRepository('WallabagUserBundle:User')
938 ->find($this->getLoggedInUserId());
939
940 if (!$user) {
941 $this->markTestSkipped('No user found in db.');
942 }
943
944 // Redirect to homepage 1055 // Redirect to homepage
945 $config = $user->getConfig(); 1056 $config = $this->getLoggedInUser()->getConfig();
946 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); 1057 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
947 $em->persist($config); 1058 $this->getEntityManager()->persist($config);
948 $em->flush();
949 1059
950 $content = $client->getContainer() 1060 $entry = new Entry($this->getLoggedInUser());
951 ->get('doctrine.orm.entity_manager') 1061 $entry->setUrl($this->url);
952 ->getRepository('WallabagCoreBundle:Entry') 1062 $this->getEntityManager()->persist($entry);
953 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
954 1063
955 $client->request('GET', '/view/'.$content->getId()); 1064 $this->getEntityManager()->flush();
956 $client->request('GET', '/archive/'.$content->getId()); 1065
1066 $client->request('GET', '/view/'.$entry->getId());
1067 $client->request('GET', '/archive/'.$entry->getId());
957 1068
958 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 1069 $this->assertEquals(302, $client->getResponse()->getStatusCode());
959 $this->assertEquals('/', $client->getResponse()->headers->get('location')); 1070 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
@@ -964,46 +1075,36 @@ class EntryControllerTest extends WallabagCoreTestCase
964 $this->logInAs('empty'); 1075 $this->logInAs('empty');
965 $client = $this->getClient(); 1076 $client = $this->getClient();
966 1077
967 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
968 $user = $em
969 ->getRepository('WallabagUserBundle:User')
970 ->find($this->getLoggedInUserId());
971
972 if (!$user) {
973 $this->markTestSkipped('No user found in db.');
974 }
975
976 // Redirect to current page 1078 // Redirect to current page
977 $config = $user->getConfig(); 1079 $config = $this->getLoggedInUser()->getConfig();
978 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); 1080 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
979 $em->persist($config); 1081 $this->getEntityManager()->persist($config);
980 $em->flush();
981 1082
982 $content = $client->getContainer() 1083 $entry = new Entry($this->getLoggedInUser());
983 ->get('doctrine.orm.entity_manager') 1084 $entry->setUrl($this->url);
984 ->getRepository('WallabagCoreBundle:Entry') 1085 $this->getEntityManager()->persist($entry);
985 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
986 1086
987 $client->request('GET', '/view/'.$content->getId()); 1087 $this->getEntityManager()->flush();
988 $client->request('GET', '/archive/'.$content->getId()); 1088
1089 $client->request('GET', '/view/'.$entry->getId());
1090 $client->request('GET', '/archive/'.$entry->getId());
989 1091
990 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 1092 $this->assertEquals(302, $client->getResponse()->getStatusCode());
991 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); 1093 $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location'));
992 } 1094 }
993 1095
994 public function testFilterOnHttpStatus() 1096 public function testFilterOnHttpStatus()
995 { 1097 {
996 $this->logInAs('admin'); 1098 $this->logInAs('admin');
1099 $this->useTheme('baggy');
997 $client = $this->getClient(); 1100 $client = $this->getClient();
998 1101
999 $crawler = $client->request('GET', '/new'); 1102 $entry = new Entry($this->getLoggedInUser());
1000 $form = $crawler->filter('form[name=entry]')->form(); 1103 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1104 $entry->setHttpStatus(404);
1105 $this->getEntityManager()->persist($entry);
1001 1106
1002 $data = [ 1107 $this->getEntityManager()->flush();
1003 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
1004 ];
1005
1006 $client->submit($form, $data);
1007 1108
1008 $crawler = $client->request('GET', '/all/list'); 1109 $crawler = $client->request('GET', '/all/list');
1009 $form = $crawler->filter('button[id=submit-filter]')->form(); 1110 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1016,14 +1117,17 @@ class EntryControllerTest extends WallabagCoreTestCase
1016 1117
1017 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1118 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1018 1119
1019 $crawler = $client->request('GET', '/new'); 1120 $entry = new Entry($this->getLoggedInUser());
1020 $form = $crawler->filter('form[name=entry]')->form(); 1121 $entry->setUrl($this->url);
1122 $entry->setHttpStatus(200);
1123 $this->getEntityManager()->persist($entry);
1021 1124
1022 $data = [ 1125 $entry = new Entry($this->getLoggedInUser());
1023 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', 1126 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1024 ]; 1127 $entry->setHttpStatus(200);
1128 $this->getEntityManager()->persist($entry);
1025 1129
1026 $client->submit($form, $data); 1130 $this->getEntityManager()->flush();
1027 1131
1028 $crawler = $client->request('GET', '/all/list'); 1132 $crawler = $client->request('GET', '/all/list');
1029 $form = $crawler->filter('button[id=submit-filter]')->form(); 1133 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1034,7 +1138,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1034 1138
1035 $crawler = $client->submit($form, $data); 1139 $crawler = $client->submit($form, $data);
1036 1140
1037 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1141 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1038 1142
1039 $crawler = $client->request('GET', '/all/list'); 1143 $crawler = $client->request('GET', '/all/list');
1040 $form = $crawler->filter('button[id=submit-filter]')->form(); 1144 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1045,14 +1149,21 @@ class EntryControllerTest extends WallabagCoreTestCase
1045 1149
1046 $crawler = $client->submit($form, $data); 1150 $crawler = $client->submit($form, $data);
1047 1151
1048 $this->assertCount(7, $crawler->filter('div[class=entry]')); 1152 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1049 } 1153 }
1050 1154
1051 public function testSearch() 1155 public function testSearch()
1052 { 1156 {
1053 $this->logInAs('admin'); 1157 $this->logInAs('admin');
1158 $this->useTheme('baggy');
1054 $client = $this->getClient(); 1159 $client = $this->getClient();
1055 1160
1161 $entry = new Entry($this->getLoggedInUser());
1162 $entry->setUrl($this->url);
1163 $entry->setTitle('test');
1164 $this->getEntityManager()->persist($entry);
1165 $this->getEntityManager()->flush();
1166
1056 // Search on unread list 1167 // Search on unread list
1057 $crawler = $client->request('GET', '/unread/list'); 1168 $crawler = $client->request('GET', '/unread/list');
1058 1169
@@ -1063,35 +1174,37 @@ class EntryControllerTest extends WallabagCoreTestCase
1063 1174
1064 $crawler = $client->submit($form, $data); 1175 $crawler = $client->submit($form, $data);
1065 1176
1066 $this->assertCount(5, $crawler->filter('div[class=entry]')); 1177 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1067 1178
1068 // Search on starred list 1179 // Search on starred list
1069 $crawler = $client->request('GET', '/starred/list'); 1180 $crawler = $client->request('GET', '/starred/list');
1070 1181
1182 $entry = new Entry($this->getLoggedInUser());
1183 $entry->setUrl('http://localhost/foo/bar');
1184 $entry->setTitle('testeur');
1185 $entry->setStarred(true);
1186 $this->getEntityManager()->persist($entry);
1187 $this->getEntityManager()->flush();
1188
1071 $form = $crawler->filter('form[name=search]')->form(); 1189 $form = $crawler->filter('form[name=search]')->form();
1072 $data = [ 1190 $data = [
1073 'search_entry[term]' => 'title', 1191 'search_entry[term]' => 'testeur',
1074 ]; 1192 ];
1075 1193
1076 $crawler = $client->submit($form, $data); 1194 $crawler = $client->submit($form, $data);
1077 1195
1078 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1196 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1079 1197
1080 // Added new article to test on archive list
1081 $crawler = $client->request('GET', '/new');
1082 $form = $crawler->filter('form[name=entry]')->form();
1083 $data = [
1084 'entry[url]' => $this->url,
1085 ];
1086 $client->submit($form, $data);
1087 $content = $client->getContainer()
1088 ->get('doctrine.orm.entity_manager')
1089 ->getRepository('WallabagCoreBundle:Entry')
1090 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1091 $client->request('GET', '/archive/'.$content->getId());
1092
1093 $crawler = $client->request('GET', '/archive/list'); 1198 $crawler = $client->request('GET', '/archive/list');
1094 1199
1200 // Added new article to test on archive list
1201 $entry = new Entry($this->getLoggedInUser());
1202 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1203 $entry->setTitle('Le manège');
1204 $entry->setArchived(true);
1205 $this->getEntityManager()->persist($entry);
1206 $this->getEntityManager()->flush();
1207
1095 $form = $crawler->filter('form[name=search]')->form(); 1208 $form = $crawler->filter('form[name=search]')->form();
1096 $data = [ 1209 $data = [
1097 'search_entry[term]' => 'manège', 1210 'search_entry[term]' => 'manège',
@@ -1100,7 +1213,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1100 $crawler = $client->submit($form, $data); 1213 $crawler = $client->submit($form, $data);
1101 1214
1102 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1215 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1103 $client->request('GET', '/delete/'.$content->getId()); 1216 $client->request('GET', '/delete/'.$entry->getId());
1104 1217
1105 // test on list of all articles 1218 // test on list of all articles
1106 $crawler = $client->request('GET', '/all/list'); 1219 $crawler = $client->request('GET', '/all/list');
@@ -1115,6 +1228,13 @@ class EntryControllerTest extends WallabagCoreTestCase
1115 $this->assertCount(0, $crawler->filter('div[class=entry]')); 1228 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1116 1229
1117 // test url search on list of all articles 1230 // test url search on list of all articles
1231 $entry = new Entry($this->getLoggedInUser());
1232 $entry->setUrl('http://domain/qux');
1233 $entry->setTitle('Le manège');
1234 $entry->setArchived(true);
1235 $this->getEntityManager()->persist($entry);
1236 $this->getEntityManager()->flush();
1237
1118 $crawler = $client->request('GET', '/all/list'); 1238 $crawler = $client->request('GET', '/all/list');
1119 1239
1120 $form = $crawler->filter('form[name=search]')->form(); 1240 $form = $crawler->filter('form[name=search]')->form();
@@ -1138,4 +1258,134 @@ class EntryControllerTest extends WallabagCoreTestCase
1138 1258
1139 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1259 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1140 } 1260 }
1261
1262 public function dataForLanguage()
1263 {
1264 return [
1265 'ru' => [
1266 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1267 'ru',
1268 ],
1269 'fr-FR' => [
1270 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1271 'fr_FR',
1272 ],
1273 'de' => [
1274 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1275 'de',
1276 ],
1277 'it' => [
1278 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1279 'it',
1280 ],
1281 'zh_CN' => [
1282 'http://www.hao123.com/shequ?__noscript__-=1',
1283 'zh_CN',
1284 ],
1285 'de_AT' => [
1286 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1287 'de_AT',
1288 ],
1289 'ru_RU' => [
1290 'http://netler.ru/ikt/windows-error-reporting.htm',
1291 'ru_RU',
1292 ],
1293 'pt_BR' => [
1294 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1295 'pt_BR',
1296 ],
1297 'fucked_list_of_languages' => [
1298 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1299 '',
1300 ],
1301 'es-ES' => [
1302 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google',
1303 'es_ES',
1304 ],
1305 ];
1306 }
1307
1308 /**
1309 * @dataProvider dataForLanguage
1310 */
1311 public function testLanguageValidation($url, $expectedLanguage)
1312 {
1313 $this->logInAs('admin');
1314 $client = $this->getClient();
1315
1316 $crawler = $client->request('GET', '/new');
1317
1318 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1319
1320 $form = $crawler->filter('form[name=entry]')->form();
1321
1322 $data = [
1323 'entry[url]' => $url,
1324 ];
1325
1326 $client->submit($form, $data);
1327
1328 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1329
1330 $content = $client->getContainer()
1331 ->get('doctrine.orm.entity_manager')
1332 ->getRepository('WallabagCoreBundle:Entry')
1333 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1334
1335 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1336 $this->assertEquals($url, $content->getUrl());
1337 $this->assertEquals($expectedLanguage, $content->getLanguage());
1338 }
1339
1340 /**
1341 * This test will require an internet connection.
1342 */
1343 public function testRestrictedArticle()
1344 {
1345 $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1346 $this->logInAs('admin');
1347 $client = $this->getClient();
1348 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1349
1350 // enable restricted access
1351 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1352
1353 // create a new site_credential
1354 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1355 $credential = new SiteCredential($user);
1356 $credential->setHost('monde-diplomatique.fr');
1357 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1358 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1359
1360 $em->persist($credential);
1361 $em->flush();
1362
1363 $crawler = $client->request('GET', '/new');
1364
1365 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1366
1367 $form = $crawler->filter('form[name=entry]')->form();
1368
1369 $data = [
1370 'entry[url]' => $url,
1371 ];
1372
1373 $client->submit($form, $data);
1374
1375 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1376
1377 $crawler = $client->followRedirect();
1378
1379 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1380 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1381
1382 $content = $em
1383 ->getRepository('WallabagCoreBundle:Entry')
1384 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1385
1386 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1387 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1388
1389 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1390 }
1141} 1391}