function RenderElementTypesTest::testSystemCompactLink
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php \Drupal\KernelTests\Core\Render\Element\RenderElementTypesTest::testSystemCompactLink()
- 8.9.x core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php \Drupal\KernelTests\Core\Render\Element\RenderElementTypesTest::testSystemCompactLink()
- 11.x core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php \Drupal\KernelTests\Core\Render\Element\RenderElementTypesTest::testSystemCompactLink()
Tests system #type 'system_compact_link'.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Render/ Element/ RenderElementTypesTest.php, line 199
Class
- RenderElementTypesTest
- Tests the rendered markup of core render element types.
Namespace
Drupal\KernelTests\Core\Render\ElementCode
public function testSystemCompactLink() : void {
$elements = [
[
'name' => "#type 'system_compact_link' when admin compact mode is off",
'value' => [
'#type' => 'system_compact_link',
],
'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact/on?") and text()="Hide descriptions"]',
],
[
'name' => "#type 'system_compact_link' when adding extra attributes",
'value' => [
'#type' => 'system_compact_link',
'#attributes' => [
'class' => [
'kittens-rule',
],
],
],
'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact/on?") and @class="kittens-rule" and text()="Hide descriptions"]',
],
];
foreach ($elements as $element) {
$xml = new \SimpleXMLElement((string) \Drupal::service('renderer')->renderRoot($element['value']));
$result = $xml->xpath($element['expected']);
$this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly.');
}
// Set admin compact mode on for additional tests.
\Drupal::request()->cookies
->set('Drupal_visitor_admin_compact_mode', TRUE);
$element = [
'name' => "#type 'system_compact_link' when admin compact mode is on",
'value' => [
'#type' => 'system_compact_link',
],
'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact?") and text()="Show descriptions"]',
];
$xml = new \SimpleXMLElement((string) \Drupal::service('renderer')->renderRoot($element['value']));
$result = $xml->xpath($element['expected']);
$this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.