summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-07-29 00:49:26 +0100
committerAlex Pott2016-07-29 00:49:26 +0100
commit21a4b87099ba234d37a304e0b32f692250169eed (patch)
tree013a026837d5d48a2191b5f54e053ac41d206348
parentaf80cb499a04d15b5905d19e66c8d5a8efd9b293 (diff)
Revert "Issue #2278383 by Xano, dawehner, kim.pepper, twistor, joelpittet, Fabianx, Crell, jibran, alexpott, Wim Leers: Create an injectible service for drupal_set_message()"
This reverts commit ee22272534726c991c07ff697faf9dc2fc08b667.
-rw-r--r--core/core.services.yml5
-rw-r--r--core/includes/bootstrap.inc44
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php24
-rw-r--r--core/lib/Drupal/Core/Installer/InstallerServiceProvider.php4
-rw-r--r--core/lib/Drupal/Core/Messenger/MessengerInterface.php84
-rw-r--r--core/lib/Drupal/Core/Messenger/SessionMessenger.php94
-rw-r--r--core/lib/Drupal/Core/Messenger/StaticMessenger.php104
-rw-r--r--core/tests/Drupal/Tests/Core/Messenger/SessionMessengerTest.php100
-rw-r--r--core/tests/Drupal/Tests/Core/Messenger/StaticMessengerTest.php80
9 files changed, 38 insertions, 501 deletions
diff --git a/core/core.services.yml b/core/core.services.yml
index 8182903..c818c8a 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1130,7 +1130,7 @@ services:
arguments: ['@state', '@current_user']
maintenance_mode_subscriber:
class: Drupal\Core\EventSubscriber\MaintenanceModeSubscriber
- arguments: ['@maintenance_mode', '@config.factory', '@string_translation', '@url_generator', '@current_user', '@bare_html_page_renderer', '@messenger']
+ arguments: ['@maintenance_mode', '@config.factory', '@string_translation', '@url_generator', '@current_user', '@bare_html_page_renderer']
tags:
- { name: event_subscriber }
path_subscriber:
@@ -1635,6 +1635,3 @@ services:
arguments: ['@current_user', '@path.current', '@path.matcher', '@language_manager']
tags:
- { name: event_subscriber }
- messenger:
- class: Drupal\Core\Messenger\SessionMessenger
- arguments: ['@page_cache_kill_switch']
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 4599b2b..ec12097 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -9,6 +9,8 @@ use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Logger\RfcLogLevel;
+use Drupal\Core\Render\Markup;
+use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Utility\Error;
@@ -435,15 +437,30 @@ function watchdog_exception($type, Exception $exception, $message = NULL, $varia
*
* @see drupal_get_messages()
* @see status-messages.html.twig
- *
- * @deprecated Deprecated as of Drupal 8.2.
- * Use \Drupal::service('messenger')->addMessage() instead.
*/
function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE) {
- /* @var \Drupal\Core\Messenger\MessengerInterface $messenger */
- $messenger = \Drupal::service('messenger');
- $messenger->addMessage($message, $type, $repeat);
- return $messenger->getMessages();
+ if (isset($message)) {
+ if (!isset($_SESSION['messages'][$type])) {
+ $_SESSION['messages'][$type] = array();
+ }
+
+ // Convert strings which are safe to the simplest Markup objects.
+ if (!($message instanceof Markup) && $message instanceof MarkupInterface) {
+ $message = Markup::create((string) $message);
+ }
+
+ // Do not use strict type checking so that equivalent string and
+ // MarkupInterface objects are detected.
+ if ($repeat || !in_array($message, $_SESSION['messages'][$type])) {
+ $_SESSION['messages'][$type][] = $message;
+ }
+
+ // Mark this page as being uncacheable.
+ \Drupal::service('page_cache_kill_switch')->trigger();
+ }
+
+ // Messages not set when DB connection fails.
+ return isset($_SESSION['messages']) ? $_SESSION['messages'] : NULL;
}
/**
@@ -470,19 +487,12 @@ function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE)
*
* @see drupal_set_message()
* @see status-messages.html.twig
- *
- * @deprecated Deprecated as of Drupal 8.2.
- * Use \Drupal::service('messenger')->getMessages() or
- * \Drupal::service('messenger')->getMessagesByType() instead.
*/
function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
- /** @var \Drupal\Core\Messenger\MessengerInterface $messenger */
- $messenger = \Drupal::service('messenger');
-
- if ($messages = $messenger->getMessages()) {
+ if ($messages = drupal_set_message()) {
if ($type) {
if ($clear_queue) {
- $messenger->deleteMessagesByType($type);
+ unset($_SESSION['messages'][$type]);
}
if (isset($messages[$type])) {
return array($type => $messages[$type]);
@@ -490,7 +500,7 @@ function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
}
else {
if ($clear_queue) {
- $messenger->deleteMessages();
+ unset($_SESSION['messages']);
}
return $messages;
}
diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
index 2e9f6fd..57d43ec 100644
--- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
@@ -5,7 +5,6 @@ namespace Drupal\Core\EventSubscriber;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Render\BareHtmlPageRendererInterface;
-use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Session\AccountInterface;
@@ -60,13 +59,6 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface {
protected $bareHtmlPageRenderer;
/**
- * The messenger.
- *
- * @var \Drupal\Core\Messenger\MessengerInterface
- */
- protected $messenger;
-
- /**
* Constructs a new MaintenanceModeSubscriber.
*
* @param \Drupal\Core\Site\MaintenanceModeInterface $maintenance_mode
@@ -81,17 +73,14 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface {
* The current user.
* @param \Drupal\Core\Render\BareHtmlPageRendererInterface $bare_html_page_renderer
* The bare HTML page renderer.
- * @param \Drupal\Core\Messenger\MessengerInterface $messenger
- * The messenger.
*/
- public function __construct(MaintenanceModeInterface $maintenance_mode, ConfigFactoryInterface $config_factory, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account, BareHtmlPageRendererInterface $bare_html_page_renderer, MessengerInterface $messenger) {
+ public function __construct(MaintenanceModeInterface $maintenance_mode, ConfigFactoryInterface $config_factory, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account, BareHtmlPageRendererInterface $bare_html_page_renderer) {
$this->maintenanceMode = $maintenance_mode;
$this->config = $config_factory;
$this->stringTranslation = $translation;
$this->urlGenerator = $url_generator;
$this->account = $account;
$this->bareHtmlPageRenderer = $bare_html_page_renderer;
- $this->messenger = $messenger;
}
/**
@@ -129,10 +118,10 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface {
// settings page.
if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
if ($this->account->hasPermission('administer site configuration')) {
- $this->messenger->addMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', [':url' => $this->urlGenerator->generate('system.site_maintenance_mode')]), 'status', FALSE);
+ $this->drupalSetMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', array(':url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE);
}
else {
- $this->messenger->addMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
+ $this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
}
}
}
@@ -152,6 +141,13 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface {
}
/**
+ * Wraps the drupal_set_message function.
+ */
+ protected function drupalSetMessage($message = NULL, $type = 'status', $repeat = FALSE) {
+ return drupal_set_message($message, $type, $repeat);
+ }
+
+ /**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
index f5fcf78..1ace991 100644
--- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
+++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
@@ -5,7 +5,6 @@ namespace Drupal\Core\Installer;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
-use Drupal\Core\Messenger\StaticMessenger;
use Symfony\Component\DependencyInjection\Reference;
/**
@@ -35,9 +34,6 @@ class InstallerServiceProvider implements ServiceProviderInterface, ServiceModif
->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
$container
->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory');
- $definition = $container->getDefinition('messenger');
- $definition->setClass(StaticMessenger::class);
- $definition->setArguments([new Reference('page_cache_kill_switch')]);
// Replace services with no-op implementations.
$container
diff --git a/core/lib/Drupal/Core/Messenger/MessengerInterface.php b/core/lib/Drupal/Core/Messenger/MessengerInterface.php
deleted file mode 100644
index da36f04..0000000
--- a/core/lib/Drupal/Core/Messenger/MessengerInterface.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-
-namespace Drupal\Core\Messenger;
-
-/**
- * Stores runtime messages sent out to individual users on the page.
- *
- * An example for these messages is for example: "Content X got saved".
- */
-interface MessengerInterface {
-
- /**
- * A status message.
- */
- const TYPE_STATUS = 'status';
-
- /**
- * A warning.
- */
- const TYPE_WARNING = 'warning';
-
- /**
- * An error.
- */
- const TYPE_ERROR = 'error';
-
- /**
- * Adds a new message to the queue.
- *
- * @param string|\Drupal\Component\Render\MarkupInterface $message
- * (optional) The translated message to be displayed to the user. For
- * consistency with other messages, it should begin with a capital letter
- * and end with a period.
- * @param string $type
- * (optional) The message's type. Either self::TYPE_STATUS,
- * self::TYPE_WARNING, or self::TYPE_ERROR.
- * @param bool $repeat
- * (optional) If this is FALSE and the message is already set, then the
- * message won't be repeated. Defaults to FALSE.
- *
- * @return $this
- */
- public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE);
-
- /**
- * Gets all messages.
- *
- * @return string[][]|\Drupal\Component\Render\MarkupInterface[][]
- * Keys are message types and values are indexed arrays of messages. Message
- * types are either self::TYPE_STATUS, self::TYPE_WARNING, or
- * self::TYPE_ERROR.
- */
- public function getMessages();
-
- /**
- * Gets all messages of a certain type.
- *
- * @param string $type
- * The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING,
- * or self::TYPE_ERROR.
- *
- * @return string[]|\Drupal\Component\Render\MarkupInterface[]
- */
- public function getMessagesByType($type);
-
- /**
- * Deletes all messages.
- *
- * @return $this
- */
- public function deleteMessages();
-
- /**
- * Deletes all messages of a certain type.
- *
- * @param string $type
- * The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING, or
- * self::TYPE_ERROR.
- *
- * @return $this
- */
- public function deleteMessagesByType($type);
-
-}
diff --git a/core/lib/Drupal/Core/Messenger/SessionMessenger.php b/core/lib/Drupal/Core/Messenger/SessionMessenger.php
deleted file mode 100644
index fc858fd..0000000
--- a/core/lib/Drupal/Core/Messenger/SessionMessenger.php
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-
-namespace Drupal\Core\Messenger;
-
-use Drupal\Component\Render\MarkupInterface;
-use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
-use Drupal\Core\Render\Markup;
-
-/**
- * Provides a session-based messenger.
- */
-class SessionMessenger implements MessengerInterface {
-
- /**
- * The page caching kill switch.
- *
- * @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch
- */
- protected $pageCacheKillSwitch;
-
- /**
- * Constructs a new instance.
- *
- * @param \Drupal\Core\Session\SessionManagerInterface
- * @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $page_cache_kill_switch
- * The page caching kill switch.
- */
- public function __construct(KillSwitch $page_cache_kill_switch) {
- $this->pageCacheKillSwitch = $page_cache_kill_switch;
- }
-
- /**
- * {@inheritdoc}
- */
- public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) {
- if (!isset($_SESSION['messages'][$type])) {
- $_SESSION['messages'][$type] = [];
- }
-
- // Convert strings which are safe to the simplest Markup objects.
- if (!($message instanceof Markup) && $message instanceof MarkupInterface) {
- $message = Markup::create((string) $message);
- }
-
- // Do not use strict type checking so that equivalent string and
- // \Drupal\Core\Render\Markup objects are detected.
- if ($repeat || !in_array($message, $_SESSION['messages'][$type])) {
- $_SESSION['messages'][$type][] = $message;
- $this->pageCacheKillSwitch->trigger();
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getMessages() {
- $messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : [];
- foreach ($messages as $type => $messages_by_type) {
- $messages[$type] = $messages_by_type;
- }
-
- return $messages;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getMessagesByType($type) {
- $messages = isset($_SESSION['messages']) && isset($_SESSION['messages'][$type]) ? $_SESSION['messages'][$type] : [];
-
- return $messages;
- }
-
- /**
- * {@inheritdoc}
- */
- public function deleteMessages() {
- unset($_SESSION['messages']);
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function deleteMessagesByType($type) {
- unset($_SESSION['messages'][$type]);
-
- return $this;
- }
-
-}
diff --git a/core/lib/Drupal/Core/Messenger/StaticMessenger.php b/core/lib/Drupal/Core/Messenger/StaticMessenger.php
deleted file mode 100644
index f2e0f51..0000000
--- a/core/lib/Drupal/Core/Messenger/StaticMessenger.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-
-namespace Drupal\Core\Messenger;
-
-use Drupal\Component\Render\MarkupInterface;
-use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
-use Drupal\Core\Render\Markup;
-
-/**
- * Provides a messenger that stores messages for this request only.
- */
-class StaticMessenger implements MessengerInterface {
-
- /**
- * The messages that have been set.
- *
- * @var array[]
- * Keys are either self::TYPE_STATUS, self::TYPE_WARNING, or
- * self::TYPE_ERROR. Values are arrays of arrays with the following keys:
- * - message (string): the message.
- * - safe (bool): whether the message is marked as safe markup.
- */
- protected $messages = [];
-
- /**
- * The page caching kill switch.
- *
- * @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch
- */
- protected $pageCacheKillSwitch;
-
- /**
- * Constructs a new instance.
- *
- * @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $page_cache_kill_switch
- * The page caching kill switch.
- */
- public function __construct(KillSwitch $page_cache_kill_switch) {
- $this->pageCacheKillSwitch = $page_cache_kill_switch;
- }
-
- /**
- * {@inheritdoc}
- */
- public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) {
- if (!isset($this->messages[$type])) {
- $this->messages[$type] = [];
- }
-
- // Convert strings which are safe to the simplest Markup objects.
- if (!($message instanceof Markup) && $message instanceof MarkupInterface) {
- $message = Markup::create((string) $message);
- }
-
- // Do not use strict type checking so that equivalent string and
- // MarkupInterface objects are detected.
- if ($repeat || !in_array($message, $this->messages[$type])) {
- $this->messages[$type][] = $message;
- $this->pageCacheKillSwitch->trigger();
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getMessages() {
- $messages = isset($this->messages) ? $this->messages : [];
- foreach ($messages as $type => $messages_by_type) {
- $messages[$type] = $messages_by_type;
- }
-
- return $messages;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getMessagesByType($type) {
- $messages = isset($this->messages) && isset($this->messages[$type]) ? $this->messages[$type] : [];
-
- return $messages;
- }
-
- /**
- * {@inheritdoc}
- */
- public function deleteMessages() {
- unset($this->messages);
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function deleteMessagesByType($type) {
- unset($this->messages[$type]);
-
- return $this;
- }
-
-}
diff --git a/core/tests/Drupal/Tests/Core/Messenger/SessionMessengerTest.php b/core/tests/Drupal/Tests/Core/Messenger/SessionMessengerTest.php
deleted file mode 100644
index 2da979c..0000000
--- a/core/tests/Drupal/Tests/Core/Messenger/SessionMessengerTest.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-namespace Drupal\Tests\Core\Messenger;
-
-use Drupal\Core\Messenger\SessionMessenger;
-use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
-use Drupal\Tests\UnitTestCase;
-
-/**
- * @coversDefaultClass \Drupal\Core\Messenger\SessionMessenger
- * @group messenger
- */
-class SessionMessengerTest extends UnitTestCase {
-
- /**
- * A copy of any existing session data to restore after the test.
- *
- * @var array
- */
- protected $existingSession;
-
- /**
- * The messenger under test.
- *
- * @var \Drupal\Core\Messenger\SessionMessenger
- */
- protected $messenger;
-
- /**
- * The page caching kill switch.
- *
- * @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $pageCacheKillSwitch;
-
- /**
- * {@inheritdoc}
- */
- public function setUp() {
- $this->pageCacheKillSwitch = $this->prophesize(KillSwitch::class);
-
- $this->existingSession = isset($_SESSION) ? $_SESSION : NULL;
- $_SESSION = [];
- }
-
- /**
- * {@inheritdoc}
- */
- public function tearDown() {
- if ($this->existingSession !== NULL) {
- $_SESSION = $this->existingSession;
- }
- else {
- unset($_SESSION);
- }
- }
-
- /**
- * @covers ::addMessage
- * @covers ::getMessages
- * @covers ::getMessagesByType
- * @covers ::deleteMessages
- * @covers ::deleteMessagesByType
- */
- public function testMessenger() {
- $this->pageCacheKillSwitch->trigger()->shouldBeCalled();
-
- $this->messenger = new SessionMessenger($this->pageCacheKillSwitch->reveal());
-
- $message_a = $this->randomMachineName();
- $type_a = $this->randomMachineName();
- $message_b = $this->randomMachineName();
- $type_b = $this->randomMachineName();
-
- // Test that if there are no messages, the default is an empty array.
- $this->assertEquals($this->messenger->getMessages(), []);
-
- // Test that adding a message returns the messenger and that the message can
- // be retrieved.
- $this->assertEquals($this->messenger->addMessage($message_a, $type_a), $this->messenger);
- $this->messenger->addMessage($message_a, $type_a);
- $this->messenger->addMessage($message_a, $type_a, TRUE);
- $this->messenger->addMessage($message_b, $type_b, TRUE);
- $this->assertEquals($this->messenger->getMessages(), [
- $type_a => [$message_a, $message_a],
- $type_b => [$message_b],
- ]);
-
- // Test deleting messages of a certain type.
- $this->assertEquals($this->messenger->deleteMessagesByType($type_a), $this->messenger);
- $this->assertEquals($this->messenger->getMessages(), [
- $type_b => [$message_b],
- ]);
-
- // Test deleting all messages.
- $this->assertEquals($this->messenger->deleteMessages(), $this->messenger);
- $this->assertEquals($this->messenger->getMessages(), []);
- }
-
-}
diff --git a/core/tests/Drupal/Tests/Core/Messenger/StaticMessengerTest.php b/core/tests/Drupal/Tests/Core/Messenger/StaticMessengerTest.php
deleted file mode 100644
index d315895..0000000
--- a/core/tests/Drupal/Tests/Core/Messenger/StaticMessengerTest.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-
-namespace Drupal\Tests\Core\Messenger;
-
-use Drupal\Core\Messenger\StaticMessenger;
-use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
-use Drupal\Tests\RandomGeneratorTrait;
-
-/**
- * @coversDefaultClass \Drupal\Core\Messenger\StaticMessenger
- * @group messenger
- */
-class StaticMessengerTest extends \PHPUnit_Framework_TestCase {
-
- use RandomGeneratorTrait;
-
- /**
- * The messenger under test.
- *
- * @var \Drupal\Core\Messenger\StaticMessenger
- */
- protected $messenger;
-
- /**
- * The page caching kill switch.
- *
- * @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $pageCacheKillSwitch;
-
- /**
- * {@inheritdoc}
- */
- public function setUp() {
- $this->pageCacheKillSwitch = $this->prophesize(KillSwitch::class);
- }
-
- /**
- * @covers ::addMessage
- * @covers ::getMessages
- * @covers ::getMessagesByType
- * @covers ::deleteMessages
- * @covers ::deleteMessagesByType
- */
- public function testMessenger() {
- $message_a = $this->randomMachineName();
- $type_a = $this->randomMachineName();
- $message_b = $this->randomMachineName();
- $type_b = $this->randomMachineName();
-
- $this->pageCacheKillSwitch->trigger()->shouldBeCalled();
-
- $this->messenger = new StaticMessenger($this->pageCacheKillSwitch->reveal());
-
- // Test that if there are no messages, the default is an empty array.
- $this->assertEquals($this->messenger->getMessages(), []);
-
- // Test that adding a message returns the messenger and that the message can
- // be retrieved.
- $this->assertSame($this->messenger->addMessage($message_a, $type_a), $this->messenger);
- $this->messenger->addMessage($message_a, $type_a);
- $this->messenger->addMessage($message_a, $type_a, TRUE);
- $this->messenger->addMessage($message_b, $type_b, TRUE);
- $this->assertEquals([
- $type_a => [$message_a, $message_a],
- $type_b => [$message_b],
- ], $this->messenger->getMessages());
-
- // Test deleting messages of a certain type.
- $this->assertEquals($this->messenger->deleteMessagesByType($type_a), $this->messenger);
- $this->assertEquals([
- $type_b => [$message_b],
- ], $this->messenger->getMessages());
-
- // Test deleting all messages.
- $this->assertEquals($this->messenger->deleteMessages(), $this->messenger);
- $this->assertEquals([], $this->messenger->getMessages());
- }
-
-}