aboutsummaryrefslogblamecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
blob: a2d6a5245e9b20a7d556bf6e6f50bb67441d27d1 (plain) (tree)
1
2
3
4
5
6
7
8
9

     
                                           




                                                      
                                                        







                                                   



                                                                                                                                   





                                                             
                                                





                                                       
                                                










                                                           
                                                                         

                                          






                                     

     
<?php

namespace Tests\Wallabag\CoreBundle\Helper;

use Wallabag\CoreBundle\Helper\Redirect;

class RedirectTest extends \PHPUnit_Framework_TestCase
{
    /** @var \PHPUnit_Framework_MockObject_MockObject */
    private $routerMock;

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

    public function setUp()
    {
        $this->routerMock = $this->getRouterMock();
        $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
            ->disableOriginalConstructor()
            ->getMock();
        $this->redirect = new Redirect($this->routerMock, $tokenStorage);
    }

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

        $this->assertEquals(null, $redirectUrl);
    }

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

        $this->assertEquals(null, $redirectUrl);
    }

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

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

    private function getRouterMock()
    {
        $mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
            ->disableOriginalConstructor()
            ->getMock();

        $mock->expects($this->any())
            ->method('generate')
            ->with('homepage')
            ->willReturn('homepage');

        return $mock;
    }
}