aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-11-10 15:50:10 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-11-16 23:07:34 +0100
commit54fd55fda1eca050ba10fd41c68251cd2dcd02a0 (patch)
tree73ff0eaa1bff68c37e5872b34a78a8540f401d9e /tests/Wallabag/CoreBundle
parent65cd8a4a9a1d15d962033f58276005a5f7716f3a (diff)
downloadwallabag-54fd55fda1eca050ba10fd41c68251cd2dcd02a0.tar.gz
wallabag-54fd55fda1eca050ba10fd41c68251cd2dcd02a0.tar.zst
wallabag-54fd55fda1eca050ba10fd41c68251cd2dcd02a0.zip
Tried to fix tests
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php65
1 files changed, 60 insertions, 5 deletions
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}