public function MessageTest::testMessages in Drupal 8
Same name and namespace in other branches
- 9 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 Classy theme.
\Drupal::service('theme_installer')
->install([
'classy',
]);
$this
->config('system.theme')
->set('default', 'classy')
->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');
}