public function UrlGeneratorTest::testAliasGenerationWithParameters in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTest::testAliasGenerationWithParameters()
Confirms that generated routes will have aliased paths.
File
- core/
tests/ Drupal/ Tests/ Core/ Routing/ UrlGeneratorTest.php, line 215 - Contains \Drupal\Tests\Core\Routing\UrlGeneratorTest.
Class
- UrlGeneratorTest
- Confirm that the UrlGenerator is functioning properly.
Namespace
Drupal\Tests\Core\RoutingCode
public function testAliasGenerationWithParameters() {
$url = $this->generator
->generate('test_2', array(
'narf' => '5',
));
$this
->assertEquals('/goodbye/cruel/world', $url);
// No cacheability to test; UrlGenerator::generate() doesn't support
// collecting cacheability metadata.
$this->routeProcessorManager
->expects($this
->exactly(7))
->method('processOutbound')
->with($this
->anything());
$options = array(
'fragment' => 'top',
);
// Extra parameters should appear in the query string.
$this
->assertGenerateFromRoute('test_1', [
'zoo' => 5,
], $options, '/hello/world?zoo=5#top', (new BubbleableMetadata())
->setCacheMaxAge(Cache::PERMANENT));
$options = array(
'query' => array(
'page' => '1',
),
'fragment' => 'bottom',
);
$this
->assertGenerateFromRoute('test_2', [
'narf' => 5,
], $options, '/goodbye/cruel/world?page=1#bottom', (new BubbleableMetadata())
->setCacheMaxAge(Cache::PERMANENT));
// Changing the parameters, the route still matches but there is no alias.
$this
->assertGenerateFromRoute('test_2', [
'narf' => 7,
], $options, '/test/two/7?page=1#bottom', (new BubbleableMetadata())
->setCacheMaxAge(Cache::PERMANENT));
$path = $this->generator
->getPathFromRoute('test_2', array(
'narf' => '5',
));
$this
->assertEquals('test/two/5', $path);
}