aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php314
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php270
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php4
-rw-r--r--tests/Wallabag/CoreBundle/Controller/RssControllerTest.php53
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php2
6 files changed, 628 insertions, 17 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index d4fbe2d4..beb0598a 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -1,8 +1,13 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\UserBundle\Entity\User;
8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\AnnotationBundle\Entity\Annotation;
6 11
7class ConfigControllerTest extends WallabagCoreTestCase 12class ConfigControllerTest extends WallabagCoreTestCase
8{ 13{
@@ -46,6 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
46 'config[theme]' => 'baggy', 51 'config[theme]' => 'baggy',
47 'config[items_per_page]' => '30', 52 'config[items_per_page]' => '30',
48 'config[reading_speed]' => '0.5', 53 'config[reading_speed]' => '0.5',
54 'config[action_mark_as_read]' => '0',
49 'config[language]' => 'en', 55 'config[language]' => 'en',
50 ]; 56 ];
51 57
@@ -407,7 +413,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
407 413
408 $crawler = $client->request('GET', '/config'); 414 $crawler = $client->request('GET', '/config');
409 415
410 $this->assertTrue($client->getResponse()->isSuccessful()); 416 $this->assertEquals(200, $client->getResponse()->getStatusCode());
411 417
412 $form = $crawler->filter('button[id=tagging_rule_save]')->form(); 418 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
413 419
@@ -494,7 +500,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
494 500
495 $crawler = $client->request('GET', '/config'); 501 $crawler = $client->request('GET', '/config');
496 502
497 $this->assertTrue($client->getResponse()->isSuccessful()); 503 $this->assertEquals(200, $client->getResponse()->getStatusCode());
498 504
499 $form = $crawler->filter('button[id=tagging_rule_save]')->form(); 505 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
500 506
@@ -509,6 +515,29 @@ class ConfigControllerTest extends WallabagCoreTestCase
509 } 515 }
510 } 516 }
511 517
518 public function testTaggingRuleTooLong()
519 {
520 $this->logInAs('admin');
521 $client = $this->getClient();
522
523 $crawler = $client->request('GET', '/config');
524
525 $this->assertEquals(200, $client->getResponse()->getStatusCode());
526
527 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
528
529 $crawler = $client->submit($form, [
530 'tagging_rule[rule]' => str_repeat('title', 60),
531 'tagging_rule[tags]' => 'cool tag',
532 ]);
533
534 $this->assertEquals(200, $client->getResponse()->getStatusCode());
535
536 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
537
538 $this->assertContains('255 characters', $body[0]);
539 }
540
512 public function testDeletingTaggingRuleFromAnOtherUser() 541 public function testDeletingTaggingRuleFromAnOtherUser()
513 { 542 {
514 $this->logInAs('bob'); 543 $this->logInAs('bob');
@@ -570,4 +599,283 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 599 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 600 $config->set('demo_mode_username', 'wallabag');
572 } 601 }
602
603 public function testDeleteUserButtonVisibility()
604 {
605 $this->logInAs('admin');
606 $client = $this->getClient();
607
608 $crawler = $client->request('GET', '/config');
609
610 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
611 $this->assertContains('config.form_user.delete.button', $body[0]);
612
613 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
614
615 $user = $em
616 ->getRepository('WallabagUserBundle:User')
617 ->findOneByUsername('empty');
618 $user->setEnabled(false);
619 $em->persist($user);
620
621 $user = $em
622 ->getRepository('WallabagUserBundle:User')
623 ->findOneByUsername('bob');
624 $user->setEnabled(false);
625 $em->persist($user);
626
627 $em->flush();
628
629 $crawler = $client->request('GET', '/config');
630
631 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
632 $this->assertNotContains('config.form_user.delete.button', $body[0]);
633
634 $client->request('GET', '/account/delete');
635 $this->assertEquals(403, $client->getResponse()->getStatusCode());
636
637 $user = $em
638 ->getRepository('WallabagUserBundle:User')
639 ->findOneByUsername('empty');
640 $user->setEnabled(true);
641 $em->persist($user);
642
643 $user = $em
644 ->getRepository('WallabagUserBundle:User')
645 ->findOneByUsername('bob');
646 $user->setEnabled(true);
647 $em->persist($user);
648
649 $em->flush();
650 }
651
652 public function testDeleteAccount()
653 {
654 $client = $this->getClient();
655 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
656
657 $user = new User();
658 $user->setName('Wallace');
659 $user->setEmail('wallace@wallabag.org');
660 $user->setUsername('wallace');
661 $user->setPlainPassword('wallace');
662 $user->setEnabled(true);
663 $user->addRole('ROLE_SUPER_ADMIN');
664
665 $em->persist($user);
666
667 $config = new Config($user);
668
669 $config->setTheme('material');
670 $config->setItemsPerPage(30);
671 $config->setReadingSpeed(1);
672 $config->setLanguage('en');
673 $config->setPocketConsumerKey('xxxxx');
674
675 $em->persist($config);
676 $em->flush();
677
678 $this->logInAs('wallace');
679 $loggedInUserId = $this->getLoggedInUserId();
680
681 // create entry to check after user deletion
682 // that this entry is also deleted
683 $crawler = $client->request('GET', '/new');
684
685 $this->assertEquals(200, $client->getResponse()->getStatusCode());
686
687 $form = $crawler->filter('form[name=entry]')->form();
688 $data = [
689 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
690 ];
691
692 $client->submit($form, $data);
693 $this->assertEquals(302, $client->getResponse()->getStatusCode());
694
695 $crawler = $client->request('GET', '/config');
696
697 $deleteLink = $crawler->filter('.delete-account')->last()->link();
698
699 $client->click($deleteLink);
700 $this->assertEquals(302, $client->getResponse()->getStatusCode());
701
702 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
703 $user = $em
704 ->getRepository('WallabagUserBundle:User')
705 ->createQueryBuilder('u')
706 ->where('u.username = :username')->setParameter('username', 'wallace')
707 ->getQuery()
708 ->getOneOrNullResult()
709 ;
710
711 $this->assertNull($user);
712
713 $entries = $client->getContainer()
714 ->get('doctrine.orm.entity_manager')
715 ->getRepository('WallabagCoreBundle:Entry')
716 ->findByUser($loggedInUserId);
717
718 $this->assertEmpty($entries);
719 }
720
721 public function testReset()
722 {
723 $this->logInAs('empty');
724 $client = $this->getClient();
725
726 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
727
728 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
729
730 $tag = new Tag();
731 $tag->setLabel('super');
732 $em->persist($tag);
733
734 $entry = new Entry($user);
735 $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
736 $entry->setContent('Youhou');
737 $entry->setTitle('Youhou');
738 $entry->addTag($tag);
739 $em->persist($entry);
740
741 $entry2 = new Entry($user);
742 $entry2->setUrl('http://www.lemonde.de/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
743 $entry2->setContent('Youhou');
744 $entry2->setTitle('Youhou');
745 $entry2->addTag($tag);
746 $em->persist($entry2);
747
748 $annotation = new Annotation($user);
749 $annotation->setText('annotated');
750 $annotation->setQuote('annotated');
751 $annotation->setRanges([]);
752 $annotation->setEntry($entry);
753 $em->persist($annotation);
754
755 $em->flush();
756
757 // reset annotations
758 $crawler = $client->request('GET', '/config#set3');
759
760 $this->assertEquals(200, $client->getResponse()->getStatusCode());
761
762 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
763
764 $this->assertEquals(302, $client->getResponse()->getStatusCode());
765 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
766
767 $annotationsReset = $em
768 ->getRepository('WallabagAnnotationBundle:Annotation')
769 ->findAnnotationsByPageId($entry->getId(), $user->getId());
770
771 $this->assertEmpty($annotationsReset, 'Annotations were reset');
772
773 // reset tags
774 $crawler = $client->request('GET', '/config#set3');
775
776 $this->assertEquals(200, $client->getResponse()->getStatusCode());
777
778 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
779
780 $this->assertEquals(302, $client->getResponse()->getStatusCode());
781 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
782
783 $tagReset = $em
784 ->getRepository('WallabagCoreBundle:Tag')
785 ->countAllTags($user->getId());
786
787 $this->assertEquals(0, $tagReset, 'Tags were reset');
788
789 // reset entries
790 $crawler = $client->request('GET', '/config#set3');
791
792 $this->assertEquals(200, $client->getResponse()->getStatusCode());
793
794 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
795
796 $this->assertEquals(302, $client->getResponse()->getStatusCode());
797 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
798
799 $entryReset = $em
800 ->getRepository('WallabagCoreBundle:Entry')
801 ->countAllEntriesByUsername($user->getId());
802
803 $this->assertEquals(0, $entryReset, 'Entries were reset');
804 }
805
806 public function testResetEntriesCascade()
807 {
808 $this->logInAs('empty');
809 $client = $this->getClient();
810
811 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
812
813 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
814
815 $tag = new Tag();
816 $tag->setLabel('super');
817 $em->persist($tag);
818
819 $entry = new Entry($user);
820 $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
821 $entry->setContent('Youhou');
822 $entry->setTitle('Youhou');
823 $entry->addTag($tag);
824 $em->persist($entry);
825
826 $annotation = new Annotation($user);
827 $annotation->setText('annotated');
828 $annotation->setQuote('annotated');
829 $annotation->setRanges([]);
830 $annotation->setEntry($entry);
831 $em->persist($annotation);
832
833 $em->flush();
834
835 $crawler = $client->request('GET', '/config#set3');
836
837 $this->assertEquals(200, $client->getResponse()->getStatusCode());
838
839 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
840
841 $this->assertEquals(302, $client->getResponse()->getStatusCode());
842 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
843
844 $entryReset = $em
845 ->getRepository('WallabagCoreBundle:Entry')
846 ->countAllEntriesByUsername($user->getId());
847
848 $this->assertEquals(0, $entryReset, 'Entries were reset');
849
850 $tagReset = $em
851 ->getRepository('WallabagCoreBundle:Tag')
852 ->countAllTags($user->getId());
853
854 $this->assertEquals(0, $tagReset, 'Tags were reset');
855
856 $annotationsReset = $em
857 ->getRepository('WallabagAnnotationBundle:Annotation')
858 ->findAnnotationsByPageId($entry->getId(), $user->getId());
859
860 $this->assertEmpty($annotationsReset, 'Annotations were reset');
861 }
862
863 public function testSwitchViewMode()
864 {
865 $this->logInAs('admin');
866 $client = $this->getClient();
867
868 $client->request('GET', '/unread/list');
869
870 $this->assertNotContains('listmode', $client->getResponse()->getContent());
871
872 $client->request('GET', '/config/view-mode');
873 $crawler = $client->followRedirect();
874
875 $client->request('GET', '/unread/list');
876
877 $this->assertContains('listmode', $client->getResponse()->getContent());
878
879 $client->request('GET', '/config/view-mode');
880 }
573} 881}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 05113650..06ed2db6 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config;
6use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
7 8
8class EntryControllerTest extends WallabagCoreTestCase 9class EntryControllerTest extends WallabagCoreTestCase
@@ -724,6 +725,15 @@ class EntryControllerTest extends WallabagCoreTestCase
724 $crawler = $client->submit($form, $data); 725 $crawler = $client->submit($form, $data);
725 $this->assertCount(5, $crawler->filter('div[class=entry]')); 726 $this->assertCount(5, $crawler->filter('div[class=entry]'));
726 727
728 $crawler = $client->request('GET', '/unread/list');
729 $form = $crawler->filter('button[id=submit-filter]')->form();
730 $data = [
731 'entry_filter[domainName]' => 'dOmain',
732 ];
733
734 $crawler = $client->submit($form, $data);
735 $this->assertCount(5, $crawler->filter('div[class=entry]'));
736
727 $form = $crawler->filter('button[id=submit-filter]')->form(); 737 $form = $crawler->filter('button[id=submit-filter]')->form();
728 $data = [ 738 $data = [
729 'entry_filter[domainName]' => 'wallabag', 739 'entry_filter[domainName]' => 'wallabag',
@@ -800,15 +810,15 @@ class EntryControllerTest extends WallabagCoreTestCase
800 ->getRepository('WallabagCoreBundle:Entry') 810 ->getRepository('WallabagCoreBundle:Entry')
801 ->findOneByUser($this->getLoggedInUserId()); 811 ->findOneByUser($this->getLoggedInUserId());
802 812
803 // no uuid 813 // no uid
804 $client->request('GET', '/share/'.$content->getUuid()); 814 $client->request('GET', '/share/'.$content->getUid());
805 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 815 $this->assertEquals(404, $client->getResponse()->getStatusCode());
806 816
807 // generating the uuid 817 // generating the uid
808 $client->request('GET', '/share/'.$content->getId()); 818 $client->request('GET', '/share/'.$content->getId());
809 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 819 $this->assertEquals(302, $client->getResponse()->getStatusCode());
810 820
811 // follow link with uuid 821 // follow link with uid
812 $crawler = $client->followRedirect(); 822 $crawler = $client->followRedirect();
813 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 823 $this->assertEquals(200, $client->getResponse()->getStatusCode());
814 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); 824 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
@@ -822,7 +832,7 @@ class EntryControllerTest extends WallabagCoreTestCase
822 832
823 // sharing is now disabled 833 // sharing is now disabled
824 $client->getContainer()->get('craue_config')->set('share_public', 0); 834 $client->getContainer()->get('craue_config')->set('share_public', 0);
825 $client->request('GET', '/share/'.$content->getUuid()); 835 $client->request('GET', '/share/'.$content->getUid());
826 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 836 $this->assertEquals(404, $client->getResponse()->getStatusCode());
827 837
828 $client->request('GET', '/view/'.$content->getId()); 838 $client->request('GET', '/view/'.$content->getId());
@@ -833,7 +843,255 @@ class EntryControllerTest extends WallabagCoreTestCase
833 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 843 $this->assertEquals(302, $client->getResponse()->getStatusCode());
834 844
835 // share is now disable 845 // share is now disable
836 $client->request('GET', '/share/'.$content->getUuid()); 846 $client->request('GET', '/share/'.$content->getUid());
837 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 847 $this->assertEquals(404, $client->getResponse()->getStatusCode());
838 } 848 }
849
850 public function testNewEntryWithDownloadImagesEnabled()
851 {
852 $this->logInAs('admin');
853 $client = $this->getClient();
854
855 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
856 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
857
858 $crawler = $client->request('GET', '/new');
859
860 $this->assertEquals(200, $client->getResponse()->getStatusCode());
861
862 $form = $crawler->filter('form[name=entry]')->form();
863
864 $data = [
865 'entry[url]' => $url,
866 ];
867
868 $client->submit($form, $data);
869
870 $this->assertEquals(302, $client->getResponse()->getStatusCode());
871
872 $em = $client->getContainer()
873 ->get('doctrine.orm.entity_manager');
874
875 $entry = $em
876 ->getRepository('WallabagCoreBundle:Entry')
877 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
878
879 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
880 $this->assertEquals($url, $entry->getUrl());
881 $this->assertContains('Perpignan', $entry->getTitle());
882 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
883
884 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
885 }
886
887 /**
888 * @depends testNewEntryWithDownloadImagesEnabled
889 */
890 public function testRemoveEntryWithDownloadImagesEnabled()
891 {
892 $this->logInAs('admin');
893 $client = $this->getClient();
894
895 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
896 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
897
898 $content = $client->getContainer()
899 ->get('doctrine.orm.entity_manager')
900 ->getRepository('WallabagCoreBundle:Entry')
901 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
902
903 $client->request('GET', '/delete/'.$content->getId());
904
905 $this->assertEquals(302, $client->getResponse()->getStatusCode());
906
907 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
908 }
909
910 public function testRedirectToHomepage()
911 {
912 $this->logInAs('empty');
913 $client = $this->getClient();
914
915 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
916 $user = $em
917 ->getRepository('WallabagUserBundle:User')
918 ->find($this->getLoggedInUserId());
919
920 if (!$user) {
921 $this->markTestSkipped('No user found in db.');
922 }
923
924 // Redirect to homepage
925 $config = $user->getConfig();
926 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
927 $em->persist($config);
928 $em->flush();
929
930 $content = $client->getContainer()
931 ->get('doctrine.orm.entity_manager')
932 ->getRepository('WallabagCoreBundle:Entry')
933 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
934
935 $client->request('GET', '/view/'.$content->getId());
936 $client->request('GET', '/archive/'.$content->getId());
937
938 $this->assertEquals(302, $client->getResponse()->getStatusCode());
939 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
940 }
941
942 public function testRedirectToCurrentPage()
943 {
944 $this->logInAs('empty');
945 $client = $this->getClient();
946
947 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
948 $user = $em
949 ->getRepository('WallabagUserBundle:User')
950 ->find($this->getLoggedInUserId());
951
952 if (!$user) {
953 $this->markTestSkipped('No user found in db.');
954 }
955
956 // Redirect to current page
957 $config = $user->getConfig();
958 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
959 $em->persist($config);
960 $em->flush();
961
962 $content = $client->getContainer()
963 ->get('doctrine.orm.entity_manager')
964 ->getRepository('WallabagCoreBundle:Entry')
965 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
966
967 $client->request('GET', '/view/'.$content->getId());
968 $client->request('GET', '/archive/'.$content->getId());
969
970 $this->assertEquals(302, $client->getResponse()->getStatusCode());
971 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location'));
972 }
973
974 public function testFilterOnHttpStatus()
975 {
976 $this->logInAs('admin');
977 $client = $this->getClient();
978
979 $crawler = $client->request('GET', '/new');
980 $form = $crawler->filter('form[name=entry]')->form();
981
982 $data = [
983 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
984 ];
985
986 $client->submit($form, $data);
987
988 $crawler = $client->request('GET', '/all/list');
989 $form = $crawler->filter('button[id=submit-filter]')->form();
990
991 $data = [
992 'entry_filter[httpStatus]' => 404,
993 ];
994
995 $crawler = $client->submit($form, $data);
996
997 $this->assertCount(1, $crawler->filter('div[class=entry]'));
998
999 $crawler = $client->request('GET', '/new');
1000 $form = $crawler->filter('form[name=entry]')->form();
1001
1002 $data = [
1003 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm',
1004 ];
1005
1006 $client->submit($form, $data);
1007
1008 $crawler = $client->request('GET', '/all/list');
1009 $form = $crawler->filter('button[id=submit-filter]')->form();
1010
1011 $data = [
1012 'entry_filter[httpStatus]' => 200,
1013 ];
1014
1015 $crawler = $client->submit($form, $data);
1016
1017 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1018
1019 $crawler = $client->request('GET', '/all/list');
1020 $form = $crawler->filter('button[id=submit-filter]')->form();
1021
1022 $data = [
1023 'entry_filter[httpStatus]' => 1024,
1024 ];
1025
1026 $crawler = $client->submit($form, $data);
1027
1028 $this->assertCount(7, $crawler->filter('div[class=entry]'));
1029 }
1030
1031 public function testSearch()
1032 {
1033 $this->logInAs('admin');
1034 $client = $this->getClient();
1035
1036 // Search on unread list
1037 $crawler = $client->request('GET', '/unread/list');
1038
1039 $form = $crawler->filter('form[name=search]')->form();
1040 $data = [
1041 'search_entry[term]' => 'title',
1042 ];
1043
1044 $crawler = $client->submit($form, $data);
1045
1046 $this->assertCount(5, $crawler->filter('div[class=entry]'));
1047
1048 // Search on starred list
1049 $crawler = $client->request('GET', '/starred/list');
1050
1051 $form = $crawler->filter('form[name=search]')->form();
1052 $data = [
1053 'search_entry[term]' => 'title',
1054 ];
1055
1056 $crawler = $client->submit($form, $data);
1057
1058 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1059
1060 // Added new article to test on archive list
1061 $crawler = $client->request('GET', '/new');
1062 $form = $crawler->filter('form[name=entry]')->form();
1063 $data = [
1064 'entry[url]' => $this->url,
1065 ];
1066 $client->submit($form, $data);
1067 $content = $client->getContainer()
1068 ->get('doctrine.orm.entity_manager')
1069 ->getRepository('WallabagCoreBundle:Entry')
1070 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1071 $client->request('GET', '/archive/'.$content->getId());
1072
1073 $crawler = $client->request('GET', '/archive/list');
1074
1075 $form = $crawler->filter('form[name=search]')->form();
1076 $data = [
1077 'search_entry[term]' => 'manège',
1078 ];
1079
1080 $crawler = $client->submit($form, $data);
1081
1082 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1083 $client->request('GET', '/delete/'.$content->getId());
1084
1085 // test on list of all articles
1086 $crawler = $client->request('GET', '/all/list');
1087
1088 $form = $crawler->filter('form[name=search]')->form();
1089 $data = [
1090 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1091 ];
1092
1093 $crawler = $client->submit($form, $data);
1094
1095 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1096 }
839} 1097}
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 5ca886bd..32a18e26 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -119,7 +119,7 @@ class ExportControllerTest extends WallabagCoreTestCase
119 $this->assertEquals('binary', $headers->get('content-transfer-encoding')); 119 $this->assertEquals('binary', $headers->get('content-transfer-encoding'));
120 120
121 ob_start(); 121 ob_start();
122 $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo'); 122 $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo-bar');
123 ob_end_clean(); 123 ob_end_clean();
124 124
125 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 125 $this->assertEquals(200, $client->getResponse()->getStatusCode());
@@ -241,7 +241,7 @@ class ExportControllerTest extends WallabagCoreTestCase
241 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); 241 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']);
242 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); 242 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']);
243 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); 243 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']);
244 $this->assertEquals(['foo', 'baz'], $content[0]['tags']); 244 $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']);
245 } 245 }
246 246
247 public function testXmlExport() 247 public function testXmlExport()
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
index fb6fe06a..5a59654d 100644
--- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
@@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6 6
7class RssControllerTest extends WallabagCoreTestCase 7class RssControllerTest extends WallabagCoreTestCase
8{ 8{
9 public function validateDom($xml, $nb = null) 9 public function validateDom($xml, $type, $nb = null)
10 { 10 {
11 $doc = new \DOMDocument(); 11 $doc = new \DOMDocument();
12 $doc->loadXML($xml); 12 $doc->loadXML($xml);
@@ -22,6 +22,23 @@ class RssControllerTest extends WallabagCoreTestCase
22 $this->assertEquals(1, $xpath->query('/rss')->length); 22 $this->assertEquals(1, $xpath->query('/rss')->length);
23 $this->assertEquals(1, $xpath->query('/rss/channel')->length); 23 $this->assertEquals(1, $xpath->query('/rss/channel')->length);
24 24
25 $this->assertEquals(1, $xpath->query('/rss/channel/title')->length);
26 $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue);
27
28 $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length);
29
30 $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length);
31 $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue);
32
33 $this->assertEquals(1, $xpath->query('/rss/channel/description')->length);
34 $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue);
35
36 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length);
37 $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href'));
38
39 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length);
40 $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href'));
41
25 foreach ($xpath->query('//item') as $item) { 42 foreach ($xpath->query('//item') as $item) {
26 $this->assertEquals(1, $xpath->query('title', $item)->length); 43 $this->assertEquals(1, $xpath->query('title', $item)->length);
27 $this->assertEquals(1, $xpath->query('source', $item)->length); 44 $this->assertEquals(1, $xpath->query('source', $item)->length);
@@ -77,7 +94,7 @@ class RssControllerTest extends WallabagCoreTestCase
77 94
78 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 95 $this->assertEquals(200, $client->getResponse()->getStatusCode());
79 96
80 $this->validateDom($client->getResponse()->getContent(), 2); 97 $this->validateDom($client->getResponse()->getContent(), 'unread', 2);
81 } 98 }
82 99
83 public function testStarred() 100 public function testStarred()
@@ -99,7 +116,7 @@ class RssControllerTest extends WallabagCoreTestCase
99 116
100 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); 117 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1);
101 118
102 $this->validateDom($client->getResponse()->getContent()); 119 $this->validateDom($client->getResponse()->getContent(), 'starred');
103 } 120 }
104 121
105 public function testArchives() 122 public function testArchives()
@@ -121,6 +138,34 @@ class RssControllerTest extends WallabagCoreTestCase
121 138
122 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 139 $this->assertEquals(200, $client->getResponse()->getStatusCode());
123 140
124 $this->validateDom($client->getResponse()->getContent()); 141 $this->validateDom($client->getResponse()->getContent(), 'archive');
142 }
143
144 public function testPagination()
145 {
146 $client = $this->getClient();
147 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
148 $user = $em
149 ->getRepository('WallabagUserBundle:User')
150 ->findOneByUsername('admin');
151
152 $config = $user->getConfig();
153 $config->setRssToken('SUPERTOKEN');
154 $config->setRssLimit(1);
155 $em->persist($config);
156 $em->flush();
157
158 $client = $this->getClient();
159
160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
161 $this->assertEquals(200, $client->getResponse()->getStatusCode());
162 $this->validateDom($client->getResponse()->getContent(), 'unread');
163
164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
165 $this->assertEquals(200, $client->getResponse()->getStatusCode());
166 $this->validateDom($client->getResponse()->getContent(), 'unread');
167
168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
169 $this->assertEquals(302, $client->getResponse()->getStatusCode());
125 } 170 }
126} 171}
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 08f4676e..2cf596d4 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -82,6 +82,6 @@ class SecurityControllerTest extends WallabagCoreTestCase
82 82
83 $client->followRedirects(); 83 $client->followRedirects();
84 $crawler = $client->request('GET', '/register'); 84 $crawler = $client->request('GET', '/register');
85 $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]); 85 $this->assertContains('registration.submit', $client->getResponse()->getContent());
86 } 86 }
87} 87}
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 769ce66e..fa1a3539 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -61,7 +61,7 @@ class TagControllerTest extends WallabagCoreTestCase
61 61
62 // tag already exists but still not assigned to this entry 62 // tag already exists but still not assigned to this entry
63 $data = [ 63 $data = [
64 'tag[label]' => 'foo', 64 'tag[label]' => 'foo bar',
65 ]; 65 ];
66 66
67 $client->submit($form, $data); 67 $client->submit($form, $data);