function DrupalMessengerServiceTest::testDrupalMessengerService

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Bootstrap/DrupalMessengerServiceTest.php \Drupal\Tests\system\Functional\Bootstrap\DrupalMessengerServiceTest::testDrupalMessengerService()
  2. 8.9.x core/modules/system/tests/src/Functional/Bootstrap/DrupalMessengerServiceTest.php \Drupal\Tests\system\Functional\Bootstrap\DrupalMessengerServiceTest::testDrupalMessengerService()
  3. 10 core/modules/system/tests/src/Functional/Bootstrap/DrupalMessengerServiceTest.php \Drupal\Tests\system\Functional\Bootstrap\DrupalMessengerServiceTest::testDrupalMessengerService()

Tests Messenger service.

File

core/modules/system/tests/src/Functional/Bootstrap/DrupalMessengerServiceTest.php, line 31

Class

DrupalMessengerServiceTest
Tests the Messenger service.

Namespace

Drupal\Tests\system\Functional\Bootstrap

Code

public function testDrupalMessengerService() : void {
    // The page at system_test.messenger_service route sets two messages and
    // then removes the first before it is displayed.
    $this->drupalGet(Url::fromRoute('system_test.messenger_service'));
    $this->assertSession()
        ->pageTextNotContains('First message (removed).');
    $this->assertSession()
        ->responseContains('Second message with <em>markup!</em> (not removed).');
    // Ensure duplicate messages are handled as expected.
    $this->assertSession()
        ->pageTextMatchesCount(1, '/Non Duplicated message/');
    $this->assertSession()
        ->pageTextMatchesCount(3, '/Duplicated message/');
    // Ensure Markup objects are rendered as expected.
    $this->assertSession()
        ->responseContains('Markup with <em>markup!</em>');
    $this->assertSession()
        ->pageTextMatchesCount(1, '/Markup with markup!/');
    $this->assertSession()
        ->responseContains('Markup2 with <em>markup!</em>');
    // Ensure when the same message is of different types it is not duplicated.
    $this->assertSession()
        ->pageTextMatchesCount(1, '$Non duplicate Markup / string.$');
    $this->assertSession()
        ->pageTextMatchesCount(2, '$Duplicate Markup / string.$');
    // Ensure that strings that are not marked as safe are escaped.
    $this->assertSession()
        ->assertEscaped('<em>This<span>markup will be</span> escaped</em>.');
    // Ensure messages survive a container rebuild.
    $assert = $this->assertSession();
    $this->drupalLogin($this->drupalCreateUser([
        'administer modules',
    ]));
    $edit = [];
    $edit["modules[help][enable]"] = TRUE;
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $assert->pageTextContains('Help has been installed');
    $assert->pageTextContains('system_test_preinstall_module called');
}

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