You are here

function PrivatemsgLinksTestCase::testAuthorLinks in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 privatemsg.test \PrivatemsgLinksTestCase::testAuthorLinks()
  2. 7 privatemsg.test \PrivatemsgLinksTestCase::testAuthorLinks()

Tests author links displayed on nodes and comments.

File

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

Class

PrivatemsgLinksTestCase
Tests for fields integration.

Code

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'],
  )));
}