You are here

public function MessageTokenTest::testTokenClearing in Message 8

Test clearing unused tokens.

File

tests/src/Kernel/MessageTokenTest.php, line 72

Class

MessageTokenTest
Test the Message and tokens integration.

Namespace

Drupal\Tests\message\Kernel

Code

public function testTokenClearing() {

  // Clearing enabled.
  $token_options = [
    'token options' => [
      'clear' => TRUE,
      'token replace' => TRUE,
    ],
  ];
  $message_template = $this
    ->createMessageTemplate('dummy_message', 'Dummy message', '', [
    '[message:author:name] [bogus:token]',
  ], $token_options);
  $message = Message::create([
    'template' => $message_template
      ->id(),
  ])
    ->setOwnerId($this->user
    ->id());
  $message
    ->save();
  $this
    ->assertEquals('<p>' . Html::escape($this->user
    ->label()) . ' </p>', (string) $message, 'The message rendered the author name and stripped unused tokens.');

  // Clearing disabled.
  $token_options = [
    'token options' => [
      'clear' => FALSE,
      'token replace' => TRUE,
    ],
  ];
  $message_template
    ->setSettings($token_options);
  $message_template
    ->save();
  $this
    ->assertEquals('<p>' . Html::escape($this->user
    ->label() . ' [bogus:token]') . '</p>', (string) $message, 'The message rendered the author name and did not strip the token.');
}