public function EngineTwigTest::testTwigUrlGenerator in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Theme/EngineTwigTest.php \Drupal\Tests\system\Functional\Theme\EngineTwigTest::testTwigUrlGenerator()
Tests the url and url_generate Twig functions.
File
- core/
modules/ system/ tests/ src/ Functional/ Theme/ EngineTwigTest.php, line 52
Class
- EngineTwigTest
- Tests Twig-specific theme functionality.
Namespace
Drupal\Tests\system\Functional\ThemeCode
public function testTwigUrlGenerator() {
$this
->drupalGet('twig-theme-test/url-generator');
// Find the absolute URL of the current site.
$url_generator = $this->container
->get('url_generator');
$expected = [
'path (as route) not absolute: ' . $url_generator
->generateFromRoute('user.register'),
'url (as route) absolute: ' . $url_generator
->generateFromRoute('user.register', [], [
'absolute' => TRUE,
]),
'path (as route) not absolute with fragment: ' . $url_generator
->generateFromRoute('user.register', [], [
'fragment' => 'bottom',
]),
'url (as route) absolute despite option: ' . $url_generator
->generateFromRoute('user.register', [], [
'absolute' => TRUE,
]),
'url (as route) absolute with fragment: ' . $url_generator
->generateFromRoute('user.register', [], [
'absolute' => TRUE,
'fragment' => 'bottom',
]),
];
// Verify that url() has the ability to bubble cacheability metadata:
// absolute URLs should bubble the 'url.site' cache context. (This only
// needs to test that cacheability metadata is bubbled *at all*; detailed
// tests for *which* cacheability metadata is bubbled live elsewhere.)
$this
->assertCacheContext('url.site');
// Make sure we got something.
$content = $this
->getSession()
->getPage()
->getContent();
$this
->assertFalse(empty($content), 'Page content is not empty');
foreach ($expected as $string) {
$this
->assertSession()
->responseContains('<div>' . $string . '</div>');
}
}