function TableTest::testThemeTableWithEmptyMessage

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableWithEmptyMessage()
  2. 10 core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableWithEmptyMessage()
  3. 11.x core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableWithEmptyMessage()

Tests the display of the table header.

Tests are performed when the there are no rows and that the empty text is displayed correctly.

File

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

Class

TableTest
Tests built-in table theme functions.

Namespace

Drupal\KernelTests\Core\Render\Element

Code

public function testThemeTableWithEmptyMessage() {
    $header = [
        'Header 1',
        [
            'data' => 'Header 2',
            'colspan' => 2,
        ],
    ];
    $table = [
        '#type' => 'table',
        '#header' => $header,
        '#rows' => [],
        '#empty' => 'Empty row.',
    ];
    // Enable the Starterkit theme.
    \Drupal::service('theme_installer')->install([
        'starterkit_theme',
    ]);
    $this->config('system.theme')
        ->set('default', 'starterkit_theme')
        ->save();
    $this->render($table);
    $this->removeWhiteSpace();
    $this->assertRaw('<thead><tr><th>Header 1</th><th colspan="2">Header 2</th></tr>', 'Table header found.');
    $this->assertRaw('<tr class="odd"><td colspan="3" class="empty message">Empty row.</td>', 'Colspan on #empty row found.');
}

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