function MessageTest::testMessages
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php \Drupal\KernelTests\Core\Theme\MessageTest::testMessages()
- 10 core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php \Drupal\KernelTests\Core\Theme\MessageTest::testMessages()
- 11.x core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php \Drupal\KernelTests\Core\Theme\MessageTest::testMessages()
Tests setting messages output.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ MessageTest.php, line 22
Class
- MessageTest
- Tests built-in message theme functions.
Namespace
Drupal\KernelTests\Core\ThemeCode
public function testMessages() {
// Enable the Starterkit theme.
\Drupal::service('theme_installer')->install([
'starterkit_theme',
]);
$this->config('system.theme')
->set('default', 'starterkit_theme')
->save();
\Drupal::messenger()->addError('An error occurred');
\Drupal::messenger()->addStatus('But then something nice happened');
$messages = [
'#type' => 'status_messages',
];
$this->render($messages);
$this->assertRaw('messages messages--error');
$this->assertRaw('messages messages--status');
// Tests display of only one type of messages.
\Drupal::messenger()->addError('An error occurred');
$messages = [
'#type' => 'status_messages',
'#display' => 'error',
];
$this->render($messages);
$this->assertRaw('messages messages--error');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.