You are here

public function TableTest::testThemeTableRowRenderArray in Drupal 8

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

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

File

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

Class

TableTest
Tests built-in table theme functions.

Namespace

Drupal\KernelTests\Core\Render\Element

Code

public function testThemeTableRowRenderArray() {
  $header = [
    'one',
    'two',
    'three',
  ];
  $rows = [
    [
      '1-one',
      [
        'data' => '1-two',
      ],
      '1-three',
    ],
    [
      [
        'data' => [
          '#markup' => '2-one',
        ],
      ],
      '2-two',
      [
        'data' => [
          '#type' => 'html_tag',
          '#tag' => 'b',
          '#value' => '2-three',
        ],
      ],
    ],
  ];
  $table = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#responsive' => FALSE,
  ];
  $this
    ->render($table);
  $this
    ->removeWhiteSpace();
  $this
    ->assertRaw('<tbody><tr><td>1-one</td><td>1-two</td><td>1-three</td></tr>', 'Table row 1 found.');
  $this
    ->assertRaw('<tr><td>2-one</td><td>2-two</td><td><b>2-three</b></td></tr></tbody>', 'Table row 2 found.');
}