You are here

public function TestMessenger::addMessage in Rules 8.3

Adds a new message to the queue.

The messages will be displayed in the order they got added later.

Parameters

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.

string $type: (optional) The message's type. Either self::TYPE_STATUS, self::TYPE_WARNING, or self::TYPE_ERROR.

bool $repeat: (optional) If this is FALSE and the message is already set, then the message won't be repeated. Defaults to FALSE.

Return value

$this

Overrides MessengerInterface::addMessage

3 calls to TestMessenger::addMessage()
TestMessenger::addError in tests/src/Unit/TestMessenger.php
Adds a new error message to the queue.
TestMessenger::addStatus in tests/src/Unit/TestMessenger.php
Adds a new status message to the queue.
TestMessenger::addWarning in tests/src/Unit/TestMessenger.php
Adds a new warning message to the queue.

File

tests/src/Unit/TestMessenger.php, line 22

Class

TestMessenger
Mock class to replace the messenger service in unit tests.

Namespace

Drupal\Tests\rules\Unit

Code

public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) {
  if (!empty($message)) {
    $this->messages[$type] = isset($this->messages[$type]) ? $this->messages[$type] : [];
    if ($repeat || !in_array($message, $this->messages[$type])) {
      $this->messages[$type][] = $message;
    }
  }
}