class PrivatemsgTokenTestCase

  1. 7-1 privatemsg.test PrivatemsgTokenTestCase
  2. 7-2 privatemsg.test PrivatemsgTokenTestCase

Tests for fields integration.

Hierarchy

Expanded class hierarchy of PrivatemsgTokenTestCase

File

./privatemsg.test, line 1179
Test file for privatemsg.module

View source
class PrivatemsgTokenTestCase extends PrivatemsgBaseTestCase {
  /**
   * Implements of getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => t('Privatemsg tokens'),
      'description' => t('Tests tokens in private messages.'),
      'group' => t('Privatemsg'),
      'dependencies' => array('token'),
    );
  }

  /**
   * Implements setUp().
   */
  function setUp() {
    parent::setUp('privatemsg', 'token');
  }

  /**
   * Basic token functionality.
   */
  function testBasicTokens() {
    $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'use tokens in privatemsg'));
    $recipient1 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
    $recipient2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));

    $this->drupalLogin($author);

    // Enable preview button.
    variable_set('privatemsg_display_preview_button', TRUE);

    // Create message with tokens and preview it.
    $edit = array(
      'recipient' => $recipient1->name . ', ' . $recipient2->name,
      'subject' => 'Hey [privatemsg_message:recipient:name]',
      'body[value]' => "Testing a few tokens.\n\nSubject: [privatemsg_message:subject]\n\nAuthor: [privatemsg_message:author:name]\n\nInvalid token: [privatemsg_message:invalid_token]",
    );
    $this->drupalPost('messages/new', $edit, t('Preview message'));

    // Make sure the tokens in subject and body are correctly displayed in the
    // preview.
    $this->assertText('Hey < Token [privatemsg_message:recipient:name] >', t('Token is displayed in subject.'));
    $this->assertText('Subject: < Token [privatemsg_message:subject] >', t('Subject token is displayed.'));
    $this->assertText('Author: < Token [privatemsg_message:author:name] >', t('Author token is displayed.'));
    $this->assertText('Invalid token: < INVALID TOKEN [privatemsg_message:invalid_token] >', t('Invalid token is displayed.'));
    $this->assertText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));

    $this->drupalPost(NULL, array(), t('Send message'));

    // Make sure the tokens in subject and body are correctly displayed in the
    // sent message.
    $this->assertText('Hey < Token [privatemsg_message:recipient:name] >', t('Token is displayed in subject.'));
    $this->assertText('Subject: < Token [privatemsg_message:subject] >', t('Subject token is displayed.'));
    $this->assertText('Author: < Token [privatemsg_message:author:name] >', t('Author token is displayed.'));
    $this->assertText('Invalid token: < INVALID TOKEN [privatemsg_message:invalid_token] >', t('Invalid token is displayed.'));
    $this->assertText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));

    // Log in as the first recipient, verify that he sees the message with the
    // replacements.
    $this->drupalLogin($recipient1);
    $this->drupalGet('messages');
    $this->clickLink('Hey ' . $recipient1->name);

    // Make sure the tokens in subject and body are correctly displayed in the
    // message.
    $this->assertText('Hey ' . $recipient1->name, t('Replaced token is displayed in subject.'));
    $this->assertText('Subject: Hey ' . $recipient1->name, t('Subject token is replaced.'));
    $this->assertText('Author: ' . $author->name, t('Author token is replaced.'));
    $this->assertText('Invalid token: [privatemsg_message:invalid_token]', t('Invalid token is displayed.'));
    $this->assertNoText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));

    // Reply, verify that the message still shows the correct subject and
    // tokens from this user are not replaced.
    $reply = array('body[value]' => 'Response with a token [privatemsg_message:mid]');
    $this->drupalPost(NULL, $reply, t('Send message'));

    $this->drupalLogin($recipient2);
    $this->drupalGet('messages');
    $this->clickLink('Hey ' . $recipient2->name);

    // Make sure the tokens in subject and body are correctly displayed in the
    // message.
    $this->assertText('Hey ' . $recipient2->name, t('Replaced token is displayed in subject.'));
    $this->assertText('Subject: Hey ' . $recipient2->name, t('Subject token is replaced.'));
    $this->assertText('Author: ' . $author->name, t('Author token is replaced.'));
    $this->assertText('Invalid token: [privatemsg_message:invalid_token]', t('Invalid token is displayed.'));
    $this->assertText('Response with a token [privatemsg_message:mid]', t('Token from recipient is not replaced.'));
    $this->assertNoText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));

    $this->drupalLogin($author);
    $this->drupalGet('messages');

    // Assert that token is displayed in the subject for the author.
    $this->assertText('Hey < Token [privatemsg_message:recipient:name] >', t('Token is displayed correctly in subject for author.'));
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
PrivatemsgBaseTestCase::$profile protected property Use testing profile.
PrivatemsgTokenTestCase::getInfo public static function Implements of getInfo().
PrivatemsgTokenTestCase::setUp function Implements setUp().
PrivatemsgTokenTestCase::testBasicTokens function Basic token functionality.