diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 79 |
1 files changed, 67 insertions, 12 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 7db4cf1f..116e5f32 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -8,8 +8,24 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
8 | 8 | ||
9 | class EntryControllerTest extends WallabagCoreTestCase | 9 | class EntryControllerTest extends WallabagCoreTestCase |
10 | { | 10 | { |
11 | public $downloadImagesEnabled = false; | ||
11 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; | 12 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; |
12 | 13 | ||
14 | /** | ||
15 | * @after | ||
16 | * | ||
17 | * Ensure download_images_enabled is disabled after each script | ||
18 | */ | ||
19 | public function tearDownImagesEnabled() | ||
20 | { | ||
21 | if ($this->downloadImagesEnabled) { | ||
22 | $client = static::createClient(); | ||
23 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | ||
24 | |||
25 | $this->downloadImagesEnabled = false; | ||
26 | } | ||
27 | } | ||
28 | |||
13 | public function testLogin() | 29 | public function testLogin() |
14 | { | 30 | { |
15 | $client = $this->getClient(); | 31 | $client = $this->getClient(); |
@@ -135,9 +151,45 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
135 | ->getRepository('WallabagCoreBundle:Entry') | 151 | ->getRepository('WallabagCoreBundle:Entry') |
136 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 152 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
137 | 153 | ||
154 | $author = $content->getPublishedBy(); | ||
155 | |||
138 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 156 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
139 | $this->assertEquals($this->url, $content->getUrl()); | 157 | $this->assertEquals($this->url, $content->getUrl()); |
140 | $this->assertContains('Google', $content->getTitle()); | 158 | $this->assertContains('Google', $content->getTitle()); |
159 | $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
160 | $this->assertEquals('Morgane Tual', $author[0]); | ||
161 | $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); | ||
162 | } | ||
163 | |||
164 | public function testPostWithMultipleAuthors() | ||
165 | { | ||
166 | $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | ||
167 | $this->logInAs('admin'); | ||
168 | $client = $this->getClient(); | ||
169 | |||
170 | $crawler = $client->request('GET', '/new'); | ||
171 | |||
172 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
173 | |||
174 | $form = $crawler->filter('form[name=entry]')->form(); | ||
175 | |||
176 | $data = [ | ||
177 | 'entry[url]' => $url, | ||
178 | ]; | ||
179 | |||
180 | $client->submit($form, $data); | ||
181 | |||
182 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
183 | |||
184 | $content = $client->getContainer() | ||
185 | ->get('doctrine.orm.entity_manager') | ||
186 | ->getRepository('WallabagCoreBundle:Entry') | ||
187 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
188 | |||
189 | $authors = $content->getPublishedBy(); | ||
190 | $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
191 | $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); | ||
192 | $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); | ||
141 | } | 193 | } |
142 | 194 | ||
143 | public function testPostNewOkUrlExist() | 195 | public function testPostNewOkUrlExist() |
@@ -235,7 +287,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
235 | ->findOneByUrl($url); | 287 | ->findOneByUrl($url); |
236 | $tags = $entry->getTags(); | 288 | $tags = $entry->getTags(); |
237 | 289 | ||
238 | $this->assertCount(1, $tags); | 290 | $this->assertCount(2, $tags); |
239 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 291 | $this->assertEquals('wallabag', $tags[0]->getLabel()); |
240 | 292 | ||
241 | $em->remove($entry); | 293 | $em->remove($entry); |
@@ -264,8 +316,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
264 | 316 | ||
265 | $tags = $entry->getTags(); | 317 | $tags = $entry->getTags(); |
266 | 318 | ||
267 | $this->assertCount(1, $tags); | 319 | $this->assertCount(2, $tags); |
268 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 320 | $this->assertEquals('wallabag', $tags[1]->getLabel()); |
269 | 321 | ||
270 | $em->remove($entry); | 322 | $em->remove($entry); |
271 | $em->flush(); | 323 | $em->flush(); |
@@ -626,7 +678,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
626 | 678 | ||
627 | $crawler = $client->submit($form, $data); | 679 | $crawler = $client->submit($form, $data); |
628 | 680 | ||
629 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 681 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
630 | } | 682 | } |
631 | 683 | ||
632 | public function testFilterOnReadingTimeOnlyLower() | 684 | public function testFilterOnReadingTimeOnlyLower() |
@@ -662,7 +714,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
662 | 714 | ||
663 | $crawler = $client->submit($form, $data); | 715 | $crawler = $client->submit($form, $data); |
664 | 716 | ||
665 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 717 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
666 | } | 718 | } |
667 | 719 | ||
668 | public function testFilterOnCreationDate() | 720 | public function testFilterOnCreationDate() |
@@ -681,7 +733,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
681 | 733 | ||
682 | $crawler = $client->submit($form, $data); | 734 | $crawler = $client->submit($form, $data); |
683 | 735 | ||
684 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 736 | $this->assertCount(6, $crawler->filter('div[class=entry]')); |
685 | 737 | ||
686 | $data = [ | 738 | $data = [ |
687 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | 739 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
@@ -690,7 +742,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
690 | 742 | ||
691 | $crawler = $client->submit($form, $data); | 743 | $crawler = $client->submit($form, $data); |
692 | 744 | ||
693 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 745 | $this->assertCount(6, $crawler->filter('div[class=entry]')); |
694 | 746 | ||
695 | $data = [ | 747 | $data = [ |
696 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | 748 | 'entry_filter[createdAt][left_date]' => '01/01/1970', |
@@ -794,7 +846,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
794 | $form['entry_filter[previewPicture]']->tick(); | 846 | $form['entry_filter[previewPicture]']->tick(); |
795 | 847 | ||
796 | $crawler = $client->submit($form); | 848 | $crawler = $client->submit($form); |
797 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 849 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
798 | } | 850 | } |
799 | 851 | ||
800 | public function testFilterOnLanguage() | 852 | public function testFilterOnLanguage() |
@@ -809,7 +861,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
809 | ]; | 861 | ]; |
810 | 862 | ||
811 | $crawler = $client->submit($form, $data); | 863 | $crawler = $client->submit($form, $data); |
812 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 864 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
813 | 865 | ||
814 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 866 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
815 | $data = [ | 867 | $data = [ |
@@ -869,6 +921,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
869 | 921 | ||
870 | public function testNewEntryWithDownloadImagesEnabled() | 922 | public function testNewEntryWithDownloadImagesEnabled() |
871 | { | 923 | { |
924 | $this->downloadImagesEnabled = true; | ||
872 | $this->logInAs('admin'); | 925 | $this->logInAs('admin'); |
873 | $client = $this->getClient(); | 926 | $client = $this->getClient(); |
874 | 927 | ||
@@ -899,7 +952,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
899 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | 952 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); |
900 | $this->assertEquals($url, $entry->getUrl()); | 953 | $this->assertEquals($url, $entry->getUrl()); |
901 | $this->assertContains('Perpignan', $entry->getTitle()); | 954 | $this->assertContains('Perpignan', $entry->getTitle()); |
902 | $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); | 955 | // instead of checking for the filename (which might change) check that the image is now local |
956 | $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent()); | ||
903 | 957 | ||
904 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | 958 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
905 | } | 959 | } |
@@ -909,6 +963,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
909 | */ | 963 | */ |
910 | public function testRemoveEntryWithDownloadImagesEnabled() | 964 | public function testRemoveEntryWithDownloadImagesEnabled() |
911 | { | 965 | { |
966 | $this->downloadImagesEnabled = true; | ||
912 | $this->logInAs('admin'); | 967 | $this->logInAs('admin'); |
913 | $client = $this->getClient(); | 968 | $client = $this->getClient(); |
914 | 969 | ||
@@ -1034,7 +1089,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1034 | 1089 | ||
1035 | $crawler = $client->submit($form, $data); | 1090 | $crawler = $client->submit($form, $data); |
1036 | 1091 | ||
1037 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1092 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
1038 | 1093 | ||
1039 | $crawler = $client->request('GET', '/all/list'); | 1094 | $crawler = $client->request('GET', '/all/list'); |
1040 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1095 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1045,7 +1100,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1045 | 1100 | ||
1046 | $crawler = $client->submit($form, $data); | 1101 | $crawler = $client->submit($form, $data); |
1047 | 1102 | ||
1048 | $this->assertCount(7, $crawler->filter('div[class=entry]')); | 1103 | $this->assertCount(8, $crawler->filter('div[class=entry]')); |
1049 | } | 1104 | } |
1050 | 1105 | ||
1051 | public function testSearch() | 1106 | public function testSearch() |