aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php108
-rw-r--r--tests/Wallabag/CoreBundle/Command/ExportCommandTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php12
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php80
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php60
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php42
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php27
10 files changed, 304 insertions, 41 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php
new file mode 100644
index 00000000..e6e57f30
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php
@@ -0,0 +1,108 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Wallabag\CoreBundle\Command\CleanDuplicatesCommand;
8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
9use Wallabag\CoreBundle\Entity\Entry;
10
11class CleanDuplicatesCommandTest extends WallabagCoreTestCase
12{
13 public function testRunCleanDuplicates()
14 {
15 $application = new Application($this->getClient()->getKernel());
16 $application->add(new CleanDuplicatesCommand());
17
18 $command = $application->find('wallabag:clean-duplicates');
19
20 $tester = new CommandTester($command);
21 $tester->execute([
22 'command' => $command->getName(),
23 ]);
24
25 $this->assertContains('Cleaning through 3 user accounts', $tester->getDisplay());
26 $this->assertContains('Finished cleaning. 0 duplicates found in total', $tester->getDisplay());
27 }
28
29 public function testRunCleanDuplicatesCommandWithBadUsername()
30 {
31 $application = new Application($this->getClient()->getKernel());
32 $application->add(new CleanDuplicatesCommand());
33
34 $command = $application->find('wallabag:clean-duplicates');
35
36 $tester = new CommandTester($command);
37 $tester->execute([
38 'command' => $command->getName(),
39 'username' => 'unknown',
40 ]);
41
42 $this->assertContains('User "unknown" not found', $tester->getDisplay());
43 }
44
45 public function testRunCleanDuplicatesCommandForUser()
46 {
47 $application = new Application($this->getClient()->getKernel());
48 $application->add(new CleanDuplicatesCommand());
49
50 $command = $application->find('wallabag:clean-duplicates');
51
52 $tester = new CommandTester($command);
53 $tester->execute([
54 'command' => $command->getName(),
55 'username' => 'admin',
56 ]);
57
58 $this->assertContains('Cleaned 0 duplicates for user admin', $tester->getDisplay());
59 }
60
61 public function testDuplicate()
62 {
63 $url = 'http://www.lemonde.fr/sport/visuel/2017/05/05/rondelle-prison-blanchissage-comprendre-le-hockey-sur-glace_5122587_3242.html';
64 $client = $this->getClient();
65 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
66
67 $this->logInAs('admin');
68
69 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
70 $this->assertCount(0, $nbEntries);
71
72 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId());
73
74 $entry1 = new Entry($user);
75 $entry1->setUrl($url);
76
77 $entry2 = new Entry($user);
78 $entry2->setUrl($url);
79
80 $em->persist($entry1);
81 $em->persist($entry2);
82
83 $em->flush();
84
85 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
86 $this->assertCount(2, $nbEntries);
87
88 $application = new Application($this->getClient()->getKernel());
89 $application->add(new CleanDuplicatesCommand());
90
91 $command = $application->find('wallabag:clean-duplicates');
92
93 $tester = new CommandTester($command);
94 $tester->execute([
95 'command' => $command->getName(),
96 'username' => 'admin',
97 ]);
98
99 $this->assertContains('Cleaned 1 duplicates for user admin', $tester->getDisplay());
100
101 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
102 $this->assertCount(1, $nbEntries);
103
104 $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url');
105 $query->setParameter('url', $url);
106 $query->execute();
107 }
108}
diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
index 6798c5d7..b21f3318 100644
--- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
@@ -70,7 +70,7 @@ class ExportCommandTest extends WallabagCoreTestCase
70 $tester->execute([ 70 $tester->execute([
71 'command' => $command->getName(), 71 'command' => $command->getName(),
72 'username' => 'admin', 72 'username' => 'admin',
73 'filepath' => 'specialexport.json' 73 'filepath' => 'specialexport.json',
74 ]); 74 ]);
75 75
76 $this->assertFileExists('specialexport.json'); 76 $this->assertFileExists('specialexport.json');
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index 1bfd41d5..122a87d4 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -87,6 +87,7 @@ class InstallCommandTest extends WallabagCoreTestCase
87 $this->assertContains('Setting up database.', $tester->getDisplay()); 87 $this->assertContains('Setting up database.', $tester->getDisplay());
88 $this->assertContains('Administration setup.', $tester->getDisplay()); 88 $this->assertContains('Administration setup.', $tester->getDisplay());
89 $this->assertContains('Config setup.', $tester->getDisplay()); 89 $this->assertContains('Config setup.', $tester->getDisplay());
90 $this->assertContains('Run migrations.', $tester->getDisplay());
90 } 91 }
91 92
92 public function testRunInstallCommandWithReset() 93 public function testRunInstallCommandWithReset()
@@ -115,12 +116,13 @@ class InstallCommandTest extends WallabagCoreTestCase
115 116
116 $this->assertContains('Checking system requirements.', $tester->getDisplay()); 117 $this->assertContains('Checking system requirements.', $tester->getDisplay());
117 $this->assertContains('Setting up database.', $tester->getDisplay()); 118 $this->assertContains('Setting up database.', $tester->getDisplay());
118 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); 119 $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
119 $this->assertContains('Administration setup.', $tester->getDisplay()); 120 $this->assertContains('Administration setup.', $tester->getDisplay());
120 $this->assertContains('Config setup.', $tester->getDisplay()); 121 $this->assertContains('Config setup.', $tester->getDisplay());
122 $this->assertContains('Run migrations.', $tester->getDisplay());
121 123
122 // we force to reset everything 124 // we force to reset everything
123 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); 125 $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
124 } 126 }
125 127
126 public function testRunInstallCommandWithDatabaseRemoved() 128 public function testRunInstallCommandWithDatabaseRemoved()
@@ -168,6 +170,7 @@ class InstallCommandTest extends WallabagCoreTestCase
168 $this->assertContains('Setting up database.', $tester->getDisplay()); 170 $this->assertContains('Setting up database.', $tester->getDisplay());
169 $this->assertContains('Administration setup.', $tester->getDisplay()); 171 $this->assertContains('Administration setup.', $tester->getDisplay());
170 $this->assertContains('Config setup.', $tester->getDisplay()); 172 $this->assertContains('Config setup.', $tester->getDisplay());
173 $this->assertContains('Run migrations.', $tester->getDisplay());
171 174
172 // the current database doesn't already exist 175 // the current database doesn't already exist
173 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); 176 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
@@ -205,8 +208,9 @@ class InstallCommandTest extends WallabagCoreTestCase
205 $this->assertContains('Setting up database.', $tester->getDisplay()); 208 $this->assertContains('Setting up database.', $tester->getDisplay());
206 $this->assertContains('Administration setup.', $tester->getDisplay()); 209 $this->assertContains('Administration setup.', $tester->getDisplay());
207 $this->assertContains('Config setup.', $tester->getDisplay()); 210 $this->assertContains('Config setup.', $tester->getDisplay());
211 $this->assertContains('Run migrations.', $tester->getDisplay());
208 212
209 $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); 213 $this->assertContains('Dropping schema and creating schema', $tester->getDisplay());
210 } 214 }
211 215
212 public function testRunInstallCommandChooseNothing() 216 public function testRunInstallCommandChooseNothing()
@@ -259,6 +263,7 @@ class InstallCommandTest extends WallabagCoreTestCase
259 $this->assertContains('Setting up database.', $tester->getDisplay()); 263 $this->assertContains('Setting up database.', $tester->getDisplay());
260 $this->assertContains('Administration setup.', $tester->getDisplay()); 264 $this->assertContains('Administration setup.', $tester->getDisplay());
261 $this->assertContains('Config setup.', $tester->getDisplay()); 265 $this->assertContains('Config setup.', $tester->getDisplay());
266 $this->assertContains('Run migrations.', $tester->getDisplay());
262 267
263 $this->assertContains('Creating schema', $tester->getDisplay()); 268 $this->assertContains('Creating schema', $tester->getDisplay());
264 } 269 }
@@ -291,5 +296,6 @@ class InstallCommandTest extends WallabagCoreTestCase
291 $this->assertContains('Setting up database.', $tester->getDisplay()); 296 $this->assertContains('Setting up database.', $tester->getDisplay());
292 $this->assertContains('Administration setup.', $tester->getDisplay()); 297 $this->assertContains('Administration setup.', $tester->getDisplay());
293 $this->assertContains('Config setup.', $tester->getDisplay()); 298 $this->assertContains('Config setup.', $tester->getDisplay());
299 $this->assertContains('Run migrations.', $tester->getDisplay());
294 } 300 }
295} 301}
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 7db4cf1f..19c8698e 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -135,9 +135,45 @@ 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 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
146 }
147
148 public function testPostWithMultipleAuthors()
149 {
150 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
151 $this->logInAs('admin');
152 $client = $this->getClient();
153
154 $crawler = $client->request('GET', '/new');
155
156 $this->assertEquals(200, $client->getResponse()->getStatusCode());
157
158 $form = $crawler->filter('form[name=entry]')->form();
159
160 $data = [
161 'entry[url]' => $url,
162 ];
163
164 $client->submit($form, $data);
165
166 $this->assertEquals(302, $client->getResponse()->getStatusCode());
167
168 $content = $client->getContainer()
169 ->get('doctrine.orm.entity_manager')
170 ->getRepository('WallabagCoreBundle:Entry')
171 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
172
173 $authors = $content->getPublishedBy();
174 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
175 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
176 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
141 } 177 }
142 178
143 public function testPostNewOkUrlExist() 179 public function testPostNewOkUrlExist()
@@ -235,7 +271,7 @@ class EntryControllerTest extends WallabagCoreTestCase
235 ->findOneByUrl($url); 271 ->findOneByUrl($url);
236 $tags = $entry->getTags(); 272 $tags = $entry->getTags();
237 273
238 $this->assertCount(1, $tags); 274 $this->assertCount(2, $tags);
239 $this->assertEquals('wallabag', $tags[0]->getLabel()); 275 $this->assertEquals('wallabag', $tags[0]->getLabel());
240 276
241 $em->remove($entry); 277 $em->remove($entry);
@@ -264,8 +300,8 @@ class EntryControllerTest extends WallabagCoreTestCase
264 300
265 $tags = $entry->getTags(); 301 $tags = $entry->getTags();
266 302
267 $this->assertCount(1, $tags); 303 $this->assertCount(2, $tags);
268 $this->assertEquals('wallabag', $tags[0]->getLabel()); 304 $this->assertEquals('wallabag', $tags[1]->getLabel());
269 305
270 $em->remove($entry); 306 $em->remove($entry);
271 $em->flush(); 307 $em->flush();
@@ -626,7 +662,7 @@ class EntryControllerTest extends WallabagCoreTestCase
626 662
627 $crawler = $client->submit($form, $data); 663 $crawler = $client->submit($form, $data);
628 664
629 $this->assertCount(2, $crawler->filter('div[class=entry]')); 665 $this->assertCount(3, $crawler->filter('div[class=entry]'));
630 } 666 }
631 667
632 public function testFilterOnReadingTimeOnlyLower() 668 public function testFilterOnReadingTimeOnlyLower()
@@ -662,7 +698,7 @@ class EntryControllerTest extends WallabagCoreTestCase
662 698
663 $crawler = $client->submit($form, $data); 699 $crawler = $client->submit($form, $data);
664 700
665 $this->assertCount(4, $crawler->filter('div[class=entry]')); 701 $this->assertCount(5, $crawler->filter('div[class=entry]'));
666 } 702 }
667 703
668 public function testFilterOnCreationDate() 704 public function testFilterOnCreationDate()
@@ -681,7 +717,7 @@ class EntryControllerTest extends WallabagCoreTestCase
681 717
682 $crawler = $client->submit($form, $data); 718 $crawler = $client->submit($form, $data);
683 719
684 $this->assertCount(5, $crawler->filter('div[class=entry]')); 720 $this->assertCount(6, $crawler->filter('div[class=entry]'));
685 721
686 $data = [ 722 $data = [
687 'entry_filter[createdAt][left_date]' => date('d/m/Y'), 723 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
@@ -690,7 +726,7 @@ class EntryControllerTest extends WallabagCoreTestCase
690 726
691 $crawler = $client->submit($form, $data); 727 $crawler = $client->submit($form, $data);
692 728
693 $this->assertCount(5, $crawler->filter('div[class=entry]')); 729 $this->assertCount(6, $crawler->filter('div[class=entry]'));
694 730
695 $data = [ 731 $data = [
696 'entry_filter[createdAt][left_date]' => '01/01/1970', 732 'entry_filter[createdAt][left_date]' => '01/01/1970',
@@ -794,7 +830,7 @@ class EntryControllerTest extends WallabagCoreTestCase
794 $form['entry_filter[previewPicture]']->tick(); 830 $form['entry_filter[previewPicture]']->tick();
795 831
796 $crawler = $client->submit($form); 832 $crawler = $client->submit($form);
797 $this->assertCount(1, $crawler->filter('div[class=entry]')); 833 $this->assertCount(2, $crawler->filter('div[class=entry]'));
798 } 834 }
799 835
800 public function testFilterOnLanguage() 836 public function testFilterOnLanguage()
@@ -809,7 +845,7 @@ class EntryControllerTest extends WallabagCoreTestCase
809 ]; 845 ];
810 846
811 $crawler = $client->submit($form, $data); 847 $crawler = $client->submit($form, $data);
812 $this->assertCount(2, $crawler->filter('div[class=entry]')); 848 $this->assertCount(3, $crawler->filter('div[class=entry]'));
813 849
814 $form = $crawler->filter('button[id=submit-filter]')->form(); 850 $form = $crawler->filter('button[id=submit-filter]')->form();
815 $data = [ 851 $data = [
@@ -899,7 +935,7 @@ class EntryControllerTest extends WallabagCoreTestCase
899 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); 935 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
900 $this->assertEquals($url, $entry->getUrl()); 936 $this->assertEquals($url, $entry->getUrl());
901 $this->assertContains('Perpignan', $entry->getTitle()); 937 $this->assertContains('Perpignan', $entry->getTitle());
902 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); 938 $this->assertContains('/c4789a7f.jpeg', $entry->getContent());
903 939
904 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); 940 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
905 } 941 }
@@ -1034,7 +1070,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1034 1070
1035 $crawler = $client->submit($form, $data); 1071 $crawler = $client->submit($form, $data);
1036 1072
1037 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1073 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1038 1074
1039 $crawler = $client->request('GET', '/all/list'); 1075 $crawler = $client->request('GET', '/all/list');
1040 $form = $crawler->filter('button[id=submit-filter]')->form(); 1076 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1045,7 +1081,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1045 1081
1046 $crawler = $client->submit($form, $data); 1082 $crawler = $client->submit($form, $data);
1047 1083
1048 $this->assertCount(7, $crawler->filter('div[class=entry]')); 1084 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1049 } 1085 }
1050 1086
1051 public function testSearch() 1087 public function testSearch()
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 32a18e26..63f2c829 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -189,11 +189,9 @@ class ExportControllerTest extends WallabagCoreTestCase
189 $this->assertContains($contentInDB[0]['language'], $csv[1]); 189 $this->assertContains($contentInDB[0]['language'], $csv[1]);
190 $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); 190 $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]);
191 191
192 $expectedTag = [];
193 foreach ($contentInDB[0]['tags'] as $tag) { 192 foreach ($contentInDB[0]['tags'] as $tag) {
194 $expectedTag[] = $tag['label']; 193 $this->assertContains($tag['label'], $csv[1]);
195 } 194 }
196 $this->assertContains(implode(', ', $expectedTag), $csv[1]);
197 } 195 }
198 196
199 public function testJsonExport() 197 public function testJsonExport()
@@ -241,7 +239,7 @@ class ExportControllerTest extends WallabagCoreTestCase
241 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); 239 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']);
242 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); 240 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']);
243 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); 241 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']);
244 $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']); 242 $this->assertEquals(['foo bar', 'baz', 'foot'], $content[0]['tags']);
245 } 243 }
246 244
247 public function testXmlExport() 245 public function testXmlExport()
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index fa1a3539..c3b22dcd 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -46,7 +46,7 @@ class TagControllerTest extends WallabagCoreTestCase
46 ->getRepository('WallabagCoreBundle:Entry') 46 ->getRepository('WallabagCoreBundle:Entry')
47 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); 47 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
48 48
49 $this->assertEquals(3, count($entry->getTags())); 49 $this->assertEquals(4, count($entry->getTags()));
50 50
51 // tag already exists and already assigned 51 // tag already exists and already assigned
52 $client->submit($form, $data); 52 $client->submit($form, $data);
@@ -57,7 +57,7 @@ class TagControllerTest extends WallabagCoreTestCase
57 ->getRepository('WallabagCoreBundle:Entry') 57 ->getRepository('WallabagCoreBundle:Entry')
58 ->find($entry->getId()); 58 ->find($entry->getId());
59 59
60 $this->assertEquals(3, count($newEntry->getTags())); 60 $this->assertEquals(4, count($newEntry->getTags()));
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 = [
@@ -72,7 +72,7 @@ class TagControllerTest extends WallabagCoreTestCase
72 ->getRepository('WallabagCoreBundle:Entry') 72 ->getRepository('WallabagCoreBundle:Entry')
73 ->find($entry->getId()); 73 ->find($entry->getId());
74 74
75 $this->assertEquals(3, count($newEntry->getTags())); 75 $this->assertEquals(4, count($newEntry->getTags()));
76 } 76 }
77 77
78 public function testAddMultipleTagToEntry() 78 public function testAddMultipleTagToEntry()
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
index aee67259..8b50bce9 100644
--- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
+++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
@@ -2,6 +2,8 @@
2 2
3namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; 3namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator;
4 4
5use Monolog\Handler\TestHandler;
6use Monolog\Logger;
5use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; 7use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
6use Graby\SiteConfig\SiteConfig as GrabySiteConfig; 8use Graby\SiteConfig\SiteConfig as GrabySiteConfig;
7use PHPUnit_Framework_TestCase; 9use PHPUnit_Framework_TestCase;
@@ -24,7 +26,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
24 $grabySiteConfig->login_uri = 'http://example.com/login'; 26 $grabySiteConfig->login_uri = 'http://example.com/login';
25 $grabySiteConfig->login_username_field = 'login'; 27 $grabySiteConfig->login_username_field = 'login';
26 $grabySiteConfig->login_password_field = 'password'; 28 $grabySiteConfig->login_password_field = 'password';
27 $grabySiteConfig->login_extra_fields = ['field' => 'value']; 29 $grabySiteConfig->login_extra_fields = ['field=value'];
28 $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; 30 $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
29 31
30 $grabyConfigBuilderMock 32 $grabyConfigBuilderMock
@@ -32,14 +34,19 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
32 ->with('example.com') 34 ->with('example.com')
33 ->will($this->returnValue($grabySiteConfig)); 35 ->will($this->returnValue($grabySiteConfig));
34 36
37 $logger = new Logger('foo');
38 $handler = new TestHandler();
39 $logger->pushHandler($handler);
40
35 $this->builder = new GrabySiteConfigBuilder( 41 $this->builder = new GrabySiteConfigBuilder(
36 $grabyConfigBuilderMock, 42 $grabyConfigBuilderMock,
37 ['example.com' => ['username' => 'foo', 'password' => 'bar']] 43 ['example.com' => ['username' => 'foo', 'password' => 'bar']],
44 $logger
38 ); 45 );
39 46
40 $config = $this->builder->buildForHost('example.com'); 47 $config = $this->builder->buildForHost('example.com');
41 48
42 self::assertEquals( 49 $this->assertEquals(
43 new SiteConfig([ 50 new SiteConfig([
44 'host' => 'example.com', 51 'host' => 'example.com',
45 'requiresLogin' => true, 52 'requiresLogin' => true,
@@ -53,6 +60,10 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
53 ]), 60 ]),
54 $config 61 $config
55 ); 62 );
63
64 $records = $handler->getRecords();
65
66 $this->assertCount(1, $records, 'One log was recorded');
56 } 67 }
57 68
58 public function testBuildConfigDoesntExist() 69 public function testBuildConfigDoesntExist()
@@ -67,19 +78,22 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
67 ->with('unknown.com') 78 ->with('unknown.com')
68 ->will($this->returnValue(new GrabySiteConfig())); 79 ->will($this->returnValue(new GrabySiteConfig()));
69 80
70 $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []); 81 $logger = new Logger('foo');
82 $handler = new TestHandler();
83 $logger->pushHandler($handler);
84
85 $this->builder = new GrabySiteConfigBuilder(
86 $grabyConfigBuilderMock,
87 [],
88 $logger
89 );
71 90
72 $config = $this->builder->buildForHost('unknown.com'); 91 $config = $this->builder->buildForHost('unknown.com');
73 92
74 self::assertEquals( 93 $this->assertFalse($config);
75 new SiteConfig([ 94
76 'host' => 'unknown.com', 95 $records = $handler->getRecords();
77 'requiresLogin' => false, 96
78 'username' => null, 97 $this->assertCount(1, $records, 'One log was recorded');
79 'password' => null,
80 'extraFields' => [],
81 ]),
82 $config
83 );
84 } 98 }
85} 99}
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 5956b502..8abb1bbb 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -111,7 +111,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
111 111
112 $this->assertEquals('http://domain.io', $entry->getUrl()); 112 $this->assertEquals('http://domain.io', $entry->getUrl());
113 $this->assertEquals('my title', $entry->getTitle()); 113 $this->assertEquals('my title', $entry->getTitle());
114 $this->assertEquals($this->fetchingErrorMessage . '<p><i>But we found a short description: </i></p>desc', $entry->getContent()); 114 $this->assertEquals($this->fetchingErrorMessage.'<p><i>But we found a short description: </i></p>desc', $entry->getContent());
115 $this->assertEmpty($entry->getPreviewPicture()); 115 $this->assertEmpty($entry->getPreviewPicture());
116 $this->assertEmpty($entry->getLanguage()); 116 $this->assertEmpty($entry->getLanguage());
117 $this->assertEmpty($entry->getHttpStatus()); 117 $this->assertEmpty($entry->getHttpStatus());
diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php
index 17b08c2a..1e21f400 100644
--- a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php
@@ -2,6 +2,8 @@
2 2
3namespace Tests\Wallabag\CoreBundle\Helper; 3namespace Tests\Wallabag\CoreBundle\Helper;
4 4
5use Monolog\Handler\TestHandler;
6use Monolog\Logger;
5use Wallabag\CoreBundle\Entity\Config; 7use Wallabag\CoreBundle\Entity\Config;
6use Wallabag\CoreBundle\Entity\Entry; 8use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\CoreBundle\Entity\Tag; 9use Wallabag\CoreBundle\Entity\Tag;
@@ -15,14 +17,19 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
15 private $tagRepository; 17 private $tagRepository;
16 private $entryRepository; 18 private $entryRepository;
17 private $tagger; 19 private $tagger;
20 private $logger;
21 private $handler;
18 22
19 public function setUp() 23 public function setUp()
20 { 24 {
21 $this->rulerz = $this->getRulerZMock(); 25 $this->rulerz = $this->getRulerZMock();
22 $this->tagRepository = $this->getTagRepositoryMock(); 26 $this->tagRepository = $this->getTagRepositoryMock();
23 $this->entryRepository = $this->getEntryRepositoryMock(); 27 $this->entryRepository = $this->getEntryRepositoryMock();
28 $this->logger = $this->getLogger();
29 $this->handler = new TestHandler();
30 $this->logger->pushHandler($this->handler);
24 31
25 $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository); 32 $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->logger);
26 } 33 }
27 34
28 public function testTagWithNoRule() 35 public function testTagWithNoRule()
@@ -32,6 +39,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
32 $this->tagger->tag($entry); 39 $this->tagger->tag($entry);
33 40
34 $this->assertTrue($entry->getTags()->isEmpty()); 41 $this->assertTrue($entry->getTags()->isEmpty());
42 $records = $this->handler->getRecords();
43 $this->assertCount(0, $records);
35 } 44 }
36 45
37 public function testTagWithNoMatchingRule() 46 public function testTagWithNoMatchingRule()
@@ -49,6 +58,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
49 $this->tagger->tag($entry); 58 $this->tagger->tag($entry);
50 59
51 $this->assertTrue($entry->getTags()->isEmpty()); 60 $this->assertTrue($entry->getTags()->isEmpty());
61 $records = $this->handler->getRecords();
62 $this->assertCount(0, $records);
52 } 63 }
53 64
54 public function testTagWithAMatchingRule() 65 public function testTagWithAMatchingRule()
@@ -70,6 +81,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
70 $tags = $entry->getTags(); 81 $tags = $entry->getTags();
71 $this->assertSame('foo', $tags[0]->getLabel()); 82 $this->assertSame('foo', $tags[0]->getLabel());
72 $this->assertSame('bar', $tags[1]->getLabel()); 83 $this->assertSame('bar', $tags[1]->getLabel());
84
85 $records = $this->handler->getRecords();
86 $this->assertCount(1, $records);
73 } 87 }
74 88
75 public function testTagWithAMixOfMatchingRules() 89 public function testTagWithAMixOfMatchingRules()
@@ -90,6 +104,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
90 104
91 $tags = $entry->getTags(); 105 $tags = $entry->getTags();
92 $this->assertSame('foo', $tags[0]->getLabel()); 106 $this->assertSame('foo', $tags[0]->getLabel());
107 $records = $this->handler->getRecords();
108 $this->assertCount(1, $records);
93 } 109 }
94 110
95 public function testWhenTheTagExists() 111 public function testWhenTheTagExists()
@@ -118,6 +134,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
118 134
119 $tags = $entry->getTags(); 135 $tags = $entry->getTags();
120 $this->assertSame($tag, $tags[0]); 136 $this->assertSame($tag, $tags[0]);
137 $records = $this->handler->getRecords();
138 $this->assertCount(1, $records);
121 } 139 }
122 140
123 public function testSameTagWithDifferentfMatchingRules() 141 public function testSameTagWithDifferentfMatchingRules()
@@ -138,6 +156,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
138 156
139 $tags = $entry->getTags(); 157 $tags = $entry->getTags();
140 $this->assertCount(1, $tags); 158 $this->assertCount(1, $tags);
159 $records = $this->handler->getRecords();
160 $this->assertCount(2, $records);
141 } 161 }
142 162
143 public function testTagAllEntriesForAUser() 163 public function testTagAllEntriesForAUser()
@@ -209,4 +229,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
209 ->disableOriginalConstructor() 229 ->disableOriginalConstructor()
210 ->getMock(); 230 ->getMock();
211 } 231 }
232
233 private function getLogger()
234 {
235 return new Logger('foo');
236 }
212} 237}