aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests/Helper/RedirectTest.php
blob: da19cf58a48c875afb798e3022c04bdacc91e073 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

namespace Wallabag\CoreBundle\Tests\Helper;

use Wallabag\CoreBundle\Helper\Redirect;

class RedirectTest extends \PHPUnit_Framework_TestCase
{
    /** @var \Symfony\Component\Routing\Router */
    private $routerMock;

    /** @var Redirect */
    private $redirect;

    public function setUp()
    {
        $this->routerMock = $this->getRouterMock();
        $this->redirect = new Redirect($this->routerMock);
    }

    public function testRedirectToNullWithFallback()
    {
        $redirectUrl = $this->redirect->to(null, 'fallback');

        $this->assertEquals('fallback', $redirectUrl);
    }

    public function testRedirectToNullWithoutFallback()
    {
        $redirectUrl = $this->redirect->to(null);

        $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl);
    }

    public function testRedirectToValidUrl()
    {
        $redirectUrl = $this->redirect->to('/unread/list');

        $this->assertEquals('/unread/list', $redirectUrl);
    }

    private function getRouterMock()
    {
        return $this->getMockBuilder('Symfony\Component\Routing\Router')
            ->setMethods(['generate'])
            ->disableOriginalConstructor()
            ->getMock();
    }
}