MessageTest.php

Same filename in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/MessageTest.php
Same filename in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/MessageTest.php
  2. 9 core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php
  3. 8.9.x core/modules/jsonapi/tests/src/Functional/MessageTest.php
  4. 8.9.x core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php
  5. 11.x core/modules/jsonapi/tests/src/Functional/MessageTest.php
  6. 11.x core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php

Namespace

Drupal\KernelTests\Core\Theme

File

core/tests/Drupal/KernelTests/Core/Theme/MessageTest.php

View source
<?php

declare (strict_types=1);
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() : void {
        // 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.