You are here

public function RenderElementTypesTest::testHtmlTag in Drupal 9

Same name and namespace in other branches
  1. 8 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 74

Class

RenderElementTypesTest
Tests the markup of core render element types passed to drupal_render().

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