/**
* Tests the link_generator Twig functions.
*/
public function testTwigLinkGenerator() { $this->
drupalGet('twig-theme-test/link-generator'
);
/** @var \Drupal\Core\Utility\LinkGenerator $link_generator */
$link_generator =
$this->container->
get('link_generator'
);
$generated_url = Url::
fromRoute('user.register',
[],
['absolute' => TRUE
])->
toString(TRUE
)->
getGeneratedUrl();
$expected =
[ 'link via the linkgenerator: ' .
$link_generator->
generate('register',
new Url('user.register',
[],
['absolute' => TRUE
])),
'link via the linkgenerator: ' .
$link_generator->
generate('register',
new Url('user.register',
[],
['absolute' => TRUE, 'attributes' =>
['foo' => 'bar'
]])),
'link via the linkgenerator: ' .
$link_generator->
generate('register',
new Url('user.register',
[],
['attributes' =>
['foo' => 'bar', 'id' => 'kitten'
]])),
'link via the linkgenerator: ' .
$link_generator->
generate('register',
new Url('user.register',
[],
['attributes' =>
['id' => 'kitten'
]])),
'link via the linkgenerator: ' .
$link_generator->
generate('register',
new Url('user.register',
[],
['attributes' =>
['class' =>
['llama', 'kitten', 'panda'
]]])),
'link via the linkgenerator: ' .
$link_generator->
generate(Markup::
create('<span>register</span>'
),
new Url('user.register',
[],
['absolute' => TRUE
])),
'link via the linkgenerator: <a href="' .
$generated_url . '"><span>register</span><svg></svg></a>',
'link via the linkgenerator: ' .
$link_generator->
generate('register',
new Url('user.register',
[],
['attributes' =>
['foo' => 'bar'
]])) . ' ' .
$link_generator->
generate('register',
new Url('user.register',
[],
['attributes' =>
['foo' => 'bar'
]])),
];