class MessageTest in Drupal 10
Same name in this branch
- 10 core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php \Drupal\KernelTests\Core\Theme\MessageTest
- 10 core/modules/jsonapi/tests/src/Functional/MessageTest.php \Drupal\Tests\jsonapi\Functional\MessageTest
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php \Drupal\KernelTests\Core\Theme\MessageTest
- 9 core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php \Drupal\KernelTests\Core\Theme\MessageTest
Tests built-in message theme functions.
@group Theme
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\KernelTests\Core\Theme\MessageTest
Expanded class hierarchy of MessageTest
File
- core/
tests/ Drupal/ KernelTests/ Core/ Theme/ MessageTest.php, line 12
Namespace
Drupal\KernelTests\Core\ThemeView source
class MessageTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
];
/**
* Tests setting messages output.
*/
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');
}
}