aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-11-07 10:26:05 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-11-16 23:07:34 +0100
commit65cd8a4a9a1d15d962033f58276005a5f7716f3a (patch)
treec0dd762b631ae22443fb5efba3b838aeee01f7af
parentf052f1fd57e51c8ae5ac17587636d608619a2057 (diff)
downloadwallabag-65cd8a4a9a1d15d962033f58276005a5f7716f3a.tar.gz
wallabag-65cd8a4a9a1d15d962033f58276005a5f7716f3a.tar.zst
wallabag-65cd8a4a9a1d15d962033f58276005a5f7716f3a.zip
Added tests
-rw-r--r--src/Wallabag/CoreBundle/Helper/Redirect.php15
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php65
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php4
3 files changed, 78 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php
index 59172db4..82792aec 100644
--- a/src/Wallabag/CoreBundle/Helper/Redirect.php
+++ b/src/Wallabag/CoreBundle/Helper/Redirect.php
@@ -3,7 +3,7 @@
3namespace Wallabag\CoreBundle\Helper; 3namespace Wallabag\CoreBundle\Helper;
4 4
5use Symfony\Component\Routing\Router; 5use Symfony\Component\Routing\Router;
6use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; 6use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
7use Wallabag\CoreBundle\Entity\Config; 7use Wallabag\CoreBundle\Entity\Config;
8 8
9/** 9/**
@@ -12,12 +12,13 @@ use Wallabag\CoreBundle\Entity\Config;
12class Redirect 12class Redirect
13{ 13{
14 private $router; 14 private $router;
15 private $tokenStorage;
15 private $actionMarkAsRead; 16 private $actionMarkAsRead;
16 17
17 public function __construct(Router $router, TokenStorage $token) 18 public function __construct(Router $router, TokenStorageInterface $tokenStorage)
18 { 19 {
19 $this->router = $router; 20 $this->router = $router;
20 $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead(); 21 $this->tokenStorage = $tokenStorage;
21 } 22 }
22 23
23 /** 24 /**
@@ -28,7 +29,13 @@ class Redirect
28 */ 29 */
29 public function to($url, $fallback = '') 30 public function to($url, $fallback = '')
30 { 31 {
31 if (Config::REDIRECT_TO_HOMEPAGE === $this->actionMarkAsRead) { 32 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
33
34 if (null === $user || !is_object($user)) {
35 return $url;
36 }
37
38 if (Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) {
32 return $this->router->generate('homepage'); 39 return $this->router->generate('homepage');
33 } 40 }
34 41
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 4ab06dbf..bf4e0543 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config;
6use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
7 8
8class EntryControllerTest extends WallabagCoreTestCase 9class EntryControllerTest extends WallabagCoreTestCase
@@ -896,4 +897,68 @@ class EntryControllerTest extends WallabagCoreTestCase
896 897
897 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); 898 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
898 } 899 }
900
901 public function testRedirectToHomepage()
902 {
903 $this->logInAs('empty');
904 $client = $this->getClient();
905
906 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
907 $user = $em
908 ->getRepository('WallabagUserBundle:User')
909 ->find($this->getLoggedInUserId());
910
911 if (!$user) {
912 $this->markTestSkipped('No user found in db.');
913 }
914
915 // Redirect to homepage
916 $config = $user->getConfig();
917 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
918 $em->persist($config);
919 $em->flush();
920
921 $content = $client->getContainer()
922 ->get('doctrine.orm.entity_manager')
923 ->getRepository('WallabagCoreBundle:Entry')
924 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
925
926 $client->request('GET', '/view/'.$content->getId());
927 $client->request('GET', '/archive/'.$content->getId());
928
929 $this->assertEquals(302, $client->getResponse()->getStatusCode());
930 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
931 }
932
933 public function testRedirectToCurrentPage()
934 {
935 $this->logInAs('empty');
936 $client = $this->getClient();
937
938 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
939 $user = $em
940 ->getRepository('WallabagUserBundle:User')
941 ->find($this->getLoggedInUserId());
942
943 if (!$user) {
944 $this->markTestSkipped('No user found in db.');
945 }
946
947 // Redirect to current page
948 $config = $user->getConfig();
949 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
950 $em->persist($config);
951 $em->flush();
952
953 $content = $client->getContainer()
954 ->get('doctrine.orm.entity_manager')
955 ->getRepository('WallabagCoreBundle:Entry')
956 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
957
958 $client->request('GET', '/view/'.$content->getId());
959 $client->request('GET', '/archive/'.$content->getId());
960
961 $this->assertEquals(302, $client->getResponse()->getStatusCode());
962 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location'));
963 }
899} 964}
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
index 825e8d53..a2d6a524 100644
--- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
@@ -25,14 +25,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
25 { 25 {
26 $redirectUrl = $this->redirect->to(null, 'fallback'); 26 $redirectUrl = $this->redirect->to(null, 'fallback');
27 27
28 $this->assertEquals('fallback', $redirectUrl); 28 $this->assertEquals(null, $redirectUrl);
29 } 29 }
30 30
31 public function testRedirectToNullWithoutFallback() 31 public function testRedirectToNullWithoutFallback()
32 { 32 {
33 $redirectUrl = $this->redirect->to(null); 33 $redirectUrl = $this->redirect->to(null);
34 34
35 $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); 35 $this->assertEquals(null, $redirectUrl);
36 } 36 }
37 37
38 public function testRedirectToValidUrl() 38 public function testRedirectToValidUrl()