X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FRender%2FElement%2FHtmlTagTest.php;h=51ac995c19d3970180ca68e3fd0ad346869d7245;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=46dd91a87d618a9b50ae189dea978c9df3b14ad5;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website
diff --git a/web/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php b/web/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php
index 46dd91a87..51ac995c1 100644
--- a/web/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php
+++ b/web/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php
@@ -3,14 +3,14 @@
namespace Drupal\Tests\Core\Render\Element;
use Drupal\Core\Render\Markup;
-use Drupal\Tests\UnitTestCase;
+use Drupal\Tests\Core\Render\RendererTestBase;
use Drupal\Core\Render\Element\HtmlTag;
/**
* @coversDefaultClass \Drupal\Core\Render\Element\HtmlTag
* @group Render
*/
-class HtmlTagTest extends UnitTestCase {
+class HtmlTagTest extends RendererTestBase {
/**
* @covers ::getInfo
@@ -29,8 +29,12 @@ class HtmlTagTest extends UnitTestCase {
*/
public function testPreRenderHtmlTag($element, $expected) {
$result = HtmlTag::preRenderHtmlTag($element);
- $this->assertArrayHasKey('#markup', $result);
- $this->assertEquals($expected, $result['#markup']);
+ foreach ($result as &$child) {
+ if (is_array($child) && isset($child['#tag'])) {
+ $child = HtmlTag::preRenderHtmlTag($child);
+ }
+ }
+ $this->assertEquals($expected, (string) $this->renderer->renderRoot($result));
}
/**
@@ -44,20 +48,20 @@ class HtmlTagTest extends UnitTestCase {
'#value' => 'value',
'#tag' => 'p',
];
- $tags[] = [$element, '
value
' . "\n"];
+ $tags['value'] = [$element, 'value
' . "\n"];
// Normal element without a value should not result in a void element.
$element = [
'#tag' => 'p',
'#value' => NULL,
];
- $tags[] = [$element, "
\n"];
+ $tags['no-value'] = [$element, "
\n"];
// A void element.
$element = [
'#tag' => 'br',
];
- $tags[] = [$element, " \n"];
+ $tags['void-element'] = [$element, " \n"];
// Attributes.
$element = [
@@ -65,32 +69,154 @@ class HtmlTagTest extends UnitTestCase {
'#attributes' => ['class' => 'test', 'id' => 'id'],
'#value' => 'value',
];
- $tags[] = [$element, 'value
' . "\n"];
+ $tags['attributes'] = [$element, 'value
' . "\n"];
// No script tags.
$element['#noscript'] = TRUE;
- $tags[] = [$element, 'value
' . "\n" . ' '];
+ $tags['noscript'] = [$element, 'value
' . "\n" . ' '];
// Ensure that #tag is sanitised.
$element = [
'#tag' => 'p> 'value',
];
- $tags[] = [$element, "
value
\n"];
+ $tags['sanitized-tag'] = [$element, "value
\n"];
// Ensure that #value is not filtered if it is marked as safe.
$element = [
'#tag' => 'p',
'#value' => Markup::create(''),
];
- $tags[] = [$element, "
\n"];
+ $tags['value-safe'] = [$element, "
\n"];
// Ensure that #value is filtered if it is not safe.
$element = [
'#tag' => 'p',
'#value' => '',
];
- $tags[] = [$element, "value
\n"];
+ $tags['value-not-safe'] = [$element, "value
\n"];
+
+ // Ensure that nested render arrays render properly.
+ $element = [
+ '#tag' => 'p',
+ '#value' => NULL,
+ [
+ ['#markup' => 'value1 '],
+ ['#markup' => 'value2 '],
+ ],
+ ];
+ $tags['nested'] = [$element, "value1 value2
\n"];
+
+ // Ensure svg elements.
+ $element = [
+ '#tag' => 'rect',
+ '#attributes' => [
+ 'width' => 25,
+ 'height' => 25,
+ 'x' => 5,
+ 'y' => 10,
+ ],
+ ];
+ $tags['rect'] = [$element, ' ' . "\n"];
+
+ $element = [
+ '#tag' => 'circle',
+ '#attributes' => [
+ 'cx' => 100,
+ 'cy' => 100,
+ 'r' => 100,
+ ],
+ ];
+ $tags['circle'] = [$element, ' ' . "\n"];
+
+ $element = [
+ '#tag' => 'polygon',
+ '#attributes' => [
+ 'points' => '60,20 100,40 100,80 60,100 20,80 20,40',
+ ],
+ ];
+ $tags['polygon'] = [$element, ' ' . "\n"];
+
+ $element = [
+ '#tag' => 'ellipse',
+ '#attributes' => [
+ 'cx' => 60,
+ 'cy' => 60,
+ 'rx' => 50,
+ 'ry' => 25,
+ ],
+ ];
+ $tags['ellipse'] = [$element, ' ' . "\n"];
+
+ $element = [
+ '#tag' => 'use',
+ '#attributes' => [
+ 'x' => 50,
+ 'y' => 10,
+ 'width' => 50,
+ 'height' => 50,
+ ],
+ ];
+ $tags['use'] = [$element, ' ' . "\n"];
+
+ $element = [
+ '#tag' => 'path',
+ '#attributes' => [
+ 'd' => 'M 100 100 L 300 100 L 200 300 z',
+ 'fill' => 'orange',
+ 'stroke' => 'black',
+ 'stroke-width' => 3,
+ ],
+ ];
+ $tags['path'] = [$element, ' ' . "\n"];
+
+ $element = [
+ '#tag' => 'stop',
+ '#attributes' => [
+ 'offset' => '5%',
+ 'stop-color' => '#F60',
+ ],
+ ];
+ $tags['stop'] = [$element, ' ' . "\n"];
+
+ // Nested svg elements.
+ $element = [
+ '#tag' => 'linearGradient',
+ '#value' => NULL,
+ [
+ '#tag' => 'stop',
+ '#value' => NULL,
+ '#attributes' => [
+ 'offset' => '5%',
+ 'stop-color' => '#F60',
+ ],
+ ],
+ [
+ '#tag' => 'stop',
+ '#value' => NULL,
+ '#attributes' => [
+ 'offset' => '95%',
+ 'stop-color' => '#FF6',
+ ],
+ ],
+ ];
+ $tags['linearGradient'] = [$element, ' ' . "\n" . ' ' . "\n" . ' ' . "\n"];
+
+ // Simple link.
+ $element = [
+ '#tag' => 'link',
+ ];
+ $tags['link'] = [HtmlTag::preRenderConditionalComments($element), ' ' . "\n"];
+
+ // Conditional link.
+ $element = [
+ '#tag' => 'link',
+ '#browsers' => [
+ 'IE' => TRUE,
+ '!IE' => FALSE,
+ ],
+ ];
+ $tags['conditional-link'] = [HtmlTag::preRenderConditionalComments($element), "\n" . '' . "\n"];
return $tags;
}
@@ -115,14 +241,14 @@ class HtmlTagTest extends UnitTestCase {
$element = [
'#tag' => 'link',
];
- $tags[] = [$element, $element];
+ $tags['no-browser'] = [$element, $element];
// Specify all browsers.
$element['#browsers'] = [
'IE' => TRUE,
'!IE' => TRUE,
];
- $tags[] = [$element, $element];
+ $tags['all-browsers'] = [$element, $element];
// All IE.
$element = [
@@ -135,7 +261,7 @@ class HtmlTagTest extends UnitTestCase {
$expected = $element;
$expected['#prefix'] = "\n\n";
- $tags[] = [$element, $expected];
+ $tags['all-ie'] = [$element, $expected];
// Exclude IE.
$element = [
@@ -147,7 +273,7 @@ class HtmlTagTest extends UnitTestCase {
$expected = $element;
$expected['#prefix'] = "\n\n";
$expected['#suffix'] = "\n";
- $tags[] = [$element, $expected];
+ $tags['no-ie'] = [$element, $expected];
// IE gt 8
$element = [
@@ -159,7 +285,7 @@ class HtmlTagTest extends UnitTestCase {
$expected = $element;
$expected['#prefix'] = "\n\n";
$expected['#suffix'] = "\n";
- $tags[] = [$element, $expected];
+ $tags['ie9plus'] = [$element, $expected];
// Prefix and suffix filtering if not safe.
$element = [
@@ -173,13 +299,13 @@ class HtmlTagTest extends UnitTestCase {
$expected = $element;
$expected['#prefix'] = "\n\nprefix";
$expected['#suffix'] = "suffix\n";
- $tags[] = [$element, $expected];
+ $tags['non-ie-unsafe'] = [$element, $expected];
// Prefix and suffix filtering if marked as safe. This has to come after the
// previous test case.
$expected['#prefix'] = "\n\nprefix ";
$expected['#suffix'] = "suffix \n";
- $tags[] = [$element, $expected, TRUE];
+ $tags['non-ie-safe'] = [$element, $expected, TRUE];
return $tags;
}