]>
Commit | Line | Data |
---|---|---|
af497a64 NL |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
af497a64 NL |
4 | |
5 | use Wallabag\CoreBundle\Helper\Redirect; | |
6 | ||
7 | class 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 | ||
28 | $this->assertEquals('fallback', $redirectUrl); | |
29 | } | |
30 | ||
31 | public function testRedirectToNullWithoutFallback() | |
32 | { | |
33 | $redirectUrl = $this->redirect->to(null); | |
34 | ||
35 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | |
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 | } |