diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2017-01-27 09:34:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-27 09:34:32 +0100 |
commit | 6fb06904ecde15b1b07d0a2af945338b416cf0e2 (patch) | |
tree | e76f3e8142399316ec5660fab8c646b2c34b8336 /tests/Wallabag/CoreBundle/Helper/RedirectTest.php | |
parent | 05fa529bcfde01be5d320cb532900d72cf4b0830 (diff) | |
parent | 78295b99dd1721c613f1ce52e2debbe6f6db7753 (diff) | |
download | wallabag-6fb06904ecde15b1b07d0a2af945338b416cf0e2.tar.gz wallabag-6fb06904ecde15b1b07d0a2af945338b416cf0e2.tar.zst wallabag-6fb06904ecde15b1b07d0a2af945338b416cf0e2.zip |
Merge pull request #2416 from wallabag/2.2
wallabag 2.2.0
Diffstat (limited to 'tests/Wallabag/CoreBundle/Helper/RedirectTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/RedirectTest.php | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index f339f75e..0539f20a 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php | |||
@@ -2,7 +2,11 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Entity\Config; | ||
6 | use Wallabag\UserBundle\Entity\User; | ||
5 | use Wallabag\CoreBundle\Helper\Redirect; | 7 | use Wallabag\CoreBundle\Helper\Redirect; |
8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
6 | 10 | ||
7 | class RedirectTest extends \PHPUnit_Framework_TestCase | 11 | class RedirectTest extends \PHPUnit_Framework_TestCase |
8 | { | 12 | { |
@@ -14,8 +18,38 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
14 | 18 | ||
15 | public function setUp() | 19 | public function setUp() |
16 | { | 20 | { |
17 | $this->routerMock = $this->getRouterMock(); | 21 | $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') |
18 | $this->redirect = new Redirect($this->routerMock); | 22 | ->disableOriginalConstructor() |
23 | ->getMock(); | ||
24 | |||
25 | $this->routerMock->expects($this->any()) | ||
26 | ->method('generate') | ||
27 | ->with('homepage') | ||
28 | ->willReturn('homepage'); | ||
29 | |||
30 | $user = new User(); | ||
31 | $user->setName('youpi'); | ||
32 | $user->setEmail('youpi@youpi.org'); | ||
33 | $user->setUsername('youpi'); | ||
34 | $user->setPlainPassword('youpi'); | ||
35 | $user->setEnabled(true); | ||
36 | $user->addRole('ROLE_SUPER_ADMIN'); | ||
37 | |||
38 | $config = new Config($user); | ||
39 | $config->setTheme('material'); | ||
40 | $config->setItemsPerPage(30); | ||
41 | $config->setReadingSpeed(1); | ||
42 | $config->setLanguage('en'); | ||
43 | $config->setPocketConsumerKey('xxxxx'); | ||
44 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | ||
45 | |||
46 | $user->setConfig($config); | ||
47 | |||
48 | $this->token = new UsernamePasswordToken($user, 'password', 'key'); | ||
49 | $tokenStorage = new TokenStorage(); | ||
50 | $tokenStorage->setToken($this->token); | ||
51 | |||
52 | $this->redirect = new Redirect($this->routerMock, $tokenStorage); | ||
19 | } | 53 | } |
20 | 54 | ||
21 | public function testRedirectToNullWithFallback() | 55 | public function testRedirectToNullWithFallback() |
@@ -39,17 +73,20 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
39 | $this->assertEquals('/unread/list', $redirectUrl); | 73 | $this->assertEquals('/unread/list', $redirectUrl); |
40 | } | 74 | } |
41 | 75 | ||
42 | private function getRouterMock() | 76 | public function testWithNotLoggedUser() |
43 | { | 77 | { |
44 | $mock = $this->getMockBuilder('Symfony\Component\Routing\Router') | 78 | $redirect = new Redirect($this->routerMock, new TokenStorage()); |
45 | ->disableOriginalConstructor() | 79 | $redirectUrl = $redirect->to('/unread/list'); |
46 | ->getMock(); | ||
47 | 80 | ||
48 | $mock->expects($this->any()) | 81 | $this->assertEquals('/unread/list', $redirectUrl); |
49 | ->method('generate') | 82 | } |
50 | ->with('homepage') | ||
51 | ->willReturn('homepage'); | ||
52 | 83 | ||
53 | return $mock; | 84 | public function testUserForRedirectToHomepage() |
85 | { | ||
86 | $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | ||
87 | |||
88 | $redirectUrl = $this->redirect->to('/unread/list'); | ||
89 | |||
90 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | ||
54 | } | 91 | } |
55 | } | 92 | } |