public function MessengerTest::testAddMarkup in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php \Drupal\KernelTests\Core\Messenger\MessengerTest::testAddMarkup()
- 10 core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php \Drupal\KernelTests\Core\Messenger\MessengerTest::testAddMarkup()
Tests adding markup.
@covers ::addStatus @covers ::deleteByType @covers ::messagesByType
File
- core/
tests/ Drupal/ KernelTests/ Core/ Messenger/ MessengerTest.php, line 133
Class
- MessengerTest
- @group Messenger @coversDefaultClass \Drupal\Core\Messenger\Messenger
Namespace
Drupal\KernelTests\Core\MessengerCode
public function testAddMarkup() {
// 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>'));
$this
->assertCount(1, $this->messenger
->messagesByType(MessengerInterface::TYPE_STATUS));
// Ensure that multiple Markup messages work.
$this->messenger
->addStatus(Markup::create('Markup2 with <em>markup!</em>'));
$this
->assertCount(2, $this->messenger
->deleteByType(MessengerInterface::TYPE_STATUS));
// 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);
$this
->assertCount(3, $this->messenger
->deleteByType(MessengerInterface::TYPE_STATUS));
$this->messenger
->deleteAll();
// Check translatable string is converted to Markup.
$this->messenger
->addStatus(new TranslatableMarkup('Translatable message'));
$messages = $this->messenger
->deleteByType(MessengerInterface::TYPE_STATUS);
$this
->assertInstanceOf(Markup::class, $messages[0]);
}