class PrivatemsgFieldsTestCase

  1. 7-1 privatemsg.test PrivatemsgFieldsTestCase
  2. 7-2 privatemsg.test PrivatemsgFieldsTestCase

Tests for fields integration.

Hierarchy

Expanded class hierarchy of PrivatemsgFieldsTestCase

File

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

View source
class PrivatemsgFieldsTestCase extends PrivatemsgBaseTestCase {
  /**
   * Implements getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => t('Privatemsg fields.'),
      'description' => t('Tests integration with fields.'),
      'group' => t('Privatemsg'),
    );
  }

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

  function testSingleField() {
    $admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
    $user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));

    $this->drupalLogin($admin);

    // Create a new field.
    $edit = array(
      'fields[_add_new_field][label]' => $this->randomName(),
      'fields[_add_new_field][field_name]' => $name = strtolower($this->randomName()),
      'fields[_add_new_field][type]' => 'text',
      'fields[_add_new_field][widget_type]' => 'text_textfield',
    );
    $this->drupalPost('admin/config/messaging/privatemsg/fields', $edit, t('Save'));
    $this->drupalPost(NULL, array(), t('Save field settings'));
    $this->drupalPost(NULL, array(), t('Save settings'));

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

    // Preview message.
    $message = array(
      'recipient' => $user->name,
      'subject' => $this->randomName(),
      'body[value]' => $this->randomName(50),
      'field_' . $name . '[und][0][value]' => $this->randomName(50),
    );
    $this->drupalPost('messages/new', $message, t('Preview message'));

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

    // Check message.
    $this->drupalLogin($user);
    $this->drupalGet('messages');
    $this->clickLink($message['subject']);

    $this->assertText($message['body[value]'], t('Message body displayed.'));
    $this->assertText($message['field_' . $name . '[und][0][value]'], t('Content of new field is displayed.'));

    // Respond.
    $response = array(
      'body[value]' => $this->randomName(50),
      'field_' . $name . '[und][0][value]' => $this->randomName(50),
    );
    $this->drupalPost(NULL, $response, t('Send message'));

    // Check response.
    $this->drupalLogin($admin);
    $this->drupalGet('messages');
    $this->clickLink($message['subject']);

    $this->assertText($response['body[value]'], t('Message body displayed.'));
    $this->assertText($response['field_' . $name . '[und][0][value]'], t('Content of new field is displayed.'));
  }

  /**
   * Verify that a message with an empty image can be sent.
   */
  function testEmptyImage() {
    $admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
    $user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));

    $this->drupalLogin($admin);

    // Create a new field.
    $edit = array(
      'fields[_add_new_field][label]' => $this->randomName(),
      'fields[_add_new_field][field_name]' => strtolower($this->randomName()),
      'fields[_add_new_field][type]' => 'image',
      'fields[_add_new_field][widget_type]' => 'image_image',
    );
    $this->drupalPost('admin/config/messaging/privatemsg/fields', $edit, t('Save'));
    $this->drupalPost(NULL, array(), t('Save field settings'));
    $this->drupalPost(NULL, array(), t('Save settings'));

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

    // Preview message.
    $message = array(
      'recipient' => $user->name,
      'subject' => $this->randomName(),
      'body[value]' => $this->randomName(50),
    );
    $this->drupalPost('messages/new', $message, t('Preview message'));

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

    // Check message.
    $this->drupalLogin($user);
    $this->drupalGet('messages');
    $this->clickLink($message['subject']);

    $this->assertText($message['body[value]'], t('Message body displayed.'));
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
PrivatemsgBaseTestCase::$profile protected property Use testing profile.
PrivatemsgFieldsTestCase::getInfo public static function Implements getInfo().
PrivatemsgFieldsTestCase::setUp function Implements setUp().
PrivatemsgFieldsTestCase::testEmptyImage function Verify that a message with an empty image can be sent.
PrivatemsgFieldsTestCase::testSingleField function