]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Helper/RedirectTest.php
Added tests
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Helper / RedirectTest.php
CommitLineData
af497a64
NL
1<?php
2
23634d5d 3namespace Tests\Wallabag\CoreBundle\Helper;
af497a64
NL
4
5use Wallabag\CoreBundle\Helper\Redirect;
6
7class RedirectTest extends \PHPUnit_Framework_TestCase
8{
4086e078 9 /** @var \PHPUnit_Framework_MockObject_MockObject */
af497a64
NL
10 private $routerMock;
11
12 /** @var Redirect */
13 private $redirect;
14
15 public function setUp()
16 {
17 $this->routerMock = $this->getRouterMock();
a42f38d9
NL
18 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
19 ->disableOriginalConstructor()
20 ->getMock();
21 $this->redirect = new Redirect($this->routerMock, $tokenStorage);
af497a64
NL
22 }
23
24 public function testRedirectToNullWithFallback()
25 {
26 $redirectUrl = $this->redirect->to(null, 'fallback');
27
65cd8a4a 28 $this->assertEquals(null, $redirectUrl);
af497a64
NL
29 }
30
31 public function testRedirectToNullWithoutFallback()
32 {
33 $redirectUrl = $this->redirect->to(null);
34
65cd8a4a 35 $this->assertEquals(null, $redirectUrl);
af497a64
NL
36 }
37
38 public function testRedirectToValidUrl()
39 {
40 $redirectUrl = $this->redirect->to('/unread/list');
41
42 $this->assertEquals('/unread/list', $redirectUrl);
43 }
44
45 private function getRouterMock()
46 {
4086e078 47 $mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
af497a64
NL
48 ->disableOriginalConstructor()
49 ->getMock();
4086e078
NL
50
51 $mock->expects($this->any())
52 ->method('generate')
53 ->with('homepage')
54 ->willReturn('homepage');
55
56 return $mock;
af497a64
NL
57 }
58}