You are here

function DrupalSetMessageTest::testDrupalSetMessage in Zircon Profile 8.0

Same name in this branch
  1. 8.0 core/tests/Drupal/KernelTests/Core/Common/DrupalSetMessageTest.php \Drupal\KernelTests\Core\Common\DrupalSetMessageTest::testDrupalSetMessage()
  2. 8.0 core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php \Drupal\system\Tests\Bootstrap\DrupalSetMessageTest::testDrupalSetMessage()
Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php \Drupal\system\Tests\Bootstrap\DrupalSetMessageTest::testDrupalSetMessage()

Tests drupal_set_message().

File

core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php, line 29
Contains \Drupal\system\Tests\Bootstrap\DrupalSetMessageTest.

Class

DrupalSetMessageTest
Tests drupal_set_message() and related functions.

Namespace

Drupal\system\Tests\Bootstrap

Code

function testDrupalSetMessage() {

  // The page at system-test/drupal-set-message sets two messages and then
  // removes the first before it is displayed.
  $this
    ->drupalGet('system-test/drupal-set-message');
  $this
    ->assertNoText('First message (removed).');
  $this
    ->assertRaw(t('Second message with <em>markup!</em> (not removed).'));

  // Ensure duplicate messages are handled as expected.
  $this
    ->assertUniqueText('Non Duplicated message');
  $this
    ->assertNoUniqueText('Duplicated message');

  // Ensure Markup objects are rendered as expected.
  $this
    ->assertRaw('Markup with <em>markup!</em>');
  $this
    ->assertUniqueText('Markup with markup!');
  $this
    ->assertRaw('Markup2 with <em>markup!</em>');

  // Ensure when the same message is of different types it is not duplicated.
  $this
    ->assertUniqueText('Non duplicate Markup / string.');
  $this
    ->assertNoUniqueText('Duplicate Markup / string.');

  // Ensure that strings that are not marked as safe are escaped.
  $this
    ->assertEscaped('<em>This<span>markup will be</span> escaped</em>.');
}