Skip to content

[Routing] use constants in tests #16277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Routing\Tests\Generator\Dumper;

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
Expand Down Expand Up @@ -64,10 +65,10 @@ public function testDumpWithRoutes()

$projectUrlGenerator = new \ProjectUrlGenerator(new RequestContext('/app.php'));

$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true);
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), true);
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), false);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), false);
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar');
$this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2');
Expand Down
48 changes: 24 additions & 24 deletions src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,55 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
public function testAbsoluteUrlWithPort80()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array(), true);
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);

$this->assertEquals('http://localhost/app.php/testing', $url);
}

public function testAbsoluteSecureUrlWithPort443()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), true);
$url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);

$this->assertEquals('https://localhost/app.php/testing', $url);
}

public function testAbsoluteUrlWithNonStandardPort()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), true);
$url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);

$this->assertEquals('http://localhost:8080/app.php/testing', $url);
}

public function testAbsoluteSecureUrlWithNonStandardPort()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), true);
$url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);

$this->assertEquals('https://localhost:8080/app.php/testing', $url);
}

public function testRelativeUrlWithoutParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array(), false);
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals('/app.php/testing', $url);
}

public function testRelativeUrlWithParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false);
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals('/app.php/testing/bar', $url);
}

public function testRelativeUrlWithNullParameter()
{
$routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null)));
$url = $this->getGenerator($routes)->generate('test', array(), false);
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals('/app.php/testing', $url);
}
Expand All @@ -83,13 +83,13 @@ public function testRelativeUrlWithNullParameterButNotOptional()
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null)));
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
// Generating path "/testing//bar" would be wrong as matching this route would fail.
$this->getGenerator($routes)->generate('test', array(), false);
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
}

public function testRelativeUrlWithOptionalZeroParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{page}'));
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), false);
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals('/app.php/testing/0', $url);
}
Expand All @@ -104,23 +104,23 @@ public function testNotPassedOptionalParameterInBetween()
public function testRelativeUrlWithExtraParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false);
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals('/app.php/testing?foo=bar', $url);
}

public function testAbsoluteUrlWithExtraParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);

$this->assertEquals('http://localhost/app.php/testing?foo=bar', $url);
}

public function testUrlWithNullExtraParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => null), true);
$url = $this->getGenerator($routes)->generate('test', array('foo' => null), UrlGeneratorInterface::ABSOLUTE_URL);

$this->assertEquals('http://localhost/app.php/testing', $url);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public function testGlobalParameterHasHigherPriorityThanDefault()
public function testGenerateWithoutRoutes()
{
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
$this->getGenerator($routes)->generate('test', array(), true);
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
}

/**
Expand All @@ -176,7 +176,7 @@ public function testGenerateWithoutRoutes()
public function testGenerateForRouteWithoutMandatoryParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
$this->getGenerator($routes)->generate('test', array(), true);
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
}

/**
Expand All @@ -185,7 +185,7 @@ public function testGenerateForRouteWithoutMandatoryParameter()
public function testGenerateForRouteWithInvalidOptionalParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
}

/**
Expand All @@ -194,15 +194,15 @@ public function testGenerateForRouteWithInvalidOptionalParameter()
public function testGenerateForRouteWithInvalidParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2')));
$this->getGenerator($routes)->generate('test', array('foo' => '0'), true);
$this->getGenerator($routes)->generate('test', array('foo' => '0'), UrlGeneratorInterface::ABSOLUTE_URL);
}

public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
$generator = $this->getGenerator($routes);
$generator->setStrictRequirements(false);
$this->assertNull($generator->generate('test', array('foo' => 'bar'), true));
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
}

public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
Expand All @@ -213,7 +213,7 @@ public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLog
->method('error');
$generator = $this->getGenerator($routes, array(), $logger);
$generator->setStrictRequirements(false);
$this->assertNull($generator->generate('test', array('foo' => 'bar'), true));
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
}

public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()
Expand All @@ -230,7 +230,7 @@ public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsC
public function testGenerateForRouteWithInvalidMandatoryParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+')));
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
}

/**
Expand Down Expand Up @@ -405,7 +405,7 @@ public function testWithHostSameAsContextAndAbsolute()
{
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));

$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), true));
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL));
}

/**
Expand All @@ -414,7 +414,7 @@ public function testWithHostSameAsContextAndAbsolute()
public function testUrlWithInvalidParameterInHost()
{
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
}

/**
Expand All @@ -423,7 +423,7 @@ public function testUrlWithInvalidParameterInHost()
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
{
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
}

/**
Expand All @@ -432,15 +432,15 @@ public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
{
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
}

public function testUrlWithInvalidParameterInHostInNonStrictMode()
{
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
$generator = $this->getGenerator($routes);
$generator->setStrictRequirements(false);
$this->assertNull($generator->generate('test', array('foo' => 'baz'), false));
$this->assertNull($generator->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH));
}

public function testHostIsCaseInsensitive()
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Http\HttpUtils;

Expand Down Expand Up @@ -43,7 +44,7 @@ public function testCreateRedirectResponseWithRouteName()
$urlGenerator
->expects($this->any())
->method('generate')
->with('foobar', array(), true)
->with('foobar', array(), UrlGeneratorInterface::ABSOLUTE_URL)
->will($this->returnValue('http://localhost/foo/bar'))
;
$urlGenerator
Expand Down