function TableTest::testThemeTableRowRenderArray

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableRowRenderArray()
  2. 10 core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableRowRenderArray()
  3. 11.x 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 265

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.');
}

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