aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-11-16 23:07:00 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-11-16 23:07:34 +0100
commit00bf45b6f291b6d1ce5f6a106e8e15bb1cce411b (patch)
treea811a3fcb9b3077d42d0cfe8d251b908276ee2bc
parent54fd55fda1eca050ba10fd41c68251cd2dcd02a0 (diff)
downloadwallabag-00bf45b6f291b6d1ce5f6a106e8e15bb1cce411b.tar.gz
wallabag-00bf45b6f291b6d1ce5f6a106e8e15bb1cce411b.tar.zst
wallabag-00bf45b6f291b6d1ce5f6a106e8e15bb1cce411b.zip
Update unit test for Redirect
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php104
1 files changed, 43 insertions, 61 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
index 3dcdf8de..6aa59644 100644
--- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
@@ -2,7 +2,11 @@
2 2
3namespace Tests\Wallabag\CoreBundle\Helper; 3namespace Tests\Wallabag\CoreBundle\Helper;
4 4
5use Wallabag\CoreBundle\Entity\Config;
6use Wallabag\UserBundle\Entity\User;
5use Wallabag\CoreBundle\Helper\Redirect; 7use Wallabag\CoreBundle\Helper\Redirect;
8use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
9use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
6 10
7class RedirectTest extends \PHPUnit_Framework_TestCase 11class RedirectTest extends \PHPUnit_Framework_TestCase
8{ 12{
@@ -17,9 +21,37 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
17 21
18 public function setUp() 22 public function setUp()
19 { 23 {
20 $this->routerMock = $this->getRouterMock(); 24 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router')
21 $user = $this->createUser(); 25 ->disableOriginalConstructor()
22 $tokenStorage = $this->createTokenStorage($user); 26 ->getMock();
27
28 $this->routerMock->expects($this->any())
29 ->method('generate')
30 ->with('homepage')
31 ->willReturn('homepage');
32
33 $user = new User();
34 $user->setName('youpi');
35 $user->setEmail('youpi@youpi.org');
36 $user->setUsername('youpi');
37 $user->setPlainPassword('youpi');
38 $user->setEnabled(true);
39 $user->addRole('ROLE_SUPER_ADMIN');
40
41 $config = new Config($user);
42 $config->setTheme('material');
43 $config->setItemsPerPage(30);
44 $config->setReadingSpeed(1);
45 $config->setLanguage('en');
46 $config->setPocketConsumerKey('xxxxx');
47 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
48
49 $user->setConfig($config);
50
51 $this->token = new UsernamePasswordToken($user, 'password', 'key');
52 $tokenStorage = new TokenStorage();
53 $tokenStorage->setToken($this->token);
54
23 $this->redirect = new Redirect($this->routerMock, $tokenStorage); 55 $this->redirect = new Redirect($this->routerMock, $tokenStorage);
24 } 56 }
25 57
@@ -44,70 +76,20 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
44 $this->assertEquals('/unread/list', $redirectUrl); 76 $this->assertEquals('/unread/list', $redirectUrl);
45 } 77 }
46 78
47 private function getRouterMock() 79 public function testWithNotLoggedUser()
48 {
49 $mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
50 ->disableOriginalConstructor()
51 ->getMock();
52
53 $mock->expects($this->any())
54 ->method('generate')
55 ->with('homepage')
56 ->willReturn('homepage');
57
58 return $mock;
59 }
60
61 protected function createTokenStorage($user = null)
62 { 80 {
63 $token = $this->createAuthenticationToken($user); 81 $redirect = new Redirect($this->routerMock, new TokenStorage());
64 82 $redirectUrl = $redirect->to('/unread/list');
65 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
66 ->disableOriginalConstructor()
67 ->getMock();
68 83
69 $mock 84 $this->assertEquals('/unread/list', $redirectUrl);
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 } 85 }
98 86
99 protected function createAuthenticationToken($user = null) 87 public function testUserForRedirectToHomepage()
100 { 88 {
101 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') 89 $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
102 ->disableOriginalConstructor()
103 ->getMock();
104 90
105 $mock 91 $redirectUrl = $this->redirect->to('/unread/list');
106 ->expects($this->any())
107 ->method('getUser')
108 ->will($this->returnValue($user))
109 ;
110 92
111 return $mock; 93 $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl);
112 } 94 }
113} 95}