-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] UrlGenerator: fixed missing query param and some ignored requirements #5181
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,12 +74,15 @@ public function testRelativeUrlWithNullParameter() | |
$this->assertEquals('/app.php/testing', $url); | ||
} | ||
|
||
/** | ||
* @expectedException Symfony\Component\Routing\Exception\InvalidParameterException | ||
*/ | ||
public function testRelativeUrlWithNullParameterButNotOptional() | ||
{ | ||
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null))); | ||
$url = $this->getGenerator($routes)->generate('test', array(), false); | ||
|
||
$this->assertEquals('/app.php/testing//bar', $url); | ||
// 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); | ||
} | ||
|
||
public function testRelativeUrlWithOptionalZeroParameter() | ||
|
@@ -90,6 +93,13 @@ public function testRelativeUrlWithOptionalZeroParameter() | |
$this->assertEquals('/app.php/testing/0', $url); | ||
} | ||
|
||
public function testNotPassedOptionalParameterInBetween() | ||
{ | ||
$routes = $this->getRoutes('test', new Route('/{slug}/{page}', array('slug' => 'index', 'page' => 0))); | ||
$this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', array('page' => 1))); | ||
$this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test')); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good |
||
|
||
public function testRelativeUrlWithExtraParameters() | ||
{ | ||
$routes = $this->getRoutes('test', new Route('/testing')); | ||
|
@@ -165,6 +175,15 @@ public function testGenerateForRouteWithInvalidOptionalParameter() | |
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); | ||
} | ||
|
||
/** | ||
* @expectedException Symfony\Component\Routing\Exception\InvalidParameterException | ||
*/ | ||
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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good |
||
|
||
public function testGenerateForRouteWithInvalidOptionalParameterNonStrict() | ||
{ | ||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); | ||
|
@@ -196,6 +215,15 @@ public function testGenerateForRouteWithInvalidMandatoryParameter() | |
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+'))); | ||
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); | ||
} | ||
|
||
/** | ||
* @expectedException Symfony\Component\Routing\Exception\InvalidParameterException | ||
*/ | ||
public function testRequiredParamAndEmptyPassed() | ||
{ | ||
$routes = $this->getRoutes('test', new Route('/{slug}', array(), array('slug' => '.+'))); | ||
$this->getGenerator($routes)->generate('test', array('slug' => '')); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good |
||
|
||
public function testSchemeRequirementDoesNothingIfSameCurrentScheme() | ||
{ | ||
|
@@ -229,6 +257,15 @@ public function testWithAnIntegerAsADefaultValue() | |
$this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); | ||
} | ||
|
||
public function testQueryParamSameAsDefault() | ||
{ | ||
$routes = $this->getRoutes('test', new Route('/test', array('default' => 'value'))); | ||
|
||
$this->assertSame('/app.php/test?default=foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); | ||
$this->assertSame('/app.php/test?default=value', $this->getGenerator($routes)->generate('test', array('default' => 'value'))); | ||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test')); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good |
||
|
||
public function testUrlEncoding() | ||
{ | ||
// This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks BC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the test is wrong and and even if it breaks bc, it was not really useful before because it generated a URL that doesnt get matched by the route. And thats not what should happen which is why we have the requirements check on url generation in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, with #5187 it would be possible to generate the URL as before (no bc break) although it doesn't really make sense in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has been merged ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I just wanted to draw your attention to #5187, so it gets merged too ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, the first developer issue that is revealed by this change: see #5396