wallabag/src/Wallabag/CoreBundle/Tests/Helper/RedirectTest.php

56 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Wallabag\CoreBundle\Tests\Helper;
use Wallabag\CoreBundle\Helper\Redirect;
class RedirectTest extends \PHPUnit_Framework_TestCase
{
2016-04-15 07:58:29 +00:00
/** @var \PHPUnit_Framework_MockObject_MockObject */
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()
{
2016-04-15 07:58:29 +00:00
$mock = $this->getMockBuilder('Symfony\Component\Routing\Router')
->disableOriginalConstructor()
->getMock();
2016-04-15 07:58:29 +00:00
$mock->expects($this->any())
->method('generate')
->with('homepage')
->willReturn('homepage');
return $mock;
}
}