function UrlTest::testLinkRenderArrayText in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/system/src/Tests/Common/UrlTest.php \Drupal\system\Tests\Common\UrlTest::testLinkRenderArrayText()
Tests that link functions support render arrays as 'text'.
File
- core/
modules/ system/ src/ Tests/ Common/ UrlTest.php, line 168 - Contains \Drupal\system\Tests\Common\UrlTest.
Class
- UrlTest
- Confirm that \Drupal\Core\Url, \Drupal\Component\Utility\UrlHelper::filterQueryParameters(), \Drupal\Component\Utility\UrlHelper::buildQuery(), and \Drupal\Core\Utility\LinkGeneratorInterface::generate() work correctly with various input.
Namespace
Drupal\system\Tests\CommonCode
function testLinkRenderArrayText() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container
->get('renderer');
// Build a link with the link generator for reference.
$l = \Drupal::l('foo', Url::fromUri('https://www.drupal.org'));
// Test a renderable array passed to the link generator.
$renderer
->executeInRenderContext(new RenderContext(), function () use ($renderer, $l) {
$renderable_text = array(
'#markup' => 'foo',
);
$l_renderable_text = \Drupal::l($renderable_text, Url::fromUri('https://www.drupal.org'));
$this
->assertEqual($l_renderable_text, $l);
});
// Test a themed link with plain text 'text'.
$type_link_plain_array = array(
'#type' => 'link',
'#title' => 'foo',
'#url' => Url::fromUri('https://www.drupal.org'),
);
$type_link_plain = $renderer
->renderRoot($type_link_plain_array);
$this
->assertEqual($type_link_plain, $l);
// Build a themed link with renderable 'text'.
$type_link_nested_array = array(
'#type' => 'link',
'#title' => array(
'#markup' => 'foo',
),
'#url' => Url::fromUri('https://www.drupal.org'),
);
$type_link_nested = $renderer
->renderRoot($type_link_nested_array);
$this
->assertEqual($type_link_nested, $l);
}