aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Helper/Redirect.php1
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php65
2 files changed, 60 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php
index 82792aec..f78b7fe0 100644
--- a/src/Wallabag/CoreBundle/Helper/Redirect.php
+++ b/src/Wallabag/CoreBundle/Helper/Redirect.php
@@ -13,7 +13,6 @@ class Redirect
13{ 13{
14 private $router; 14 private $router;
15 private $tokenStorage; 15 private $tokenStorage;
16 private $actionMarkAsRead;
17 16
18 public function __construct(Router $router, TokenStorageInterface $tokenStorage) 17 public function __construct(Router $router, TokenStorageInterface $tokenStorage)
19 { 18 {
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
index a2d6a524..3dcdf8de 100644
--- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
@@ -12,12 +12,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
12 /** @var Redirect */ 12 /** @var Redirect */
13 private $redirect; 13 private $redirect;
14 14
15 const PASSWORD = 's3Cr3t';
16 const SALT = '^S4lt$';
17
15 public function setUp() 18 public function setUp()
16 { 19 {
17 $this->routerMock = $this->getRouterMock(); 20 $this->routerMock = $this->getRouterMock();
18 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') 21 $user = $this->createUser();
19 ->disableOriginalConstructor() 22 $tokenStorage = $this->createTokenStorage($user);
20 ->getMock();
21 $this->redirect = new Redirect($this->routerMock, $tokenStorage); 23 $this->redirect = new Redirect($this->routerMock, $tokenStorage);
22 } 24 }
23 25
@@ -25,14 +27,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
25 { 27 {
26 $redirectUrl = $this->redirect->to(null, 'fallback'); 28 $redirectUrl = $this->redirect->to(null, 'fallback');
27 29
28 $this->assertEquals(null, $redirectUrl); 30 $this->assertEquals('fallback', $redirectUrl);
29 } 31 }
30 32
31 public function testRedirectToNullWithoutFallback() 33 public function testRedirectToNullWithoutFallback()
32 { 34 {
33 $redirectUrl = $this->redirect->to(null); 35 $redirectUrl = $this->redirect->to(null);
34 36
35 $this->assertEquals(null, $redirectUrl); 37 $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl);
36 } 38 }
37 39
38 public function testRedirectToValidUrl() 40 public function testRedirectToValidUrl()
@@ -55,4 +57,57 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
55 57
56 return $mock; 58 return $mock;
57 } 59 }
60
61 protected function createTokenStorage($user = null)
62 {
63 $token = $this->createAuthenticationToken($user);
64
65 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
66 ->disableOriginalConstructor()
67 ->getMock();
68
69 $mock
70 ->expects($this->any())
71 ->method('getToken')
72 ->will($this->returnValue($token))
73 ;
74
75 return $mock;
76 }
77
78 protected function createUser()
79 {
80 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')
81 ->disableOriginalConstructor()
82 ->getMock();
83
84 $mock
85 ->expects($this->any())
86 ->method('getPassword')
87 ->will($this->returnValue(static::PASSWORD))
88 ;
89
90 $mock
91 ->expects($this->any())
92 ->method('getSalt')
93 ->will($this->returnValue(static::SALT))
94 ;
95
96 return $mock;
97 }
98
99 protected function createAuthenticationToken($user = null)
100 {
101 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
102 ->disableOriginalConstructor()
103 ->getMock();
104
105 $mock
106 ->expects($this->any())
107 ->method('getUser')
108 ->will($this->returnValue($user))
109 ;
110
111 return $mock;
112 }
58} 113}