function RenderElementTypesTest::testHtmlTag

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php \Drupal\KernelTests\Core\Render\Element\RenderElementTypesTest::testHtmlTag()
  2. 10 core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php \Drupal\KernelTests\Core\Render\Element\RenderElementTypesTest::testHtmlTag()
  3. 11.x core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php \Drupal\KernelTests\Core\Render\Element\RenderElementTypesTest::testHtmlTag()

Tests system #type 'html_tag'.

File

core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php, line 79

Class

RenderElementTypesTest
Tests the rendered markup of core render element types.

Namespace

Drupal\KernelTests\Core\Render\Element

Code

public function testHtmlTag() {
    // Test void element.
    $this->assertElements([
        '#type' => 'html_tag',
        '#tag' => 'meta',
        '#value' => 'ignored',
        '#attributes' => [
            'name' => 'description',
            'content' => 'Drupal test',
        ],
    ], '<meta name="description" content="Drupal test" />' . "\n", "#type 'html_tag', void element renders properly");
    // Test non-void element.
    $this->assertElements([
        '#type' => 'html_tag',
        '#tag' => 'section',
        '#value' => 'value',
        '#attributes' => [
            'class' => [
                'unicorns',
            ],
        ],
    ], '<section class="unicorns">value</section>' . "\n", "#type 'html_tag', non-void element renders properly");
    // Test empty void element tag.
    $this->assertElements([
        '#type' => 'html_tag',
        '#tag' => 'link',
    ], "<link />\n", "#type 'html_tag' empty void element renders properly");
    // Test empty non-void element tag.
    $this->assertElements([
        '#type' => 'html_tag',
        '#tag' => 'section',
    ], "<section></section>\n", "#type 'html_tag' empty non-void element renders properly");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.