MessageTest.php
Same filename in this branch
Same filename in other branches
- 8.9.x core/modules/jsonapi/tests/src/Functional/MessageTest.php
- 8.9.x core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php
- 10 core/modules/jsonapi/tests/src/Functional/MessageTest.php
- 10 core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php
- 11.x core/modules/jsonapi/tests/src/Functional/MessageTest.php
- 11.x core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php
Namespace
Drupal\KernelTests\Core\ThemeFile
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ MessageTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Theme;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests built-in message theme functions.
*
* @group Theme
*/
class MessageTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
];
/**
* Tests setting messages output.
*/
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');
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
MessageTest | Tests built-in message theme functions. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.