3 namespace Tests\Wallabag\CoreBundle\Helper
;
5 use Wallabag\CoreBundle\Helper\Redirect
;
7 class RedirectTest
extends \PHPUnit_Framework_TestCase
9 /** @var \PHPUnit_Framework_MockObject_MockObject */
15 const PASSWORD
= 's3Cr3t';
16 const SALT
= '^S4lt$';
18 public function setUp()
20 $this->routerMock = $this->getRouterMock();
21 $user = $this->createUser();
22 $tokenStorage = $this->createTokenStorage($user);
23 $this->redirect = new Redirect($this->routerMock, $tokenStorage);
26 public function testRedirectToNullWithFallback()
28 $redirectUrl = $this->redirect->to(null, 'fallback
');
30 $this->assertEquals('fallback
', $redirectUrl);
33 public function testRedirectToNullWithoutFallback()
35 $redirectUrl = $this->redirect->to(null);
37 $this->assertEquals($this->routerMock->generate('homepage
'), $redirectUrl);
40 public function testRedirectToValidUrl()
42 $redirectUrl = $this->redirect->to('/unread
/list');
44 $this->assertEquals('/unread
/list', $redirectUrl);
47 private function getRouterMock()
49 $mock = $this->getMockBuilder('Symfony\Component\Routing\Router
')
50 ->disableOriginalConstructor()
53 $mock->expects($this->any())
56 ->willReturn('homepage
');
61 protected function createTokenStorage($user = null)
63 $token = $this->createAuthenticationToken($user);
65 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
')
66 ->disableOriginalConstructor()
70 ->expects($this->any())
72 ->will($this->returnValue($token))
78 protected function createUser()
80 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface
')
81 ->disableOriginalConstructor()
85 ->expects($this->any())
86 ->method('getPassword
')
87 ->will($this->returnValue(static::PASSWORD))
91 ->expects($this->any())
93 ->will($this->returnValue(static::SALT))
99 protected function createAuthenticationToken($user = null)
101 $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface
')
102 ->disableOriginalConstructor()
106 ->expects($this->any())
108 ->will($this->returnValue($user))