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.php182
1 files changed, 182 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 05113650..09cf01b8 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
@@ -836,4 +837,185 @@ class EntryControllerTest extends WallabagCoreTestCase
836 $client->request('GET', '/share/'.$content->getUuid()); 837 $client->request('GET', '/share/'.$content->getUuid());
837 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 838 $this->assertEquals(404, $client->getResponse()->getStatusCode());
838 } 839 }
840
841 public function testNewEntryWithDownloadImagesEnabled()
842 {
843 $this->logInAs('admin');
844 $client = $this->getClient();
845
846 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
847 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
848
849 $crawler = $client->request('GET', '/new');
850
851 $this->assertEquals(200, $client->getResponse()->getStatusCode());
852
853 $form = $crawler->filter('form[name=entry]')->form();
854
855 $data = [
856 'entry[url]' => $url,
857 ];
858
859 $client->submit($form, $data);
860
861 $this->assertEquals(302, $client->getResponse()->getStatusCode());
862
863 $em = $client->getContainer()
864 ->get('doctrine.orm.entity_manager');
865
866 $entry = $em
867 ->getRepository('WallabagCoreBundle:Entry')
868 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
869
870 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
871 $this->assertEquals($url, $entry->getUrl());
872 $this->assertContains('Perpignan', $entry->getTitle());
873 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
874
875 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
876 }
877
878 /**
879 * @depends testNewEntryWithDownloadImagesEnabled
880 */
881 public function testRemoveEntryWithDownloadImagesEnabled()
882 {
883 $this->logInAs('admin');
884 $client = $this->getClient();
885
886 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
887 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
888
889 $content = $client->getContainer()
890 ->get('doctrine.orm.entity_manager')
891 ->getRepository('WallabagCoreBundle:Entry')
892 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
893
894 $client->request('GET', '/delete/'.$content->getId());
895
896 $this->assertEquals(302, $client->getResponse()->getStatusCode());
897
898 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
899 }
900
901 public function testRedirectToHomepage()
902 {
903 $this->logInAs('empty');
904 $client = $this->getClient();
905
906 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
907 $user = $em
908 ->getRepository('WallabagUserBundle:User')
909 ->find($this->getLoggedInUserId());
910
911 if (!$user) {
912 $this->markTestSkipped('No user found in db.');
913 }
914
915 // Redirect to homepage
916 $config = $user->getConfig();
917 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
918 $em->persist($config);
919 $em->flush();
920
921 $content = $client->getContainer()
922 ->get('doctrine.orm.entity_manager')
923 ->getRepository('WallabagCoreBundle:Entry')
924 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
925
926 $client->request('GET', '/view/'.$content->getId());
927 $client->request('GET', '/archive/'.$content->getId());
928
929 $this->assertEquals(302, $client->getResponse()->getStatusCode());
930 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
931 }
932
933 public function testRedirectToCurrentPage()
934 {
935 $this->logInAs('empty');
936 $client = $this->getClient();
937
938 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
939 $user = $em
940 ->getRepository('WallabagUserBundle:User')
941 ->find($this->getLoggedInUserId());
942
943 if (!$user) {
944 $this->markTestSkipped('No user found in db.');
945 }
946
947 // Redirect to current page
948 $config = $user->getConfig();
949 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
950 $em->persist($config);
951 $em->flush();
952
953 $content = $client->getContainer()
954 ->get('doctrine.orm.entity_manager')
955 ->getRepository('WallabagCoreBundle:Entry')
956 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
957
958 $client->request('GET', '/view/'.$content->getId());
959 $client->request('GET', '/archive/'.$content->getId());
960
961 $this->assertEquals(302, $client->getResponse()->getStatusCode());
962 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location'));
963 }
964
965 public function testFilterOnHttpStatus()
966 {
967 $this->logInAs('admin');
968 $client = $this->getClient();
969
970 $crawler = $client->request('GET', '/new');
971 $form = $crawler->filter('form[name=entry]')->form();
972
973 $data = [
974 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
975 ];
976
977 $client->submit($form, $data);
978
979 $crawler = $client->request('GET', '/all/list');
980 $form = $crawler->filter('button[id=submit-filter]')->form();
981
982 $data = [
983 'entry_filter[httpStatus]' => 404,
984 ];
985
986 $crawler = $client->submit($form, $data);
987
988 $this->assertCount(1, $crawler->filter('div[class=entry]'));
989
990 $crawler = $client->request('GET', '/new');
991 $form = $crawler->filter('form[name=entry]')->form();
992
993 $data = [
994 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm',
995 ];
996
997 $client->submit($form, $data);
998
999 $crawler = $client->request('GET', '/all/list');
1000 $form = $crawler->filter('button[id=submit-filter]')->form();
1001
1002 $data = [
1003 'entry_filter[httpStatus]' => 200,
1004 ];
1005
1006 $crawler = $client->submit($form, $data);
1007
1008 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1009
1010 $crawler = $client->request('GET', '/all/list');
1011 $form = $crawler->filter('button[id=submit-filter]')->form();
1012
1013 $data = [
1014 'entry_filter[httpStatus]' => 1024,
1015 ];
1016
1017 $crawler = $client->submit($form, $data);
1018
1019 $this->assertCount(7, $crawler->filter('div[class=entry]'));
1020 }
839} 1021}