You are here

public function TableTest::testThemeTableHeaderRenderArray in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableHeaderRenderArray()

Tests header elements with a mix of string and render array values.

File

core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php, line 232

Class

TableTest
Tests built-in table theme functions.

Namespace

Drupal\KernelTests\Core\Render\Element

Code

public function testThemeTableHeaderRenderArray() {
  $header = [
    [
      'data' => [
        '#markup' => 'one',
      ],
    ],
    'two',
    [
      'data' => [
        '#type' => 'html_tag',
        '#tag' => 'b',
        '#value' => 'three',
      ],
    ],
  ];
  $rows = [
    [
      1,
      2,
      3,
    ],
    [
      4,
      5,
      6,
    ],
    [
      7,
      8,
      9,
    ],
  ];
  $table = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#responsive' => FALSE,
  ];
  $this
    ->render($table);
  $this
    ->removeWhiteSpace();
  $this
    ->assertRaw('<thead><tr><th>one</th><th>two</th><th><b>three</b></th></tr>', 'Table header found.');
}