]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Helper/RedirectTest.php
Added a configuration to define the redirection after archiving an entry
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Helper / RedirectTest.php
1 <?php
2
3 namespace Tests\Wallabag\CoreBundle\Helper;
4
5 use Wallabag\CoreBundle\Helper\Redirect;
6
7 class RedirectTest extends \PHPUnit_Framework_TestCase
8 {
9 /** @var \PHPUnit_Framework_MockObject_MockObject */
10 private $routerMock;
11
12 /** @var Redirect */
13 private $redirect;
14
15 public function setUp()
16 {
17 $this->routerMock = $this->getRouterMock();
18 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
19 ->disableOriginalConstructor()
20 ->getMock();
21 $this->redirect = new Redirect($this->routerMock, $tokenStorage);
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 {
47 $mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $mock->expects($this->any())
52 ->method('generate')
53 ->with('homepage')
54 ->willReturn('homepage');
55
56 return $mock;
57 }
58 }