public function MessengerTest::testRemoveSingleMessage in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php \Drupal\KernelTests\Core\Messenger\MessengerTest::testRemoveSingleMessage()
@covers ::addStatus @covers ::deleteByType @covers ::messagesByType
File
- core/
tests/ Drupal/ KernelTests/ Core/ Messenger/ MessengerTest.php, line 36
Class
- MessengerTest
- @group Messenger @coversDefaultClass \Drupal\Core\Messenger\Messenger
Namespace
Drupal\KernelTests\Core\MessengerCode
public function testRemoveSingleMessage() {
// Set two messages.
$this->messenger
->addStatus('First message (removed).');
$this->messenger
->addStatus(t('Second message with <em>markup!</em> (not removed).'));
$messages = $this->messenger
->deleteByType(MessengerInterface::TYPE_STATUS);
// Remove the first.
unset($messages[0]);
// Re-add the second.
foreach ($messages as $message) {
$this->messenger
->addStatus($message);
}
// Check we only have the second one.
$this
->assertCount(1, $this->messenger
->messagesByType(MessengerInterface::TYPE_STATUS));
$this
->assertContainsEquals('Second message with <em>markup!</em> (not removed).', $this->messenger
->deleteByType(MessengerInterface::TYPE_STATUS));
}