You are here

public function RenderElementTypesTest::testContainer in Drupal 8

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()

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 drupal_render().

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");
}