2016-04-15 05:58:01 +00:00
|
|
|
<?php
|
|
|
|
|
2016-06-01 19:27:35 +00:00
|
|
|
namespace Tests\Wallabag\CoreBundle\Helper;
|
2016-04-15 05:58:01 +00:00
|
|
|
|
|
|
|
use Wallabag\CoreBundle\Helper\Redirect;
|
|
|
|
|
|
|
|
class RedirectTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-04-15 07:58:29 +00:00
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
2016-04-15 05:58:01 +00:00
|
|
|
private $routerMock;
|
|
|
|
|
|
|
|
/** @var Redirect */
|
|
|
|
private $redirect;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->routerMock = $this->getRouterMock();
|
2016-11-06 11:02:39 +00:00
|
|
|
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->redirect = new Redirect($this->routerMock, $tokenStorage);
|
2016-04-15 05:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRedirectToNullWithFallback()
|
|
|
|
{
|
|
|
|
$redirectUrl = $this->redirect->to(null, 'fallback');
|
|
|
|
|
2016-11-07 09:26:05 +00:00
|
|
|
$this->assertEquals(null, $redirectUrl);
|
2016-04-15 05:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRedirectToNullWithoutFallback()
|
|
|
|
{
|
|
|
|
$redirectUrl = $this->redirect->to(null);
|
|
|
|
|
2016-11-07 09:26:05 +00:00
|
|
|
$this->assertEquals(null, $redirectUrl);
|
2016-04-15 05:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRedirectToValidUrl()
|
|
|
|
{
|
|
|
|
$redirectUrl = $this->redirect->to('/unread/list');
|
|
|
|
|
|
|
|
$this->assertEquals('/unread/list', $redirectUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getRouterMock()
|
|
|
|
{
|
2016-04-15 07:58:29 +00:00
|
|
|
$mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
|
2016-04-15 05:58:01 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-04-15 07:58:29 +00:00
|
|
|
|
|
|
|
$mock->expects($this->any())
|
|
|
|
->method('generate')
|
|
|
|
->with('homepage')
|
|
|
|
->willReturn('homepage');
|
|
|
|
|
|
|
|
return $mock;
|
2016-04-15 05:58:01 +00:00
|
|
|
}
|
|
|
|
}
|