aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php8
-rw-r--r--tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php9
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php53
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php15
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php35
-rw-r--r--tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php23
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php15
9 files changed, 158 insertions, 12 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index 83f5bf24..1bfd41d5 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -33,7 +33,7 @@ class InstallCommandTest extends WallabagCoreTestCase
33 } 33 }
34 34
35 /** 35 /**
36 * Ensure next tests will have a clean database 36 * Ensure next tests will have a clean database.
37 */ 37 */
38 public static function tearDownAfterClass() 38 public static function tearDownAfterClass()
39 { 39 {
@@ -87,7 +87,6 @@ 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('Installing assets.', $tester->getDisplay());
91 } 90 }
92 91
93 public function testRunInstallCommandWithReset() 92 public function testRunInstallCommandWithReset()
@@ -119,7 +118,6 @@ class InstallCommandTest extends WallabagCoreTestCase
119 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); 118 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
120 $this->assertContains('Administration setup.', $tester->getDisplay()); 119 $this->assertContains('Administration setup.', $tester->getDisplay());
121 $this->assertContains('Config setup.', $tester->getDisplay()); 120 $this->assertContains('Config setup.', $tester->getDisplay());
122 $this->assertContains('Installing assets.', $tester->getDisplay());
123 121
124 // we force to reset everything 122 // we force to reset everything
125 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); 123 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
@@ -170,7 +168,6 @@ class InstallCommandTest extends WallabagCoreTestCase
170 $this->assertContains('Setting up database.', $tester->getDisplay()); 168 $this->assertContains('Setting up database.', $tester->getDisplay());
171 $this->assertContains('Administration setup.', $tester->getDisplay()); 169 $this->assertContains('Administration setup.', $tester->getDisplay());
172 $this->assertContains('Config setup.', $tester->getDisplay()); 170 $this->assertContains('Config setup.', $tester->getDisplay());
173 $this->assertContains('Installing assets.', $tester->getDisplay());
174 171
175 // the current database doesn't already exist 172 // the current database doesn't already exist
176 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); 173 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
@@ -208,7 +205,6 @@ class InstallCommandTest extends WallabagCoreTestCase
208 $this->assertContains('Setting up database.', $tester->getDisplay()); 205 $this->assertContains('Setting up database.', $tester->getDisplay());
209 $this->assertContains('Administration setup.', $tester->getDisplay()); 206 $this->assertContains('Administration setup.', $tester->getDisplay());
210 $this->assertContains('Config setup.', $tester->getDisplay()); 207 $this->assertContains('Config setup.', $tester->getDisplay());
211 $this->assertContains('Installing assets.', $tester->getDisplay());
212 208
213 $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); 209 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
214 } 210 }
@@ -263,7 +259,6 @@ class InstallCommandTest extends WallabagCoreTestCase
263 $this->assertContains('Setting up database.', $tester->getDisplay()); 259 $this->assertContains('Setting up database.', $tester->getDisplay());
264 $this->assertContains('Administration setup.', $tester->getDisplay()); 260 $this->assertContains('Administration setup.', $tester->getDisplay());
265 $this->assertContains('Config setup.', $tester->getDisplay()); 261 $this->assertContains('Config setup.', $tester->getDisplay());
266 $this->assertContains('Installing assets.', $tester->getDisplay());
267 262
268 $this->assertContains('Creating schema', $tester->getDisplay()); 263 $this->assertContains('Creating schema', $tester->getDisplay());
269 } 264 }
@@ -296,6 +291,5 @@ class InstallCommandTest extends WallabagCoreTestCase
296 $this->assertContains('Setting up database.', $tester->getDisplay()); 291 $this->assertContains('Setting up database.', $tester->getDisplay());
297 $this->assertContains('Administration setup.', $tester->getDisplay()); 292 $this->assertContains('Administration setup.', $tester->getDisplay());
298 $this->assertContains('Config setup.', $tester->getDisplay()); 293 $this->assertContains('Config setup.', $tester->getDisplay());
299 $this->assertContains('Installing assets.', $tester->getDisplay());
300 } 294 }
301} 295}
diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php
index 79452ace..97ed0d58 100644
--- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php
@@ -18,12 +18,19 @@ class DeveloperControllerTest extends WallabagCoreTestCase
18 18
19 $form = $crawler->filter('button[type=submit]')->form(); 19 $form = $crawler->filter('button[type=submit]')->form();
20 20
21 $client->submit($form); 21 $data = [
22 'client[name]' => 'My app',
23 ];
24
25 $crawler = $client->submit($form, $data);
22 26
23 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 27 $this->assertEquals(200, $client->getResponse()->getStatusCode());
24 28
25 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); 29 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
26 $this->assertGreaterThan(count($nbClients), count($newNbClients)); 30 $this->assertGreaterThan(count($nbClients), count($newNbClients));
31
32 $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text']));
33 $this->assertContains('My app', $alert[0]);
27 } 34 }
28 35
29 public function testListingClient() 36 public function testListingClient()
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 5c739c78..a74c17d9 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -236,6 +236,16 @@ class EntryControllerTest extends WallabagCoreTestCase
236 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 236 $this->assertEquals(200, $client->getResponse()->getStatusCode());
237 } 237 }
238 238
239 public function testUntagged()
240 {
241 $this->logInAs('admin');
242 $client = $this->getClient();
243
244 $client->request('GET', '/untagged/list');
245
246 $this->assertEquals(200, $client->getResponse()->getStatusCode());
247 }
248
239 public function testStarred() 249 public function testStarred()
240 { 250 {
241 $this->logInAs('admin'); 251 $this->logInAs('admin');
@@ -698,4 +708,47 @@ class EntryControllerTest extends WallabagCoreTestCase
698 $crawler = $client->submit($form, $data); 708 $crawler = $client->submit($form, $data);
699 $this->assertCount(2, $crawler->filter('div[class=entry]')); 709 $this->assertCount(2, $crawler->filter('div[class=entry]'));
700 } 710 }
711
712 public function testCache()
713 {
714 $this->logInAs('admin');
715 $client = $this->getClient();
716
717 $content = $client->getContainer()
718 ->get('doctrine.orm.entity_manager')
719 ->getRepository('WallabagCoreBundle:Entry')
720 ->findOneByUser($this->getLoggedInUserId());
721
722 // no uuid
723 $client->request('GET', '/share/'.$content->getUuid());
724 $this->assertEquals(404, $client->getResponse()->getStatusCode());
725
726 // generating the uuid
727 $client->request('GET', '/share/'.$content->getId());
728 $this->assertEquals(302, $client->getResponse()->getStatusCode());
729
730 // follow link with uuid
731 $crawler = $client->followRedirect();
732 $this->assertEquals(200, $client->getResponse()->getStatusCode());
733 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
734 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
735 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
736 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
737
738 // sharing is now disabled
739 $client->getContainer()->get('craue_config')->set('share_public', 0);
740 $client->request('GET', '/share/'.$content->getUuid());
741 $this->assertEquals(404, $client->getResponse()->getStatusCode());
742
743 $client->request('GET', '/view/'.$content->getId());
744 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
745
746 // removing the share
747 $client->request('GET', '/share/delete/'.$content->getId());
748 $this->assertEquals(302, $client->getResponse()->getStatusCode());
749
750 // share is now disable
751 $client->request('GET', '/share/'.$content->getUuid());
752 $this->assertEquals(404, $client->getResponse()->getStatusCode());
753 }
701} 754}
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index b22156c3..47b86117 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -168,7 +168,7 @@ class ExportControllerTest extends WallabagCoreTestCase
168 $this->assertGreaterThan(1, $csv); 168 $this->assertGreaterThan(1, $csv);
169 // +1 for title line 169 // +1 for title line
170 $this->assertEquals(count($contentInDB) + 1, count($csv)); 170 $this->assertEquals(count($contentInDB) + 1, count($csv));
171 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]); 171 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]);
172 } 172 }
173 173
174 public function testJsonExport() 174 public function testJsonExport()
@@ -210,6 +210,8 @@ class ExportControllerTest extends WallabagCoreTestCase
210 $this->assertArrayHasKey('reading_time', $content[0]); 210 $this->assertArrayHasKey('reading_time', $content[0]);
211 $this->assertArrayHasKey('domain_name', $content[0]); 211 $this->assertArrayHasKey('domain_name', $content[0]);
212 $this->assertArrayHasKey('tags', $content[0]); 212 $this->assertArrayHasKey('tags', $content[0]);
213 $this->assertArrayHasKey('created_at', $content[0]);
214 $this->assertArrayHasKey('updated_at', $content[0]);
213 } 215 }
214 216
215 public function testXmlExport() 217 public function testXmlExport()
@@ -247,5 +249,7 @@ class ExportControllerTest extends WallabagCoreTestCase
247 $this->assertNotEmpty('url', (string) $content->entry[0]->url); 249 $this->assertNotEmpty('url', (string) $content->entry[0]->url);
248 $this->assertNotEmpty('content', (string) $content->entry[0]->content); 250 $this->assertNotEmpty('content', (string) $content->entry[0]->content);
249 $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); 251 $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name);
252 $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at);
253 $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at);
250 } 254 }
251} 255}
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 03355f5a..08f4676e 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -69,4 +69,19 @@ class SecurityControllerTest extends WallabagCoreTestCase
69 $this->assertTrue($user->isTrustedComputer('ABCDEF')); 69 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
70 $this->assertFalse($user->isTrustedComputer('FEDCBA')); 70 $this->assertFalse($user->isTrustedComputer('FEDCBA'));
71 } 71 }
72
73 public function testEnabledRegistration()
74 {
75 $client = $this->getClient();
76
77 if (!$client->getContainer()->getParameter('fosuser_registration')) {
78 $this->markTestSkipped('fosuser_registration is not enabled.');
79
80 return;
81 }
82
83 $client->followRedirects();
84 $crawler = $client->request('GET', '/register');
85 $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]);
86 }
72} 87}
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 58450e5f..2c32393f 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -47,7 +47,7 @@ class TagControllerTest extends WallabagCoreTestCase
47 47
48 $this->assertEquals(1, count($entry->getTags())); 48 $this->assertEquals(1, count($entry->getTags()));
49 49
50 # tag already exists and already assigned 50 // tag already exists and already assigned
51 $client->submit($form, $data); 51 $client->submit($form, $data);
52 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 52 $this->assertEquals(302, $client->getResponse()->getStatusCode());
53 53
@@ -58,7 +58,7 @@ class TagControllerTest extends WallabagCoreTestCase
58 58
59 $this->assertEquals(1, count($newEntry->getTags())); 59 $this->assertEquals(1, count($newEntry->getTags()));
60 60
61 # tag already exists but still not assigned to this entry 61 // tag already exists but still not assigned to this entry
62 $data = [ 62 $data = [
63 'tag[label]' => 'foo', 63 'tag[label]' => 'foo',
64 ]; 64 ];
@@ -131,4 +131,35 @@ class TagControllerTest extends WallabagCoreTestCase
131 131
132 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 132 $this->assertEquals(404, $client->getResponse()->getStatusCode());
133 } 133 }
134
135 public function testShowEntriesForTagAction()
136 {
137 $this->logInAs('admin');
138 $client = $this->getClient();
139
140 $entry = $client->getContainer()
141 ->get('doctrine.orm.entity_manager')
142 ->getRepository('WallabagCoreBundle:Entry')
143 ->findOneByUsernameAndNotArchived('admin');
144
145 $tag = $client->getContainer()
146 ->get('doctrine.orm.entity_manager')
147 ->getRepository('WallabagCoreBundle:Tag')
148 ->findOneByEntryAndTagLabel($entry, 'foo');
149
150 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
151
152 $this->assertEquals(200, $client->getResponse()->getStatusCode());
153 $this->assertCount(2, $crawler->filter('div[class=entry]'));
154
155 $tag = $client->getContainer()
156 ->get('doctrine.orm.entity_manager')
157 ->getRepository('WallabagCoreBundle:Tag')
158 ->findOneByLabel('baz');
159
160 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
161
162 $this->assertEquals(200, $client->getResponse()->getStatusCode());
163 $this->assertCount(0, $crawler->filter('div[class=entry]'));
164 }
134} 165}
diff --git a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php
index 2a7f9390..078bb69a 100644
--- a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php
@@ -15,7 +15,11 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase
15{ 15{
16 private function getEvent(Request $request) 16 private function getEvent(Request $request)
17 { 17 {
18 return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST); 18 $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
19 ->disableOriginalConstructor()
20 ->getMock();
21
22 return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
19 } 23 }
20 24
21 public function testWithoutSession() 25 public function testWithoutSession()
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 7abb0737..5d772602 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -296,6 +296,29 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
296 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); 296 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
297 } 297 }
298 298
299 public function testAssignTagsNotFlushed()
300 {
301 $graby = $this->getMockBuilder('Graby\Graby')
302 ->disableOriginalConstructor()
303 ->getMock();
304
305 $tagRepo = $this->getTagRepositoryMock();
306 $tagRepo->expects($this->never())
307 ->method('__call');
308
309 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
310
311 $tagEntity = new Tag();
312 $tagEntity->setLabel('tag1');
313
314 $entry = new Entry(new User());
315
316 $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]);
317
318 $this->assertCount(1, $entry->getTags());
319 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
320 }
321
299 private function getTaggerMock() 322 private function getTaggerMock()
300 { 323 {
301 return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') 324 return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger')
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index c0055888..4f103921 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -80,4 +80,19 @@ abstract class WallabagCoreTestCase extends WebTestCase
80 80
81 throw new \RuntimeException('No logged in User.'); 81 throw new \RuntimeException('No logged in User.');
82 } 82 }
83
84 /**
85 * Check if Redis is installed.
86 * If not, mark test as skip.
87 */
88 protected function checkRedis()
89 {
90 try {
91 $this->client->getContainer()->get('wallabag_core.redis.client')->connect();
92 } catch (\Exception $e) {
93 $this->markTestSkipped(
94 'Redis is not installed/activated'
95 );
96 }
97 }
83} 98}