public function TableTest::testThemeTableWithEmptyMessage in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableWithEmptyMessage()
- 9 core/tests/Drupal/KernelTests/Core/Render/Element/TableTest.php \Drupal\KernelTests\Core\Render\Element\TableTest::testThemeTableWithEmptyMessage()
Tests that the table header is printed correctly even if there are no rows, and that the empty text is displayed correctly.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Render/ Element/ TableTest.php, line 69
Class
- TableTest
- Tests built-in table theme functions.
Namespace
Drupal\KernelTests\Core\Render\ElementCode
public function testThemeTableWithEmptyMessage() {
$header = [
'Header 1',
[
'data' => 'Header 2',
'colspan' => 2,
],
];
$table = [
'#type' => 'table',
'#header' => $header,
'#rows' => [],
'#empty' => 'Empty row.',
];
// Enable the Classy theme.
\Drupal::service('theme_installer')
->install([
'classy',
]);
$this
->config('system.theme')
->set('default', 'classy')
->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.');
}