You are here

function PrivatemsgTestCase::testPreview in Privatemsg 6.2

Same name and namespace in other branches
  1. 6 privatemsg.test \PrivatemsgTestCase::testPreview()
  2. 7.2 privatemsg.test \PrivatemsgTestCase::testPreview()
  3. 7 privatemsg.test \PrivatemsgTestCase::testPreview()

Test preview functionality.

File

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

Class

PrivatemsgTestCase
@file Test file for privatemsg.module

Code

function testPreview() {
  $user = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
  ));

  // Enable preview button.
  variable_set('privatemsg_display_preview_button', TRUE);
  $message = array(
    'recipient' => $user->name,
    'subject' => $this
      ->randomName(),
    'body' => $this
      ->randomName(50),
  );
  $this
    ->drupalLogin($user);

  // Preview message.
  $this
    ->drupalPost('messages/new', $message, t('Preview message'));
  $this
    ->assertFieldByXPath("//div[@class='privatemsg-message-body']/p", $message['body'], t('Message body is previewed'));
  $this
    ->assertFieldByName('body', $message['body'], t('Message body field has the correct default value.'));

  // Send message.
  $this
    ->drupalPost(NULL, array(), t('Send message'));
  $this
    ->assertText($message['subject'], t('Message subject is displayed.'));
  $this
    ->assertText($message['body'], t('Message body is displayed.'));
  $this
    ->assertText(t('A message has been sent to @recipient.', array(
    '@recipient' => $user->name,
  )), t('Sent confirmation displayed.'));
}