You are here

public function TestMessenger::addMessage in Ubercart 8.4

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 uc_cart_links/tests/src/Unit/TestMessenger.php
Adds a new error message to the queue.
TestMessenger::addStatus in uc_cart_links/tests/src/Unit/TestMessenger.php
Adds a new status message to the queue.
TestMessenger::addWarning in uc_cart_links/tests/src/Unit/TestMessenger.php
Adds a new warning message to the queue.

File

uc_cart_links/tests/src/Unit/TestMessenger.php, line 17

Class

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

Namespace

Drupal\Tests\uc_cart_links\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;
    }
  }
}