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.php18
-rw-r--r--tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php37
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php20
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php45
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php23
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php4
7 files changed, 133 insertions, 20 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index bd351b18..d8928451 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -18,6 +18,18 @@ use Wallabag\CoreBundle\Command\InstallCommand;
18 18
19class InstallCommandTest extends WallabagCoreTestCase 19class InstallCommandTest extends WallabagCoreTestCase
20{ 20{
21 public static function setUpBeforeClass()
22 {
23 // disable doctrine-test-bundle
24 StaticDriver::setKeepStaticConnections(false);
25 }
26
27 public static function tearDownAfterClass()
28 {
29 // enable doctrine-test-bundle
30 StaticDriver::setKeepStaticConnections(true);
31 }
32
21 public function setUp() 33 public function setUp()
22 { 34 {
23 parent::setUp(); 35 parent::setUp();
@@ -51,9 +63,6 @@ class InstallCommandTest extends WallabagCoreTestCase
51 parent::setUp(); 63 parent::setUp();
52 } 64 }
53 65
54 // disable doctrine-test-bundle
55 StaticDriver::setKeepStaticConnections(false);
56
57 $this->resetDatabase($this->getClient()); 66 $this->resetDatabase($this->getClient());
58 } 67 }
59 68
@@ -62,6 +71,7 @@ class InstallCommandTest extends WallabagCoreTestCase
62 $databasePath = getenv('TEST_DATABASE_PATH'); 71 $databasePath = getenv('TEST_DATABASE_PATH');
63 // Remove variable environnement 72 // Remove variable environnement
64 putenv('TEST_DATABASE_PATH'); 73 putenv('TEST_DATABASE_PATH');
74
65 if ($databasePath && file_exists($databasePath)) { 75 if ($databasePath && file_exists($databasePath)) {
66 unlink($databasePath); 76 unlink($databasePath);
67 } else { 77 } else {
@@ -71,8 +81,6 @@ class InstallCommandTest extends WallabagCoreTestCase
71 $this->resetDatabase($client); 81 $this->resetDatabase($client);
72 } 82 }
73 83
74 // enable doctrine-test-bundle
75 StaticDriver::setKeepStaticConnections(true);
76 parent::tearDown(); 84 parent::tearDown();
77 } 85 }
78 86
diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
index b13f6519..c4bd6dac 100644
--- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
@@ -26,7 +26,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
26 { 26 {
27 parent::setUp(); 27 parent::setUp();
28 28
29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository'); 29 $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test');
30 30
31 $user = $userRepository->findOneByUserName('admin'); 31 $user = $userRepository->findOneByUserName('admin');
32 $this->adminEntry = new Entry($user); 32 $this->adminEntry = new Entry($user);
@@ -60,7 +60,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
60 60
61 $reloadedEntries = $this->getClient() 61 $reloadedEntries = $this->getClient()
62 ->getContainer() 62 ->getContainer()
63 ->get('wallabag_core.entry_repository') 63 ->get('wallabag_core.entry_repository.test')
64 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); 64 ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]);
65 65
66 foreach ($reloadedEntries as $reloadedEntry) { 66 foreach ($reloadedEntries as $reloadedEntry) {
@@ -84,7 +84,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
84 'interactive' => false, 84 'interactive' => false,
85 ]); 85 ]);
86 86
87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); 87 $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test');
88 88
89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); 89 $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId());
90 $this->assertNotEmpty($reloadedAdminEntry->getContent()); 90 $this->assertNotEmpty($reloadedAdminEntry->getContent());
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index e07c57dd..cf9f1e97 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -849,7 +849,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
849 $entryArchived->setContent('Youhou'); 849 $entryArchived->setContent('Youhou');
850 $entryArchived->setTitle('Youhou'); 850 $entryArchived->setTitle('Youhou');
851 $entryArchived->addTag($tagArchived); 851 $entryArchived->addTag($tagArchived);
852 $entryArchived->setArchived(true); 852 $entryArchived->updateArchived(true);
853 $em->persist($entryArchived); 853 $em->persist($entryArchived);
854 854
855 $annotationArchived = new Annotation($user); 855 $annotationArchived = new Annotation($user);
@@ -965,4 +965,39 @@ class ConfigControllerTest extends WallabagCoreTestCase
965 965
966 $client->request('GET', '/config/view-mode'); 966 $client->request('GET', '/config/view-mode');
967 } 967 }
968
969 public function testChangeLocaleWithoutReferer()
970 {
971 $client = $this->getClient();
972
973 $client->request('GET', '/locale/de');
974 $client->followRedirect();
975
976 $this->assertSame('de', $client->getRequest()->getLocale());
977 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
978 }
979
980 public function testChangeLocaleWithReferer()
981 {
982 $client = $this->getClient();
983
984 $client->request('GET', '/login');
985 $client->request('GET', '/locale/de');
986 $client->followRedirect();
987
988 $this->assertSame('de', $client->getRequest()->getLocale());
989 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
990 }
991
992 public function testChangeLocaleToBadLocale()
993 {
994 $client = $this->getClient();
995
996 $client->request('GET', '/login');
997 $client->request('GET', '/locale/yuyuyuyu');
998 $client->followRedirect();
999
1000 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1001 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1002 }
968} 1003}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 479e0700..006ca330 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -620,7 +620,7 @@ class EntryControllerTest extends WallabagCoreTestCase
620 $content->setMimetype('text/html'); 620 $content->setMimetype('text/html');
621 $content->setTitle('test title entry'); 621 $content->setTitle('test title entry');
622 $content->setContent('This is my content /o/'); 622 $content->setContent('This is my content /o/');
623 $content->setArchived(true); 623 $content->updateArchived(true);
624 $content->setLanguage('fr'); 624 $content->setLanguage('fr');
625 625
626 $em->persist($content); 626 $em->persist($content);
@@ -773,7 +773,7 @@ class EntryControllerTest extends WallabagCoreTestCase
773 773
774 $entry = new Entry($this->getLoggedInUser()); 774 $entry = new Entry($this->getLoggedInUser());
775 $entry->setUrl($this->url); 775 $entry->setUrl($this->url);
776 $entry->setArchived(false); 776 $entry->updateArchived(false);
777 $this->getEntityManager()->persist($entry); 777 $this->getEntityManager()->persist($entry);
778 $this->getEntityManager()->flush(); 778 $this->getEntityManager()->flush();
779 779
@@ -984,8 +984,13 @@ class EntryControllerTest extends WallabagCoreTestCase
984 $client->request('GET', '/share/' . $content->getId()); 984 $client->request('GET', '/share/' . $content->getId());
985 $this->assertSame(302, $client->getResponse()->getStatusCode()); 985 $this->assertSame(302, $client->getResponse()->getStatusCode());
986 986
987 // follow link with uid 987 $shareUrl = $client->getResponse()->getTargetUrl();
988 $crawler = $client->followRedirect(); 988
989 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
990 $client->restart();
991
992 $client->request('GET', $shareUrl);
993
989 $this->assertSame(200, $client->getResponse()->getStatusCode()); 994 $this->assertSame(200, $client->getResponse()->getStatusCode());
990 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); 995 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
991 $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); 996 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
@@ -1001,9 +1006,6 @@ class EntryControllerTest extends WallabagCoreTestCase
1001 $client->request('GET', '/share/' . $content->getUid()); 1006 $client->request('GET', '/share/' . $content->getUid());
1002 $this->assertSame(404, $client->getResponse()->getStatusCode()); 1007 $this->assertSame(404, $client->getResponse()->getStatusCode());
1003 1008
1004 $client->request('GET', '/view/' . $content->getId());
1005 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
1006
1007 // removing the share 1009 // removing the share
1008 $client->request('GET', '/share/delete/' . $content->getId()); 1010 $client->request('GET', '/share/delete/' . $content->getId());
1009 $this->assertSame(302, $client->getResponse()->getStatusCode()); 1011 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -1244,7 +1246,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1244 $entry = new Entry($this->getLoggedInUser()); 1246 $entry = new Entry($this->getLoggedInUser());
1245 $entry->setUrl('http://0.0.0.0/foo/baz/qux'); 1247 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1246 $entry->setTitle('Le manège'); 1248 $entry->setTitle('Le manège');
1247 $entry->setArchived(true); 1249 $entry->updateArchived(true);
1248 $this->getEntityManager()->persist($entry); 1250 $this->getEntityManager()->persist($entry);
1249 $this->getEntityManager()->flush(); 1251 $this->getEntityManager()->flush();
1250 1252
@@ -1274,7 +1276,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1274 $entry = new Entry($this->getLoggedInUser()); 1276 $entry = new Entry($this->getLoggedInUser());
1275 $entry->setUrl('http://domain/qux'); 1277 $entry->setUrl('http://domain/qux');
1276 $entry->setTitle('Le manège'); 1278 $entry->setTitle('Le manège');
1277 $entry->setArchived(true); 1279 $entry->updateArchived(true);
1278 $this->getEntityManager()->persist($entry); 1280 $this->getEntityManager()->persist($entry);
1279 $this->getEntityManager()->flush(); 1281 $this->getEntityManager()->flush();
1280 1282
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 768f4c07..be17dcf5 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -176,4 +176,49 @@ class TagControllerTest extends WallabagCoreTestCase
176 $em->remove($tag); 176 $em->remove($tag);
177 $em->flush(); 177 $em->flush();
178 } 178 }
179
180 public function testRenameTagUsingTheFormInsideTagList()
181 {
182 $this->logInAs('admin');
183 $client = $this->getClient();
184
185 $tag = new Tag();
186 $tag->setLabel($this->tagName);
187 $entry = new Entry($this->getLoggedInUser());
188 $entry->setUrl('http://0.0.0.0/foo');
189 $entry->addTag($tag);
190 $this->getEntityManager()->persist($entry);
191 $this->getEntityManager()->flush();
192 $this->getEntityManager()->clear();
193
194 // We make a first request to set an history and test redirection after tag deletion
195 $crawler = $client->request('GET', '/tag/list');
196 $form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form();
197
198 $data = [
199 'tag[label]' => 'specific label',
200 ];
201
202 $client->submit($form, $data);
203 $this->assertSame(302, $client->getResponse()->getStatusCode());
204
205 $freshEntry = $client->getContainer()
206 ->get('doctrine.orm.entity_manager')
207 ->getRepository('WallabagCoreBundle:Entry')
208 ->find($entry->getId());
209
210 $tags = $freshEntry->getTags()->toArray();
211 foreach ($tags as $key => $item) {
212 $tags[$key] = $item->getLabel();
213 }
214
215 $this->assertFalse(array_search($tag->getLabel(), $tags, true), 'Previous tag is not attach to entry anymore.');
216
217 $newTag = $client->getContainer()
218 ->get('doctrine.orm.entity_manager')
219 ->getRepository('WallabagCoreBundle:Tag')
220 ->findOneByLabel('specific label');
221 $this->assertInstanceOf(Tag::class, $newTag, 'Tag "specific label" exists.');
222 $this->assertTrue($newTag->hasEntry($freshEntry), 'Tag "specific label" is assigned to the entry.');
223 }
179} 224}
diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
index 93edfde8..ff0a9602 100644
--- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
@@ -56,4 +56,27 @@ class UserLocaleListenerTest extends TestCase
56 56
57 $this->assertNull($session->get('_locale')); 57 $this->assertNull($session->get('_locale'));
58 } 58 }
59
60 public function testWithLanguageFromSession()
61 {
62 $session = new Session(new MockArraySessionStorage());
63 $listener = new UserLocaleListener($session);
64 $session->set('_locale', 'de');
65
66 $user = new User();
67 $user->setEnabled(true);
68
69 $config = new Config($user);
70 $config->setLanguage('fr');
71
72 $user->setConfig($config);
73
74 $userToken = new UsernamePasswordToken($user, '', 'test');
75 $request = Request::create('/');
76 $event = new InteractiveLoginEvent($request, $userToken);
77
78 $listener->onInteractiveLogin($event);
79
80 $this->assertSame('de', $session->get('_locale'));
81 }
59} 82}
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index 6e1163c5..816d22f4 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -84,8 +84,8 @@ abstract class WallabagCoreTestCase extends WebTestCase
84 $container = $this->client->getContainer(); 84 $container = $this->client->getContainer();
85 $session = $container->get('session'); 85 $session = $container->get('session');
86 86
87 $userManager = $container->get('fos_user.user_manager'); 87 $userManager = $container->get('fos_user.user_manager.test');
88 $loginManager = $container->get('fos_user.security.login_manager'); 88 $loginManager = $container->get('fos_user.security.login_manager.test');
89 $firewallName = $container->getParameter('fos_user.firewall_name'); 89 $firewallName = $container->getParameter('fos_user.firewall_name');
90 90
91 $user = $userManager->findUserBy(['username' => $username]); 91 $user = $userManager->findUserBy(['username' => $username]);