diff options
Diffstat (limited to 'tests')
9 files changed, 80 insertions, 16 deletions
diff --git a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php index 105e8add..9c7aba6b 100644 --- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php +++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php | |||
@@ -43,9 +43,9 @@ abstract class WallabagAnnotationTestCase extends WebTestCase | |||
43 | $container = $client->getContainer(); | 43 | $container = $client->getContainer(); |
44 | 44 | ||
45 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | 45 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ |
46 | $userManager = $container->get('fos_user.user_manager'); | 46 | $userManager = $container->get('fos_user.user_manager.test'); |
47 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | 47 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ |
48 | $loginManager = $container->get('fos_user.security.login_manager'); | 48 | $loginManager = $container->get('fos_user.security.login_manager.test'); |
49 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 49 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
50 | 50 | ||
51 | $this->user = $userManager->findUserBy(['username' => 'admin']); | 51 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index f58d1c12..090155d7 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | |||
@@ -121,7 +121,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
121 | { | 121 | { |
122 | $client = $this->getClient(); | 122 | $client = $this->getClient(); |
123 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 123 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
124 | $userManager = $client->getContainer()->get('fos_user.user_manager'); | 124 | $userManager = $client->getContainer()->get('fos_user.user_manager.test'); |
125 | $user = $userManager->findUserBy(['username' => $username]); | 125 | $user = $userManager->findUserBy(['username' => $username]); |
126 | $apiClient = new Client($user); | 126 | $apiClient = new Client($user); |
127 | $apiClient->setName('My app'); | 127 | $apiClient->setName('My app'); |
diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index 8a188e1c..0c52aea0 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php | |||
@@ -31,9 +31,9 @@ abstract class WallabagApiTestCase extends WebTestCase | |||
31 | $container = $client->getContainer(); | 31 | $container = $client->getContainer(); |
32 | 32 | ||
33 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | 33 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ |
34 | $userManager = $container->get('fos_user.user_manager'); | 34 | $userManager = $container->get('fos_user.user_manager.test'); |
35 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | 35 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ |
36 | $loginManager = $container->get('fos_user.security.login_manager'); | 36 | $loginManager = $container->get('fos_user.security.login_manager.test'); |
37 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 37 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
38 | 38 | ||
39 | $this->user = $userManager->findUserBy(['username' => 'admin']); | 39 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
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 d709f4eb..cf9f1e97 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -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 0ac119d8..6effe43e 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -985,8 +985,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
985 | $client->request('GET', '/share/' . $content->getId()); | 985 | $client->request('GET', '/share/' . $content->getId()); |
986 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 986 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
987 | 987 | ||
988 | // follow link with uid | 988 | $shareUrl = $client->getResponse()->getTargetUrl(); |
989 | $crawler = $client->followRedirect(); | 989 | |
990 | // use a new client to have a fresh empty session (instead of a logged one from the previous client) | ||
991 | $client->restart(); | ||
992 | |||
993 | $client->request('GET', $shareUrl); | ||
994 | |||
990 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 995 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
991 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | 996 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); |
992 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | 997 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); |
@@ -1002,9 +1007,6 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1002 | $client->request('GET', '/share/' . $content->getUid()); | 1007 | $client->request('GET', '/share/' . $content->getUid()); |
1003 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | 1008 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
1004 | 1009 | ||
1005 | $client->request('GET', '/view/' . $content->getId()); | ||
1006 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | ||
1007 | |||
1008 | // removing the share | 1010 | // removing the share |
1009 | $client->request('GET', '/share/delete/' . $content->getId()); | 1011 | $client->request('GET', '/share/delete/' . $content->getId()); |
1010 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 1012 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
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]); |
diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index 2b540fdf..c13bfbea 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php | |||
@@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase; | |||
8 | use Symfony\Component\EventDispatcher\EventDispatcher; | 8 | use Symfony\Component\EventDispatcher\EventDispatcher; |
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\HttpFoundation\Response; | 10 | use Symfony\Component\HttpFoundation\Response; |
11 | use Symfony\Component\HttpFoundation\Session\Session; | ||
12 | use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; | ||
11 | use Wallabag\CoreBundle\Entity\Config; | 13 | use Wallabag\CoreBundle\Entity\Config; |
12 | use Wallabag\UserBundle\Entity\User; | 14 | use Wallabag\UserBundle\Entity\User; |
13 | use Wallabag\UserBundle\EventListener\CreateConfigListener; | 15 | use Wallabag\UserBundle\EventListener\CreateConfigListener; |
@@ -22,6 +24,7 @@ class CreateConfigListenerTest extends TestCase | |||
22 | 24 | ||
23 | protected function setUp() | 25 | protected function setUp() |
24 | { | 26 | { |
27 | $session = new Session(new MockArraySessionStorage()); | ||
25 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | 28 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
26 | ->disableOriginalConstructor() | 29 | ->disableOriginalConstructor() |
27 | ->getMock(); | 30 | ->getMock(); |
@@ -34,7 +37,8 @@ class CreateConfigListenerTest extends TestCase | |||
34 | 'fr', | 37 | 'fr', |
35 | 1, | 38 | 1, |
36 | 1, | 39 | 1, |
37 | 1 | 40 | 1, |
41 | $session | ||
38 | ); | 42 | ); |
39 | 43 | ||
40 | $this->dispatcher = new EventDispatcher(); | 44 | $this->dispatcher = new EventDispatcher(); |