Commit ce887237 authored by alexpott's avatar alexpott

Issue #2674780 by esclapes, catch, penyaskito, dawehner: Unexpected API change...

Issue #2674780 by esclapes, catch, penyaskito, dawehner: Unexpected API change in UrlGenerator::generate()
parent 6958e219
......@@ -96,8 +96,8 @@ protected function bubble(GeneratedUrl $generated_url, array $options = []) {
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = array(), $absolute = FALSE) {
$options['absolute'] = $absolute;
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) {
$options['absolute'] = is_bool($referenceType) ? $referenceType : $referenceType === self::ABSOLUTE_URL;
$generated_url = $this->generateFromRoute($name, $parameters, $options, TRUE);
$this->bubble($generated_url);
return $generated_url->getGeneratedUrl();
......
......@@ -272,8 +272,8 @@ protected function getInternalPathFromRoute($name, SymfonyRoute $route, $paramet
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = array(), $absolute = FALSE) {
$options['absolute'] = $absolute;
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) {
$options['absolute'] = is_bool($referenceType) ? $referenceType : $referenceType === self::ABSOLUTE_URL;
return $this->generateFromRoute($name, $parameters, $options);
}
......
......@@ -216,6 +216,27 @@ public function testAliasGeneration() {
$this->assertEquals('test/one', $path);
}
/**
* Confirms that generated routes will have aliased paths using interface constants.
*/
public function testAliasGenerationUsingInterfaceConstants() {
$url = $this->generator->generate('test_1', array(), UrlGenerator::ABSOLUTE_PATH);
$this->assertEquals('/hello/world', $url);
// No cacheability to test; UrlGenerator::generate() doesn't support
// collecting cacheability metadata.
$this->routeProcessorManager->expects($this->exactly(3))
->method('processOutbound')
->with($this->anything());
// Check that the two generate methods return the same result.
$this->assertGenerateFromRoute('test_1', [], [], $url, (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));
$path = $this->generator->getPathFromRoute('test_1');
$this->assertEquals('test/one', $path);
}
/**
* @covers ::generateFromRoute
*/
......@@ -375,6 +396,24 @@ public function testAbsoluteURLGeneration() {
$this->assertGenerateFromRoute('test_1', ['zoo' => 5], $options, 'http://localhost/hello/world?zoo=5#top', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT)->setCacheContexts(['url.site']));
}
/**
* Confirms that absolute URLs work with generated routes using interface constants.
*/
public function testAbsoluteURLGenerationUsingInterfaceConstants() {
$url = $this->generator->generate('test_1', array(), UrlGenerator::ABSOLUTE_URL);
$this->assertEquals('http://localhost/hello/world', $url);
// No cacheability to test; UrlGenerator::generate() doesn't support
// collecting cacheability metadata.
$this->routeProcessorManager->expects($this->exactly(2))
->method('processOutbound')
->with($this->anything());
$options = array('absolute' => TRUE, 'fragment' => 'top');
// Extra parameters should appear in the query string.
$this->assertGenerateFromRoute('test_1', ['zoo' => 5], $options, 'http://localhost/hello/world?zoo=5#top', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT)->setCacheContexts(['url.site']));
}
/**
* Confirms that explicitly setting the base_url works with generated routes
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment