public function HtmlTagTest::providerPreRenderHtmlTag in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php \Drupal\Tests\Core\Render\Element\HtmlTagTest::providerPreRenderHtmlTag()
Data provider for preRenderHtmlTag test.
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ Element/ HtmlTagTest.php, line 44 - Contains \Drupal\Tests\Core\Render\Element\HtmlTagTest.
Class
- HtmlTagTest
- @coversDefaultClass \Drupal\Core\Render\Element\HtmlTag @group Render
Namespace
Drupal\Tests\Core\Render\ElementCode
public function providerPreRenderHtmlTag() {
$tags = array();
// Value prefix/suffix.
$element = array(
'#value' => 'value',
'#tag' => 'p',
);
$tags[] = array(
$element,
'<p>value</p>' . "\n",
);
// Normal element without a value should not result in a void element.
$element = array(
'#tag' => 'p',
'#value' => NULL,
);
$tags[] = array(
$element,
"<p></p>\n",
);
// A void element.
$element = array(
'#tag' => 'br',
);
$tags[] = array(
$element,
"<br />\n",
);
// Attributes.
$element = array(
'#tag' => 'div',
'#attributes' => array(
'class' => 'test',
'id' => 'id',
),
'#value' => 'value',
);
$tags[] = array(
$element,
'<div class="test" id="id">value</div>' . "\n",
);
// No script tags.
$element['#noscript'] = TRUE;
$tags[] = array(
$element,
'<noscript><div class="test" id="id">value</div>' . "\n" . '</noscript>',
);
// Ensure that #tag is sanitised.
$element = array(
'#tag' => 'p><script>alert()</script><p',
'#value' => 'value',
);
$tags[] = array(
$element,
"<p><script>alert()</script><p>value</p><script>alert()</script><p>\n",
);
// Ensure that #value is not filtered if it is marked as safe.
$element = array(
'#tag' => 'p',
'#value' => Markup::create('<script>value</script>'),
);
$tags[] = array(
$element,
"<p><script>value</script></p>\n",
);
// Ensure that #value is filtered if it is not safe.
$element = array(
'#tag' => 'p',
'#value' => '<script>value</script>',
);
$tags[] = array(
$element,
"<p>value</p>\n",
);
return $tags;
}