You are here

function PrivatemsgTestCase::testPreview in Privatemsg 7

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

Test preview functionality.

File

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

Class

PrivatemsgTestCase

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[value]' => $this
      ->randomName(50),
  );
  $this
    ->drupalLogin($user);

  // Preview message.
  $this
    ->drupalPost('messages/new', $message, t('Preview message'));
  $this
    ->assertTitle(t('Write new message to @user', array(
    '@user' => $user->name,
  )) . ' | Drupal', t('Correct title is displayed.'));
  $this
    ->assertFieldByXPath($this
    ->buildXPathQuery('//div[@class=:class]/p', array(
    ':class' => 'privatemsg-message-body',
  )), $message['body[value]'], t('Message body is previewed'));
  $this
    ->assertFieldByName('body[value]', $message['body[value]'], 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[value]'], t('Message body is displayed.'));
  $this
    ->assertText(t('A message has been sent to @recipient.', array(
    '@recipient' => $user->name,
  )), t('Sent confirmation displayed.'));
}