diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle')
15 files changed, 933 insertions, 24 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index d4fbe2d4..447feb4f 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 | ||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Config; | ||
7 | use Wallabag\UserBundle\Entity\User; | ||
8 | use Wallabag\CoreBundle\Entity\Entry; | ||
9 | use Wallabag\CoreBundle\Entity\Tag; | ||
10 | use Wallabag\AnnotationBundle\Entity\Annotation; | ||
6 | 11 | ||
7 | class ConfigControllerTest extends WallabagCoreTestCase | 12 | class 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 | ||
@@ -570,4 +576,283 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
570 | $config->set('demo_mode_enabled', 0); | 576 | $config->set('demo_mode_enabled', 0); |
571 | $config->set('demo_mode_username', 'wallabag'); | 577 | $config->set('demo_mode_username', 'wallabag'); |
572 | } | 578 | } |
579 | |||
580 | public function testDeleteUserButtonVisibility() | ||
581 | { | ||
582 | $this->logInAs('admin'); | ||
583 | $client = $this->getClient(); | ||
584 | |||
585 | $crawler = $client->request('GET', '/config'); | ||
586 | |||
587 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
588 | $this->assertContains('config.form_user.delete.button', $body[0]); | ||
589 | |||
590 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
591 | |||
592 | $user = $em | ||
593 | ->getRepository('WallabagUserBundle:User') | ||
594 | ->findOneByUsername('empty'); | ||
595 | $user->setEnabled(false); | ||
596 | $em->persist($user); | ||
597 | |||
598 | $user = $em | ||
599 | ->getRepository('WallabagUserBundle:User') | ||
600 | ->findOneByUsername('bob'); | ||
601 | $user->setEnabled(false); | ||
602 | $em->persist($user); | ||
603 | |||
604 | $em->flush(); | ||
605 | |||
606 | $crawler = $client->request('GET', '/config'); | ||
607 | |||
608 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
609 | $this->assertNotContains('config.form_user.delete.button', $body[0]); | ||
610 | |||
611 | $client->request('GET', '/account/delete'); | ||
612 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
613 | |||
614 | $user = $em | ||
615 | ->getRepository('WallabagUserBundle:User') | ||
616 | ->findOneByUsername('empty'); | ||
617 | $user->setEnabled(true); | ||
618 | $em->persist($user); | ||
619 | |||
620 | $user = $em | ||
621 | ->getRepository('WallabagUserBundle:User') | ||
622 | ->findOneByUsername('bob'); | ||
623 | $user->setEnabled(true); | ||
624 | $em->persist($user); | ||
625 | |||
626 | $em->flush(); | ||
627 | } | ||
628 | |||
629 | public function testDeleteAccount() | ||
630 | { | ||
631 | $client = $this->getClient(); | ||
632 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
633 | |||
634 | $user = new User(); | ||
635 | $user->setName('Wallace'); | ||
636 | $user->setEmail('wallace@wallabag.org'); | ||
637 | $user->setUsername('wallace'); | ||
638 | $user->setPlainPassword('wallace'); | ||
639 | $user->setEnabled(true); | ||
640 | $user->addRole('ROLE_SUPER_ADMIN'); | ||
641 | |||
642 | $em->persist($user); | ||
643 | |||
644 | $config = new Config($user); | ||
645 | |||
646 | $config->setTheme('material'); | ||
647 | $config->setItemsPerPage(30); | ||
648 | $config->setReadingSpeed(1); | ||
649 | $config->setLanguage('en'); | ||
650 | $config->setPocketConsumerKey('xxxxx'); | ||
651 | |||
652 | $em->persist($config); | ||
653 | $em->flush(); | ||
654 | |||
655 | $this->logInAs('wallace'); | ||
656 | $loggedInUserId = $this->getLoggedInUserId(); | ||
657 | |||
658 | // create entry to check after user deletion | ||
659 | // that this entry is also deleted | ||
660 | $crawler = $client->request('GET', '/new'); | ||
661 | |||
662 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
663 | |||
664 | $form = $crawler->filter('form[name=entry]')->form(); | ||
665 | $data = [ | ||
666 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | ||
667 | ]; | ||
668 | |||
669 | $client->submit($form, $data); | ||
670 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
671 | |||
672 | $crawler = $client->request('GET', '/config'); | ||
673 | |||
674 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); | ||
675 | |||
676 | $client->click($deleteLink); | ||
677 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
678 | |||
679 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
680 | $user = $em | ||
681 | ->getRepository('WallabagUserBundle:User') | ||
682 | ->createQueryBuilder('u') | ||
683 | ->where('u.username = :username')->setParameter('username', 'wallace') | ||
684 | ->getQuery() | ||
685 | ->getOneOrNullResult() | ||
686 | ; | ||
687 | |||
688 | $this->assertNull($user); | ||
689 | |||
690 | $entries = $client->getContainer() | ||
691 | ->get('doctrine.orm.entity_manager') | ||
692 | ->getRepository('WallabagCoreBundle:Entry') | ||
693 | ->findByUser($loggedInUserId); | ||
694 | |||
695 | $this->assertEmpty($entries); | ||
696 | } | ||
697 | |||
698 | public function testReset() | ||
699 | { | ||
700 | $this->logInAs('empty'); | ||
701 | $client = $this->getClient(); | ||
702 | |||
703 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
704 | |||
705 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
706 | |||
707 | $tag = new Tag(); | ||
708 | $tag->setLabel('super'); | ||
709 | $em->persist($tag); | ||
710 | |||
711 | $entry = new Entry($user); | ||
712 | $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'); | ||
713 | $entry->setContent('Youhou'); | ||
714 | $entry->setTitle('Youhou'); | ||
715 | $entry->addTag($tag); | ||
716 | $em->persist($entry); | ||
717 | |||
718 | $entry2 = new Entry($user); | ||
719 | $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'); | ||
720 | $entry2->setContent('Youhou'); | ||
721 | $entry2->setTitle('Youhou'); | ||
722 | $entry2->addTag($tag); | ||
723 | $em->persist($entry2); | ||
724 | |||
725 | $annotation = new Annotation($user); | ||
726 | $annotation->setText('annotated'); | ||
727 | $annotation->setQuote('annotated'); | ||
728 | $annotation->setRanges([]); | ||
729 | $annotation->setEntry($entry); | ||
730 | $em->persist($annotation); | ||
731 | |||
732 | $em->flush(); | ||
733 | |||
734 | // reset annotations | ||
735 | $crawler = $client->request('GET', '/config#set3'); | ||
736 | |||
737 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
738 | |||
739 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); | ||
740 | |||
741 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
742 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
743 | |||
744 | $annotationsReset = $em | ||
745 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
746 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | ||
747 | |||
748 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
749 | |||
750 | // reset tags | ||
751 | $crawler = $client->request('GET', '/config#set3'); | ||
752 | |||
753 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
754 | |||
755 | $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); | ||
756 | |||
757 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
758 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
759 | |||
760 | $tagReset = $em | ||
761 | ->getRepository('WallabagCoreBundle:Tag') | ||
762 | ->countAllTags($user->getId()); | ||
763 | |||
764 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | ||
765 | |||
766 | // reset entries | ||
767 | $crawler = $client->request('GET', '/config#set3'); | ||
768 | |||
769 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
770 | |||
771 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | ||
772 | |||
773 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
774 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
775 | |||
776 | $entryReset = $em | ||
777 | ->getRepository('WallabagCoreBundle:Entry') | ||
778 | ->countAllEntriesByUsername($user->getId()); | ||
779 | |||
780 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | ||
781 | } | ||
782 | |||
783 | public function testResetEntriesCascade() | ||
784 | { | ||
785 | $this->logInAs('empty'); | ||
786 | $client = $this->getClient(); | ||
787 | |||
788 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
789 | |||
790 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
791 | |||
792 | $tag = new Tag(); | ||
793 | $tag->setLabel('super'); | ||
794 | $em->persist($tag); | ||
795 | |||
796 | $entry = new Entry($user); | ||
797 | $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'); | ||
798 | $entry->setContent('Youhou'); | ||
799 | $entry->setTitle('Youhou'); | ||
800 | $entry->addTag($tag); | ||
801 | $em->persist($entry); | ||
802 | |||
803 | $annotation = new Annotation($user); | ||
804 | $annotation->setText('annotated'); | ||
805 | $annotation->setQuote('annotated'); | ||
806 | $annotation->setRanges([]); | ||
807 | $annotation->setEntry($entry); | ||
808 | $em->persist($annotation); | ||
809 | |||
810 | $em->flush(); | ||
811 | |||
812 | $crawler = $client->request('GET', '/config#set3'); | ||
813 | |||
814 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
815 | |||
816 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | ||
817 | |||
818 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
819 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
820 | |||
821 | $entryReset = $em | ||
822 | ->getRepository('WallabagCoreBundle:Entry') | ||
823 | ->countAllEntriesByUsername($user->getId()); | ||
824 | |||
825 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | ||
826 | |||
827 | $tagReset = $em | ||
828 | ->getRepository('WallabagCoreBundle:Tag') | ||
829 | ->countAllTags($user->getId()); | ||
830 | |||
831 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | ||
832 | |||
833 | $annotationsReset = $em | ||
834 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
835 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | ||
836 | |||
837 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
838 | } | ||
839 | |||
840 | public function testSwitchViewMode() | ||
841 | { | ||
842 | $this->logInAs('admin'); | ||
843 | $client = $this->getClient(); | ||
844 | |||
845 | $client->request('GET', '/unread/list'); | ||
846 | |||
847 | $this->assertNotContains('listmode', $client->getResponse()->getContent()); | ||
848 | |||
849 | $client->request('GET', '/config/view-mode'); | ||
850 | $crawler = $client->followRedirect(); | ||
851 | |||
852 | $client->request('GET', '/unread/list'); | ||
853 | |||
854 | $this->assertContains('listmode', $client->getResponse()->getContent()); | ||
855 | |||
856 | $client->request('GET', '/config/view-mode'); | ||
857 | } | ||
573 | } | 858 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 05113650..c347cca5 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Config; | ||
6 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
7 | 8 | ||
8 | class EntryControllerTest extends WallabagCoreTestCase | 9 | class 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', |
@@ -836,4 +846,252 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
836 | $client->request('GET', '/share/'.$content->getUuid()); | 846 | $client->request('GET', '/share/'.$content->getUuid()); |
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/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 | ||
7 | class RssControllerTest extends WallabagCoreTestCase | 7 | class 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/EventListener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php index 078bb69a..84a54d3a 100644 --- a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\EventListener; | 3 | namespace Tests\Wallabag\CoreBundle\Event\Listener; |
4 | 4 | ||
5 | use Symfony\Component\EventDispatcher\EventDispatcher; | 5 | use Symfony\Component\EventDispatcher\EventDispatcher; |
6 | use Symfony\Component\HttpFoundation\Request; | 6 | use Symfony\Component\HttpFoundation\Request; |
@@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; | |||
9 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; | 9 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
10 | use Symfony\Component\HttpKernel\HttpKernelInterface; | 10 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
11 | use Symfony\Component\HttpKernel\KernelEvents; | 11 | use Symfony\Component\HttpKernel\KernelEvents; |
12 | use Wallabag\CoreBundle\EventListener\LocaleListener; | 12 | use Wallabag\CoreBundle\Event\Listener\LocaleListener; |
13 | 13 | ||
14 | class LocaleListenerTest extends \PHPUnit_Framework_TestCase | 14 | class LocaleListenerTest extends \PHPUnit_Framework_TestCase |
15 | { | 15 | { |
diff --git a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index e9ac7c1d..45aecc63 100644 --- a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\EventListener; | 3 | namespace Tests\Wallabag\CoreBundle\Event\Listener; |
4 | 4 | ||
5 | use Symfony\Component\HttpFoundation\Request; | 5 | use Symfony\Component\HttpFoundation\Request; |
6 | use Symfony\Component\HttpFoundation\Session\Session; | 6 | use Symfony\Component\HttpFoundation\Session\Session; |
@@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; | |||
8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | 8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
9 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | 9 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; |
10 | use Wallabag\CoreBundle\Entity\Config; | 10 | use Wallabag\CoreBundle\Entity\Config; |
11 | use Wallabag\CoreBundle\EventListener\UserLocaleListener; | 11 | use Wallabag\CoreBundle\Event\Listener\UserLocaleListener; |
12 | use Wallabag\UserBundle\Entity\User; | 12 | use Wallabag\UserBundle\Entity\User; |
13 | 13 | ||
14 | class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase | 14 | class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase |
diff --git a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php index 4ae76703..b8cd0fad 100644 --- a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php +++ b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php | |||
@@ -1,11 +1,11 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Subscriber; | 3 | namespace Tests\Wallabag\CoreBundle\Event\Subscriber; |
4 | 4 | ||
5 | use Doctrine\Common\EventManager; | 5 | use Doctrine\Common\EventManager; |
6 | use Doctrine\ORM\Event\LoadClassMetadataEventArgs; | 6 | use Doctrine\ORM\Event\LoadClassMetadataEventArgs; |
7 | use Doctrine\ORM\Mapping\ClassMetadata; | 7 | use Doctrine\ORM\Mapping\ClassMetadata; |
8 | use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber; | 8 | use Wallabag\CoreBundle\Event\Subscriber\TablePrefixSubscriber; |
9 | 9 | ||
10 | class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase | 10 | class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase |
11 | { | 11 | { |
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php new file mode 100644 index 00000000..aee67259 --- /dev/null +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -0,0 +1,85 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; | ||
4 | |||
5 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; | ||
6 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; | ||
7 | use PHPUnit_Framework_TestCase; | ||
8 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; | ||
9 | |||
10 | class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | ||
11 | { | ||
12 | /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */ | ||
13 | protected $builder; | ||
14 | |||
15 | public function testBuildConfigExists() | ||
16 | { | ||
17 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | ||
18 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') | ||
19 | ->disableOriginalConstructor() | ||
20 | ->getMock(); | ||
21 | |||
22 | $grabySiteConfig = new GrabySiteConfig(); | ||
23 | $grabySiteConfig->requires_login = true; | ||
24 | $grabySiteConfig->login_uri = 'http://example.com/login'; | ||
25 | $grabySiteConfig->login_username_field = 'login'; | ||
26 | $grabySiteConfig->login_password_field = 'password'; | ||
27 | $grabySiteConfig->login_extra_fields = ['field' => 'value']; | ||
28 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | ||
29 | |||
30 | $grabyConfigBuilderMock | ||
31 | ->method('buildForHost') | ||
32 | ->with('example.com') | ||
33 | ->will($this->returnValue($grabySiteConfig)); | ||
34 | |||
35 | $this->builder = new GrabySiteConfigBuilder( | ||
36 | $grabyConfigBuilderMock, | ||
37 | ['example.com' => ['username' => 'foo', 'password' => 'bar']] | ||
38 | ); | ||
39 | |||
40 | $config = $this->builder->buildForHost('example.com'); | ||
41 | |||
42 | self::assertEquals( | ||
43 | new SiteConfig([ | ||
44 | 'host' => 'example.com', | ||
45 | 'requiresLogin' => true, | ||
46 | 'loginUri' => 'http://example.com/login', | ||
47 | 'usernameField' => 'login', | ||
48 | 'passwordField' => 'password', | ||
49 | 'extraFields' => ['field' => 'value'], | ||
50 | 'notLoggedInXpath' => '//div[@class="need-login"]', | ||
51 | 'username' => 'foo', | ||
52 | 'password' => 'bar', | ||
53 | ]), | ||
54 | $config | ||
55 | ); | ||
56 | } | ||
57 | |||
58 | public function testBuildConfigDoesntExist() | ||
59 | { | ||
60 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | ||
61 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') | ||
62 | ->disableOriginalConstructor() | ||
63 | ->getMock(); | ||
64 | |||
65 | $grabyConfigBuilderMock | ||
66 | ->method('buildForHost') | ||
67 | ->with('unknown.com') | ||
68 | ->will($this->returnValue(new GrabySiteConfig())); | ||
69 | |||
70 | $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []); | ||
71 | |||
72 | $config = $this->builder->buildForHost('unknown.com'); | ||
73 | |||
74 | self::assertEquals( | ||
75 | new SiteConfig([ | ||
76 | 'host' => 'unknown.com', | ||
77 | 'requiresLogin' => false, | ||
78 | 'username' => null, | ||
79 | 'password' => null, | ||
80 | 'extraFields' => [], | ||
81 | ]), | ||
82 | $config | ||
83 | ); | ||
84 | } | ||
85 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 5d772602..33b3ff2a 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -97,6 +97,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
97 | 'url' => '', | 97 | 'url' => '', |
98 | 'content_type' => '', | 98 | 'content_type' => '', |
99 | 'language' => '', | 99 | 'language' => '', |
100 | 'status' => '', | ||
100 | 'open_graph' => [ | 101 | 'open_graph' => [ |
101 | 'og_title' => 'my title', | 102 | 'og_title' => 'my title', |
102 | 'og_description' => 'desc', | 103 | 'og_description' => 'desc', |
@@ -111,6 +112,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
111 | $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent()); | 112 | $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent()); |
112 | $this->assertEmpty($entry->getPreviewPicture()); | 113 | $this->assertEmpty($entry->getPreviewPicture()); |
113 | $this->assertEmpty($entry->getLanguage()); | 114 | $this->assertEmpty($entry->getLanguage()); |
115 | $this->assertEmpty($entry->getHttpStatus()); | ||
114 | $this->assertEmpty($entry->getMimetype()); | 116 | $this->assertEmpty($entry->getMimetype()); |
115 | $this->assertEquals(0.0, $entry->getReadingTime()); | 117 | $this->assertEquals(0.0, $entry->getReadingTime()); |
116 | $this->assertEquals('domain.io', $entry->getDomainName()); | 118 | $this->assertEquals('domain.io', $entry->getDomainName()); |
@@ -135,6 +137,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
135 | 'url' => 'http://1.1.1.1', | 137 | 'url' => 'http://1.1.1.1', |
136 | 'content_type' => 'text/html', | 138 | 'content_type' => 'text/html', |
137 | 'language' => 'fr', | 139 | 'language' => 'fr', |
140 | 'status' => '200', | ||
138 | 'open_graph' => [ | 141 | 'open_graph' => [ |
139 | 'og_title' => 'my OG title', | 142 | 'og_title' => 'my OG title', |
140 | 'og_description' => 'OG desc', | 143 | 'og_description' => 'OG desc', |
@@ -151,6 +154,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
151 | $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | 154 | $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); |
152 | $this->assertEquals('text/html', $entry->getMimetype()); | 155 | $this->assertEquals('text/html', $entry->getMimetype()); |
153 | $this->assertEquals('fr', $entry->getLanguage()); | 156 | $this->assertEquals('fr', $entry->getLanguage()); |
157 | $this->assertEquals('200', $entry->getHttpStatus()); | ||
154 | $this->assertEquals(4.0, $entry->getReadingTime()); | 158 | $this->assertEquals(4.0, $entry->getReadingTime()); |
155 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | 159 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); |
156 | } | 160 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php new file mode 100644 index 00000000..85f12d87 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -0,0 +1,142 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Wallabag\CoreBundle\Helper\DownloadImages; | ||
6 | use Monolog\Logger; | ||
7 | use Monolog\Handler\TestHandler; | ||
8 | use GuzzleHttp\Client; | ||
9 | use GuzzleHttp\Subscriber\Mock; | ||
10 | use GuzzleHttp\Message\Response; | ||
11 | use GuzzleHttp\Stream\Stream; | ||
12 | |||
13 | class DownloadImagesTest extends \PHPUnit_Framework_TestCase | ||
14 | { | ||
15 | public function testProcessHtml() | ||
16 | { | ||
17 | $client = new Client(); | ||
18 | |||
19 | $mock = new Mock([ | ||
20 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), | ||
21 | ]); | ||
22 | |||
23 | $client->getEmitter()->attach($mock); | ||
24 | |||
25 | $logHandler = new TestHandler(); | ||
26 | $logger = new Logger('test', array($logHandler)); | ||
27 | |||
28 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
29 | |||
30 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); | ||
31 | |||
32 | $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res); | ||
33 | } | ||
34 | |||
35 | public function testProcessHtmlWithBadImage() | ||
36 | { | ||
37 | $client = new Client(); | ||
38 | |||
39 | $mock = new Mock([ | ||
40 | new Response(200, ['content-type' => 'application/json'], Stream::factory('')), | ||
41 | ]); | ||
42 | |||
43 | $client->getEmitter()->attach($mock); | ||
44 | |||
45 | $logHandler = new TestHandler(); | ||
46 | $logger = new Logger('test', array($logHandler)); | ||
47 | |||
48 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
49 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); | ||
50 | |||
51 | $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); | ||
52 | } | ||
53 | |||
54 | public function singleImage() | ||
55 | { | ||
56 | return [ | ||
57 | ['image/pjpeg', 'jpeg'], | ||
58 | ['image/jpeg', 'jpeg'], | ||
59 | ['image/png', 'png'], | ||
60 | ['image/gif', 'gif'], | ||
61 | ]; | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * @dataProvider singleImage | ||
66 | */ | ||
67 | public function testProcessSingleImage($header, $extension) | ||
68 | { | ||
69 | $client = new Client(); | ||
70 | |||
71 | $mock = new Mock([ | ||
72 | new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), | ||
73 | ]); | ||
74 | |||
75 | $client->getEmitter()->attach($mock); | ||
76 | |||
77 | $logHandler = new TestHandler(); | ||
78 | $logger = new Logger('test', array($logHandler)); | ||
79 | |||
80 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
81 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | ||
82 | |||
83 | $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.'.$extension, $res); | ||
84 | } | ||
85 | |||
86 | public function testProcessSingleImageWithBadUrl() | ||
87 | { | ||
88 | $client = new Client(); | ||
89 | |||
90 | $mock = new Mock([ | ||
91 | new Response(404, []), | ||
92 | ]); | ||
93 | |||
94 | $client->getEmitter()->attach($mock); | ||
95 | |||
96 | $logHandler = new TestHandler(); | ||
97 | $logger = new Logger('test', array($logHandler)); | ||
98 | |||
99 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
100 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | ||
101 | |||
102 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); | ||
103 | } | ||
104 | |||
105 | public function testProcessSingleImageWithBadImage() | ||
106 | { | ||
107 | $client = new Client(); | ||
108 | |||
109 | $mock = new Mock([ | ||
110 | new Response(200, ['content-type' => 'image/png'], Stream::factory('')), | ||
111 | ]); | ||
112 | |||
113 | $client->getEmitter()->attach($mock); | ||
114 | |||
115 | $logHandler = new TestHandler(); | ||
116 | $logger = new Logger('test', array($logHandler)); | ||
117 | |||
118 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
119 | $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | ||
120 | |||
121 | $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); | ||
122 | } | ||
123 | |||
124 | public function testProcessSingleImageFailAbsolute() | ||
125 | { | ||
126 | $client = new Client(); | ||
127 | |||
128 | $mock = new Mock([ | ||
129 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), | ||
130 | ]); | ||
131 | |||
132 | $client->getEmitter()->attach($mock); | ||
133 | |||
134 | $logHandler = new TestHandler(); | ||
135 | $logger = new Logger('test', array($logHandler)); | ||
136 | |||
137 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
138 | $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); | ||
139 | |||
140 | $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); | ||
141 | } | ||
142 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index f339f75e..0539f20a 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php | |||
@@ -2,7 +2,11 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Entity\Config; | ||
6 | use Wallabag\UserBundle\Entity\User; | ||
5 | use Wallabag\CoreBundle\Helper\Redirect; | 7 | use Wallabag\CoreBundle\Helper\Redirect; |
8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
6 | 10 | ||
7 | class RedirectTest extends \PHPUnit_Framework_TestCase | 11 | class RedirectTest extends \PHPUnit_Framework_TestCase |
8 | { | 12 | { |
@@ -14,8 +18,38 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
14 | 18 | ||
15 | public function setUp() | 19 | public function setUp() |
16 | { | 20 | { |
17 | $this->routerMock = $this->getRouterMock(); | 21 | $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') |
18 | $this->redirect = new Redirect($this->routerMock); | 22 | ->disableOriginalConstructor() |
23 | ->getMock(); | ||
24 | |||
25 | $this->routerMock->expects($this->any()) | ||
26 | ->method('generate') | ||
27 | ->with('homepage') | ||
28 | ->willReturn('homepage'); | ||
29 | |||
30 | $user = new User(); | ||
31 | $user->setName('youpi'); | ||
32 | $user->setEmail('youpi@youpi.org'); | ||
33 | $user->setUsername('youpi'); | ||
34 | $user->setPlainPassword('youpi'); | ||
35 | $user->setEnabled(true); | ||
36 | $user->addRole('ROLE_SUPER_ADMIN'); | ||
37 | |||
38 | $config = new Config($user); | ||
39 | $config->setTheme('material'); | ||
40 | $config->setItemsPerPage(30); | ||
41 | $config->setReadingSpeed(1); | ||
42 | $config->setLanguage('en'); | ||
43 | $config->setPocketConsumerKey('xxxxx'); | ||
44 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | ||
45 | |||
46 | $user->setConfig($config); | ||
47 | |||
48 | $this->token = new UsernamePasswordToken($user, 'password', 'key'); | ||
49 | $tokenStorage = new TokenStorage(); | ||
50 | $tokenStorage->setToken($this->token); | ||
51 | |||
52 | $this->redirect = new Redirect($this->routerMock, $tokenStorage); | ||
19 | } | 53 | } |
20 | 54 | ||
21 | public function testRedirectToNullWithFallback() | 55 | public function testRedirectToNullWithFallback() |
@@ -39,17 +73,20 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
39 | $this->assertEquals('/unread/list', $redirectUrl); | 73 | $this->assertEquals('/unread/list', $redirectUrl); |
40 | } | 74 | } |
41 | 75 | ||
42 | private function getRouterMock() | 76 | public function testWithNotLoggedUser() |
43 | { | 77 | { |
44 | $mock = $this->getMockBuilder('Symfony\Component\Routing\Router') | 78 | $redirect = new Redirect($this->routerMock, new TokenStorage()); |
45 | ->disableOriginalConstructor() | 79 | $redirectUrl = $redirect->to('/unread/list'); |
46 | ->getMock(); | ||
47 | 80 | ||
48 | $mock->expects($this->any()) | 81 | $this->assertEquals('/unread/list', $redirectUrl); |
49 | ->method('generate') | 82 | } |
50 | ->with('homepage') | ||
51 | ->willReturn('homepage'); | ||
52 | 83 | ||
53 | return $mock; | 84 | public function testUserForRedirectToHomepage() |
85 | { | ||
86 | $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | ||
87 | |||
88 | $redirectUrl = $this->redirect->to('/unread/list'); | ||
89 | |||
90 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | ||
54 | } | 91 | } |
55 | } | 92 | } |
diff --git a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php new file mode 100644 index 00000000..435c25ca --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php | |||
@@ -0,0 +1,28 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Tools; | ||
4 | |||
5 | use Symfony\Component\Finder\Finder; | ||
6 | use Wallabag\CoreBundle\Tools\Utils; | ||
7 | |||
8 | class UtilsTest extends \PHPUnit_Framework_TestCase | ||
9 | { | ||
10 | /** | ||
11 | * @dataProvider examples | ||
12 | */ | ||
13 | public function testCorrectWordsCountForDifferentLanguages($text, $expectedCount) | ||
14 | { | ||
15 | static::assertEquals((float) $expectedCount, Utils::getReadingTime($text)); | ||
16 | } | ||
17 | |||
18 | public function examples() | ||
19 | { | ||
20 | $examples = []; | ||
21 | $finder = (new Finder())->in(__DIR__.'/samples'); | ||
22 | foreach ($finder->getIterator() as $file) { | ||
23 | $examples[] = [$file->getContents(), 1]; | ||
24 | } | ||
25 | |||
26 | return $examples; | ||
27 | } | ||
28 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt b/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt new file mode 100644 index 00000000..7b904da4 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt | |||
@@ -0,0 +1,7 @@ | |||
1 | Лорем ипсум долор сит амет, ех цум иллуд деленит, пер регионе фацилис те. Еи мел видит саепе интеллегам, яуас маиестатис цонституам яуо ат, цивибус реформиданс нецесситатибус ид яуи. Импетус тациматес пертинах ад еум. Усу еу легере бландит. | ||
2 | |||
3 | Ан меа тритани иуварет, иллум сцаевола легендос ат меа, дебитис импедит нусяуам ест ад. Не маиорум молестие цотидиеяуе вис. Иисяуе цонцлудатуряуе меи еу, татион цонсецтетуер еи про. Либер риденс ид хас, ид цонсул сенсерит пертинациа меа. Фацер молестиае цомпрехенсам ад еум, ин хис апеириан вивендум. Яуи аудире епицуреи иудицабит ат, веро хабео вертерем ад иус. Бонорум плацерат ин вис, сеа но оцурререт принципес интерессет, хас ет дицерет диспутандо. | ||
4 | |||
5 | Яуо цу цлита оцурререт. Сонет менандри ин сеа. Еум те нонумы вертерем. Вирис еяуидем фацилиси ет вим, делицата интеллегат иус ин. Ид дицат суммо витае вел, алияуип делецтус те дуо, цу вих хинц дуис видиссе. Нец цу фацилис урбанитас, алиа инсоленс ассуеверит при ут. | ||
6 | |||
7 | Яуаеяуе абхорреант инцоррупте не сеа, еу еирмод ерудити вих. Вел оптион тритани цоррумпит те. Поссе сусципит губергрен ут мел, ет еос ириуре менандри еффициенди. Те сале нулла цонсецтетуер сеа, меа не прима алиенум еффициантур. При ет воцибус реформиданс, темпор албуциус сед ан. Еи утрояуе волумус иус, атяуи цонгуе но меи. \ No newline at end of file | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/greek.txt b/tests/Wallabag/CoreBundle/Tools/samples/greek.txt new file mode 100644 index 00000000..59f15b8b --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/samples/greek.txt | |||
@@ -0,0 +1,9 @@ | |||
1 | Λορεμ ιπσθμ δολορ σιτ αμετ, ηασ νο θταμθρ qθαεqθε ρεπρεηενδθντ. Ναμ λατινε προμπτα qθαερενδθμ ιδ. Νεc ει φαcερ cονcλθδατθρqθε, vολθπτθα vολθπταρια εφφιcιενδι αδ προ, νε σεα ασσεντιορ δεφινιεβασ. Μεα αγαμ ειθσ δολορε ετ, ηισ ει cορπορα περφεcτο. Vιξ cιβο δελενιτ νε, jθστο ριδενσ οπορτερε σεδ ιδ. | ||
2 | |||
3 | Ηισ νισλ ιθvαρετ γθβεργρεν εξ. Εθμ ιμπεδιτ δετραξιτ ινιμιcθσ ατ, αλια βλανδιτ δθο εα, μεα ιλλθδ επιcθρι cονσετετθρ αδ. Ιλλθδ γραεcε δελενιτι ηισ νο. Νεc ιδ ριδενσ εθισμοδ περιcθλισ, vισ αδ λαβοραμθσ περσεcθτι. Ιθσ εα λθπτατθμ αλιqθανδο δισπθτανδο. | ||
4 | |||
5 | Νεc εθ σθασ θτιναμ cονcεπταμ, σεα φεθγαιτ φιερεντ νε, σθμο ταμqθαμ περ ετ. Ελιτ θτροqθε ατομορθμ ιν δθο, εθ μεα λιβρισ ορνατθσ ταcιματεσ. Cθ σολεατ cονστιτθαμ νεc, τε σεα εξερcι αλιενθμ ρεcτεqθε. Σεα θτιναμ ινcορρθπτε αδ, δελενιτ cονcλθσιονεμqθε ναμ αν, διαμ γθβεργρεν cθ σιτ. | ||
6 | |||
7 | Cθ σεδ αλβθcιθσ ποστθλαντ. Vιξ ιδ ηομερο περcιπιτ cονcεπταμ. Ιν vιμ λιβρισ vιδερερ, εξ vισ αλιι ερρορ. Vιξ λοβορτισ ασσεντιορ cοντεντιονεσ τε, νε ηασ δεcορε περcιπιτθρ. Εστ εξ δισπθτατιονι δεφινιτιονεμ, qθοδ πηαεδρθμ προ εθ, εξ ηασ ιντεγρε ελιγενδι cονσεcτετθερ. | ||
8 | |||
9 | Ιθσ μολλισ ειρμοδ νο, vιξ νοστρθμ cονσετετθρ ει. Ιθδιcο vερτερεμ λθcιλιθσ qθι τε, νε προμπτα θτροqθε αccομμοδαρε περ. Φαcετε μανδαμθσ ηασ εξ, λιβερ δεβετ εθμ εξ, vιξ ιδ διcερετ σιγνιφερθμqθε. Εθ vιξ vοcεντ. \ No newline at end of file | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/latin.txt b/tests/Wallabag/CoreBundle/Tools/samples/latin.txt new file mode 100644 index 00000000..605cc40e --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/samples/latin.txt | |||
@@ -0,0 +1,9 @@ | |||
1 | Lorem ipsum dolor sit amet, pro vivendo oporteat pertinacia ei. Vim fabellas molestiae cu, vel nibh legimus ea, in qui atomorum democritum. Ius ne agam soluta ignota, his sale aperiri complectitur te, omnis volumus accusam an eos. Ut mentitum appetere mel, minim temporibus eloquentiam sea ea. | ||
2 | |||
3 | Tation nominati pro ad. Pri eros eloquentiam reformidans ea, et liber epicurei erroribus pro, pri patrioque repudiandae et. Cetero perfecto at eam. Eros hendrerit constituto vix at, brute aperiri adolescens pro eu. Vix lucilius consulatu ei, ullum tantas munere vel in, regione feugiat eligendi at eam. | ||
4 | |||
5 | Eam an lucilius iracundia, audire diceret facilisi his in, ex paulo pertinacia pro. Ei nec dolorum prodesset, adhuc tacimates argumentum sit ad. Vim te hinc scriptorem, ad labores perpetua nec. Sit no legimus fierent, epicuri partiendo reformidans ne mea, per assum animal mnesarchum no. Cum cetero apeirian at. Ne altera feugait vim, pri purto accumsan at, causae mentitum epicurei eam ad. | ||
6 | |||
7 | Nec ut quod probo eligendi, cu dico iriure aperiam vis. Augue causae abhorreant per ut, iriure repudiandae no nam, exerci equidem deleniti nam te. Et duo saperet debitis adipiscing, quo odio audiam no, ex iudico delenit propriae duo. Eu eum eros abhorreant, an tractatos expetendis est. | ||
8 | |||
9 | Vix. \ No newline at end of file | ||
diff --git a/tests/Wallabag/CoreBundle/fixtures/unnamed.png b/tests/Wallabag/CoreBundle/fixtures/unnamed.png new file mode 100644 index 00000000..e6dd9caa --- /dev/null +++ b/tests/Wallabag/CoreBundle/fixtures/unnamed.png | |||
Binary files differ | |||