function RenderElementTypesTest::testContainer

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

Tests system #type 'container'.

File

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

Class

RenderElementTypesTest
Tests the markup of core render element types passed to <a href="/api/drupal/core%21includes%21common.inc/function/drupal_render/8.9.x" title="Renders HTML given a structured array tree." class="local">drupal_render</a>().

Namespace

Drupal\KernelTests\Core\Render\Element

Code

public function testContainer() {
    // Basic container with no attributes.
    $this->assertElements([
        '#type' => 'container',
        '#markup' => 'foo',
    ], "<div>foo</div>\n", "#type 'container' with no HTML attributes");
    // Container with a class.
    $this->assertElements([
        '#type' => 'container',
        '#markup' => 'foo',
        '#attributes' => [
            'class' => [
                'bar',
            ],
        ],
    ], '<div class="bar">foo</div>' . "\n", "#type 'container' with a class HTML attribute");
    // Container with children.
    $this->assertElements([
        '#type' => 'container',
        'child' => [
            '#markup' => 'foo',
        ],
    ], "<div>foo</div>\n", "#type 'container' with child elements");
}

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