aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php74
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php80
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php51
3 files changed, 192 insertions, 13 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 409a8291..19fb5170 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -298,7 +298,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
298 $entry = $this->client->getContainer() 298 $entry = $this->client->getContainer()
299 ->get('doctrine.orm.entity_manager') 299 ->get('doctrine.orm.entity_manager')
300 ->getRepository('WallabagCoreBundle:Entry') 300 ->getRepository('WallabagCoreBundle:Entry')
301 ->findOneByUser(1); 301 ->findOneByUser(1, ['id' => 'asc']);
302 302
303 if (!$entry) { 303 if (!$entry) {
304 $this->markTestSkipped('No content found in db.'); 304 $this->markTestSkipped('No content found in db.');
@@ -642,7 +642,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
642 642
643 $content = json_decode($this->client->getResponse()->getContent(), true); 643 $content = json_decode($this->client->getResponse()->getContent(), true);
644 644
645 $this->assertEquals(true, $content['exists']); 645 $this->assertEquals(2, $content['exists']);
646 } 646 }
647 647
648 public function testGetEntriesExistsWithManyUrls() 648 public function testGetEntriesExistsWithManyUrls()
@@ -657,7 +657,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
657 657
658 $this->assertArrayHasKey($url1, $content); 658 $this->assertArrayHasKey($url1, $content);
659 $this->assertArrayHasKey($url2, $content); 659 $this->assertArrayHasKey($url2, $content);
660 $this->assertEquals(true, $content[$url1]); 660 $this->assertEquals(2, $content[$url1]);
661 $this->assertEquals(false, $content[$url2]); 661 $this->assertEquals(false, $content[$url2]);
662 } 662 }
663 663
@@ -714,4 +714,72 @@ class EntryRestControllerTest extends WallabagApiTestCase
714 714
715 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 715 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
716 } 716 }
717
718 public function testPostEntriesTagsListAction()
719 {
720 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
721 ->getRepository('WallabagCoreBundle:Entry')
722 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
723
724 $tags = $entry->getTags();
725
726 $this->assertCount(2, $tags);
727
728 $list = [
729 [
730 'url' => 'http://0.0.0.0/entry4',
731 'tags' => 'new tag 1, new tag 2',
732 ],
733 ];
734
735 $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list));
736
737 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
738
739 $content = json_decode($this->client->getResponse()->getContent(), true);
740
741 $this->assertInternalType('int', $content[0]['entry']);
742 $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']);
743
744 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
745 ->getRepository('WallabagCoreBundle:Entry')
746 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
747
748 $tags = $entry->getTags();
749 $this->assertCount(4, $tags);
750 }
751
752 public function testDeleteEntriesTagsListAction()
753 {
754 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
755 ->getRepository('WallabagCoreBundle:Entry')
756 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
757
758 $tags = $entry->getTags();
759
760 $this->assertCount(4, $tags);
761
762 $list = [
763 [
764 'url' => 'http://0.0.0.0/entry4',
765 'tags' => 'new tag 1, new tag 2',
766 ],
767 ];
768
769 $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list));
770
771 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
772
773 $content = json_decode($this->client->getResponse()->getContent(), true);
774
775 $this->assertInternalType('int', $content[0]['entry']);
776 $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']);
777
778 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
779 ->getRepository('WallabagCoreBundle:Entry')
780 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
781
782 $tags = $entry->getTags();
783 $this->assertCount(2, $tags);
784 }
717} 785}
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index beb0598a..35888f16 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -798,11 +798,87 @@ class ConfigControllerTest extends WallabagCoreTestCase
798 798
799 $entryReset = $em 799 $entryReset = $em
800 ->getRepository('WallabagCoreBundle:Entry') 800 ->getRepository('WallabagCoreBundle:Entry')
801 ->countAllEntriesByUsername($user->getId()); 801 ->countAllEntriesByUser($user->getId());
802 802
803 $this->assertEquals(0, $entryReset, 'Entries were reset'); 803 $this->assertEquals(0, $entryReset, 'Entries were reset');
804 } 804 }
805 805
806 public function testResetArchivedEntries()
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 $tagArchived = new Tag();
834 $tagArchived->setLabel('super');
835 $em->persist($tagArchived);
836
837 $entryArchived = new Entry($user);
838 $entryArchived->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
839 $entryArchived->setContent('Youhou');
840 $entryArchived->setTitle('Youhou');
841 $entryArchived->addTag($tagArchived);
842 $entryArchived->setArchived(true);
843 $em->persist($entryArchived);
844
845 $annotationArchived = new Annotation($user);
846 $annotationArchived->setText('annotated');
847 $annotationArchived->setQuote('annotated');
848 $annotationArchived->setRanges([]);
849 $annotationArchived->setEntry($entryArchived);
850 $em->persist($annotationArchived);
851
852 $em->flush();
853
854 $crawler = $client->request('GET', '/config#set3');
855
856 $this->assertEquals(200, $client->getResponse()->getStatusCode());
857
858 $crawler = $client->click($crawler->selectLink('config.reset.archived')->link());
859
860 $this->assertEquals(302, $client->getResponse()->getStatusCode());
861 $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
862
863 $entryReset = $em
864 ->getRepository('WallabagCoreBundle:Entry')
865 ->countAllEntriesByUser($user->getId());
866
867 $this->assertEquals(1, $entryReset, 'Entries were reset');
868
869 $tagReset = $em
870 ->getRepository('WallabagCoreBundle:Tag')
871 ->countAllTags($user->getId());
872
873 $this->assertEquals(1, $tagReset, 'Tags were reset');
874
875 $annotationsReset = $em
876 ->getRepository('WallabagAnnotationBundle:Annotation')
877 ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId());
878
879 $this->assertEmpty($annotationsReset, 'Annotations were reset');
880 }
881
806 public function testResetEntriesCascade() 882 public function testResetEntriesCascade()
807 { 883 {
808 $this->logInAs('empty'); 884 $this->logInAs('empty');
@@ -843,7 +919,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
843 919
844 $entryReset = $em 920 $entryReset = $em
845 ->getRepository('WallabagCoreBundle:Entry') 921 ->getRepository('WallabagCoreBundle:Entry')
846 ->countAllEntriesByUsername($user->getId()); 922 ->countAllEntriesByUser($user->getId());
847 923
848 $this->assertEquals(0, $entryReset, 'Entries were reset'); 924 $this->assertEquals(0, $entryReset, 'Entries were reset');
849 925
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 3eb6d47f..d26a56f8 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -135,9 +135,44 @@ class EntryControllerTest extends WallabagCoreTestCase
135 ->getRepository('WallabagCoreBundle:Entry') 135 ->getRepository('WallabagCoreBundle:Entry')
136 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 136 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
137 137
138 $author = $content->getPublishedBy();
139
138 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); 140 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
139 $this->assertEquals($this->url, $content->getUrl()); 141 $this->assertEquals($this->url, $content->getUrl());
140 $this->assertContains('Google', $content->getTitle()); 142 $this->assertContains('Google', $content->getTitle());
143 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
144 $this->assertEquals('Morgane Tual', $author[0]);
145 }
146
147 public function testPostWithMultipleAuthors()
148 {
149 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
150 $this->logInAs('admin');
151 $client = $this->getClient();
152
153 $crawler = $client->request('GET', '/new');
154
155 $this->assertEquals(200, $client->getResponse()->getStatusCode());
156
157 $form = $crawler->filter('form[name=entry]')->form();
158
159 $data = [
160 'entry[url]' => $url,
161 ];
162
163 $client->submit($form, $data);
164
165 $this->assertEquals(302, $client->getResponse()->getStatusCode());
166
167 $content = $client->getContainer()
168 ->get('doctrine.orm.entity_manager')
169 ->getRepository('WallabagCoreBundle:Entry')
170 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
171
172 $authors = $content->getPublishedBy();
173 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
174 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
175 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
141 } 176 }
142 177
143 public function testPostNewOkUrlExist() 178 public function testPostNewOkUrlExist()
@@ -606,7 +641,7 @@ class EntryControllerTest extends WallabagCoreTestCase
606 641
607 $crawler = $client->submit($form, $data); 642 $crawler = $client->submit($form, $data);
608 643
609 $this->assertCount(2, $crawler->filter('div[class=entry]')); 644 $this->assertCount(3, $crawler->filter('div[class=entry]'));
610 } 645 }
611 646
612 public function testFilterOnReadingTimeOnlyLower() 647 public function testFilterOnReadingTimeOnlyLower()
@@ -642,7 +677,7 @@ class EntryControllerTest extends WallabagCoreTestCase
642 677
643 $crawler = $client->submit($form, $data); 678 $crawler = $client->submit($form, $data);
644 679
645 $this->assertCount(4, $crawler->filter('div[class=entry]')); 680 $this->assertCount(5, $crawler->filter('div[class=entry]'));
646 } 681 }
647 682
648 public function testFilterOnCreationDate() 683 public function testFilterOnCreationDate()
@@ -661,7 +696,7 @@ class EntryControllerTest extends WallabagCoreTestCase
661 696
662 $crawler = $client->submit($form, $data); 697 $crawler = $client->submit($form, $data);
663 698
664 $this->assertCount(5, $crawler->filter('div[class=entry]')); 699 $this->assertCount(6, $crawler->filter('div[class=entry]'));
665 700
666 $data = [ 701 $data = [
667 'entry_filter[createdAt][left_date]' => date('d/m/Y'), 702 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
@@ -670,7 +705,7 @@ class EntryControllerTest extends WallabagCoreTestCase
670 705
671 $crawler = $client->submit($form, $data); 706 $crawler = $client->submit($form, $data);
672 707
673 $this->assertCount(5, $crawler->filter('div[class=entry]')); 708 $this->assertCount(6, $crawler->filter('div[class=entry]'));
674 709
675 $data = [ 710 $data = [
676 'entry_filter[createdAt][left_date]' => '01/01/1970', 711 'entry_filter[createdAt][left_date]' => '01/01/1970',
@@ -774,7 +809,7 @@ class EntryControllerTest extends WallabagCoreTestCase
774 $form['entry_filter[previewPicture]']->tick(); 809 $form['entry_filter[previewPicture]']->tick();
775 810
776 $crawler = $client->submit($form); 811 $crawler = $client->submit($form);
777 $this->assertCount(1, $crawler->filter('div[class=entry]')); 812 $this->assertCount(2, $crawler->filter('div[class=entry]'));
778 } 813 }
779 814
780 public function testFilterOnLanguage() 815 public function testFilterOnLanguage()
@@ -789,7 +824,7 @@ class EntryControllerTest extends WallabagCoreTestCase
789 ]; 824 ];
790 825
791 $crawler = $client->submit($form, $data); 826 $crawler = $client->submit($form, $data);
792 $this->assertCount(2, $crawler->filter('div[class=entry]')); 827 $this->assertCount(3, $crawler->filter('div[class=entry]'));
793 828
794 $form = $crawler->filter('button[id=submit-filter]')->form(); 829 $form = $crawler->filter('button[id=submit-filter]')->form();
795 $data = [ 830 $data = [
@@ -1014,7 +1049,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1014 1049
1015 $crawler = $client->submit($form, $data); 1050 $crawler = $client->submit($form, $data);
1016 1051
1017 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1052 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1018 1053
1019 $crawler = $client->request('GET', '/all/list'); 1054 $crawler = $client->request('GET', '/all/list');
1020 $form = $crawler->filter('button[id=submit-filter]')->form(); 1055 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1025,7 +1060,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1025 1060
1026 $crawler = $client->submit($form, $data); 1061 $crawler = $client->submit($form, $data);
1027 1062
1028 $this->assertCount(7, $crawler->filter('div[class=entry]')); 1063 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1029 } 1064 }
1030 1065
1031 public function testSearch() 1066 public function testSearch()