function SystemTestController::messengerServiceTest

Same name in other branches
  1. 9 core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php \Drupal\system_test\Controller\SystemTestController::messengerServiceTest()
  2. 8.9.x core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php \Drupal\system_test\Controller\SystemTestController::messengerServiceTest()
  3. 11.x core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php \Drupal\system_test\Controller\SystemTestController::messengerServiceTest()

Tests setting messages and removing one before it is displayed.

Return value

string Empty string, we just test the setting of messages.

1 string reference to 'SystemTestController::messengerServiceTest'
system_test.routing.yml in core/modules/system/tests/modules/system_test/system_test.routing.yml
core/modules/system/tests/modules/system_test/system_test.routing.yml

File

core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php, line 118

Class

SystemTestController
Controller routines for system_test routes.

Namespace

Drupal\system_test\Controller

Code

public function messengerServiceTest() {
    // Set two messages.
    $this->messenger
        ->addStatus('First message (removed).');
    $this->messenger
        ->addStatus($this->t('Second message with <em>markup!</em> (not removed).'));
    $messages = $this->messenger
        ->deleteByType('status');
    // Remove the first.
    unset($messages[0]);
    foreach ($messages as $message) {
        $this->messenger
            ->addStatus($message);
    }
    // Duplicate message check.
    $this->messenger
        ->addStatus('Non Duplicated message');
    $this->messenger
        ->addStatus('Non Duplicated message');
    $this->messenger
        ->addStatus('Duplicated message', TRUE);
    $this->messenger
        ->addStatus('Duplicated message', TRUE);
    // Add a Markup message.
    $this->messenger
        ->addStatus(Markup::create('Markup with <em>markup!</em>'));
    // Test duplicate Markup messages.
    $this->messenger
        ->addStatus(Markup::create('Markup with <em>markup!</em>'));
    // Ensure that multiple Markup messages work.
    $this->messenger
        ->addStatus(Markup::create('Markup2 with <em>markup!</em>'));
    // Test mixing of types.
    $this->messenger
        ->addStatus(Markup::create('Non duplicate Markup / string.'));
    $this->messenger
        ->addStatus('Non duplicate Markup / string.');
    $this->messenger
        ->addStatus(Markup::create('Duplicate Markup / string.'), TRUE);
    $this->messenger
        ->addStatus('Duplicate Markup / string.', TRUE);
    // Test auto-escape of non safe strings.
    $this->messenger
        ->addStatus('<em>This<span>markup will be</span> escaped</em>.');
    return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.