class PrivatemsgLinksTestCase

  1. 1 privatemsg.test PrivatemsgLinksTestCase
  2. 7-1 privatemsg.test PrivatemsgLinksTestCase
  3. 7-2 privatemsg.test PrivatemsgLinksTestCase
  4. 6-2 privatemsg.test PrivatemsgLinksTestCase

Tests for fields integration.

Hierarchy

Expanded class hierarchy of PrivatemsgLinksTestCase

File

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

View source
class PrivatemsgLinksTestCase extends PrivatemsgBaseTestCase {

  /**
   * Use testing profile.
   */
  protected $profile = 'standard';

  /**
   * Implements of getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => t('Privatemsg links'),
      'description' => t('Tests links displayed in nodes, profiles and blocks.'),
      'group' => t('Privatemsg'),
    );
  }

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

  /**
   * Tests author links displayed on nodes and comments.
   */
  function testAuthorLinks() {
    $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'create article content', 'create page content'));
    $user = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));

    $this->drupalLogin($admin);

    $settings = array(
      'privatemsg_display_link_self' => FALSE,
      'privatemsg_link_node_types[article]' => TRUE,
      'privatemsg_display_on_teaser' => FALSE,
      'privatemsg_display_on_comments' => TRUE,
    );
    $this->drupalPost('admin/config/messaging/privatemsg', $settings, t('Save configuration'));

    $node1 = array(
      'title' => $this->randomName(10),
      'body[und][0][value]' => $this->randomString(50),
    );
    $this->drupalPost('node/add/article', $node1, t('Save'));

    $comment = array('comment_body[und][0][value]' => $this->randomName(20));
    $this->drupalPost(NULL, $comment, t('Save'));

    $node2 = array(
      'title' => $this->randomName(),
      'body[und][0][value]' => $this->randomString(50),
    );
    $this->drupalPost('node/add/page', $node2, t('Save'));

    $this->drupalGet('node');
    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
    $this->clickLink($node1['title']);
    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));

    $this->drupalLogin($user);
    $this->drupalGet('node');
    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
    $this->clickLink($node1['title']);
    $this->assertNoUniqueText(t('Send author a message'), t('Send author a message link displayed.'));

    $this->clickLink(t('Send author a message'));
    // To field and subject should be correctly pre-filled now.
    $this->drupalPost(NULL, array(), t('Send message'));

    // Make sure the message was sent to the correct user.
    $this->assertText(t('A message has been sent to @user', array('@user' => $admin->name)));

    // @todo: Do not guess nid.
    $this->drupalGet('node/2');
    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));

    $this->drupalLogin($admin);
    $this->drupalGet('messages');
    $this->assertText(t('Message regarding @node', array('@node' => $node1['title'])));
  }

  /**
   * Tests menu block.
   */
  function testMenuBlock() {
    $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'administer blocks', 'administer menu'));
    $user = $this->drupalCreateUser(array('read privatemsg'));

    // Enable block.
    $this->drupalLogin($admin);
    $blocks = array('blocks[privatemsg_privatemsg-menu][region]' => 'sidebar_second');
    $this->drupalPost('admin/structure/block', $blocks, t('Save blocks'));

    // Disable secondary menu.
    /* @todo: Not yet possible because simpletest needs a log out link to verify that the user is logged in.
     $menu_settings = array(
     'menu_secondary_links_source' => '',
     );
     $this->drupalPost('admin/structure/menu/settings', $menu_settings, t('Save configuration'));
     *
     */

    $this->drupalGet('');
    $this->assertText(t('Private messages'), t('Privatemsg menu block title displayed.'));
    $this->assertText('Write new message', t('Write new message link displayed.'));

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

    $this->drupalLogin($user);
    $this->assertNoText(t('Write new message'), t('Write new message link not displayed.'));
    $this->assertNoUniqueText(t('Messages (1 new)'), t('Messages link including new message information displayed'));
  }

  /**
   * Tests menu block.
   */
  function testNewBlock() {
    $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'administer blocks', 'administer menu'));
    $user = $this->drupalCreateUser(array('read privatemsg'));

    // Enable block.
    $this->drupalLogin($admin);
    $blocks = array('blocks[privatemsg_privatemsg-new][region]' => 'sidebar_second');
    $this->drupalPost('admin/structure/block', $blocks, t('Save blocks'));

    $this->drupalGet('');
    $this->assertNoText(t('Unread message'), t('Privatemsg unread message block title not displayed.'));

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

    $this->drupalLogin($user);
    $this->assertText(t('Unread message'), t('Privatemsg unread message block title displayed.'));

    $this->assertText(t('You have an unread message! Click here to read it.'), t('Unread message indication displayed.'));
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
PrivatemsgLinksTestCase::$profile protected property Use testing profile. Overrides PrivatemsgBaseTestCase::$profile
PrivatemsgLinksTestCase::getInfo public static function Implements of getInfo().
PrivatemsgLinksTestCase::setUp function Implements setUp().
PrivatemsgLinksTestCase::testAuthorLinks function Tests author links displayed on nodes and comments.
PrivatemsgLinksTestCase::testMenuBlock function Tests menu block.
PrivatemsgLinksTestCase::testNewBlock function Tests menu block.