You are here

function MessageTokens::testTokens in Message 7

Test token replacement in a message type.

File

tests/message.test, line 327

Class

MessageTokens
Test the Message and tokens integration.

Code

function testTokens() {
  $user1 = $this
    ->drupalCreateUser();
  $random_text = $this
    ->randomName();
  $token_message = '[message:user:name] ' . $random_text;
  $replaced_message = $user1->name . ' ' . $random_text;
  $message_type = message_type_create('foo');
  $message_type->{MESSAGE_FIELD_MESSAGE_TEXT} = array(
    LANGUAGE_NONE => array(
      0 => array(
        'value' => $token_message,
        'format' => 'plain_text',
      ),
    ),
  );
  $message_type
    ->save();
  $message = message_create('foo', array(), $user1);
  $this
    ->assertEqual($replaced_message . "\n", strip_tags($message
    ->getText()), t('Got correct text after token replacement.'));

  // Test not replacing tokens setting enabled.
  $message->data['token replace'] = FALSE;
  $this
    ->assertEqual($token_message . "\n", strip_tags($message
    ->getText()), t('Got correct text without token replacement.'));
}