You are here

function PrivatemsgTagsTestCase::testInboxTagging in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_filter/privatemsg_filter.test \PrivatemsgTagsTestCase::testInboxTagging()
  2. 6 privatemsg_filter/privatemsg_filter.test \PrivatemsgTagsTestCase::testInboxTagging()
  3. 7.2 privatemsg_filter/privatemsg_filter.test \PrivatemsgTagsTestCase::testInboxTagging()

File

privatemsg_filter/privatemsg_filter.test, line 351
Contains tests for the privatemsg_filter module.

Class

PrivatemsgTagsTestCase
Test filters, tags and inbox/sent handling.

Code

function testInboxTagging() {
  $webuser = $this
    ->drupalCreateuser(array(
    'read privatemsg',
    'write privatemsg',
    'tag private messages',
    'create private message tags',
  ));
  $admin = $this
    ->drupalCreateUser(array(
    'administer privatemsg settings',
  ));

  // Display tag column in thread list.
  $this
    ->drupalLogin($admin);
  $this
    ->drupalPost('admin/config/messaging/privatemsg', array(
    'privatemsg_display_fields[tags]' => 'tags',
  ), t('Save configuration'));

  // Create a new thread through the api.
  $response = privatemsg_new_thread(array(
    $webuser,
  ), $subject1 = $this
    ->randomName(10), $this
    ->randomName(20), array(
    'author' => $webuser,
  ));
  $thread_id = $response['message']->thread_id;
  $tag1 = $this
    ->randomName();
  $tag2 = $this
    ->randomName();
  $edit = array(
    'tags' => $tag1 . ', ' . $tag2,
  );
  $this
    ->drupalLogin($webuser);
  $this
    ->drupalGet('messages/view/' . $thread_id);
  $this
    ->clickLink(t('Tag this conversation'));
  $this
    ->drupalPost(NULL, $edit, t('Tag this conversation'));
  $this
    ->assertText($tag1, t('Found message tag'));
  $this
    ->assertText($tag2, t('Found message tag'));

  // Create another thread.
  $response = privatemsg_new_thread(array(
    $webuser,
  ), $subject2 = $this
    ->randomName(10), $this
    ->randomName(20), array(
    'author' => $webuser,
  ));
  $thread_id2 = $response['message']->thread_id;
  $this
    ->drupalGet('messages');
  $rows = $this
    ->xpath('//tbody/tr');
  foreach ($rows as $row) {
    if ($row->td[2]->a == $subject1) {

      // The first thread should have both tags. Try both ways as the order
      // might change.
      $verify = $tag1 == $row->td[1]->a[0] && $tag2 == $row->td[1]->a[1] || $tag1 == $row->td[1]->a[1] && $tag2 == $row->td[1]->a[0];
      $this
        ->assertTrue($verify, t('First thread is correctly tagged.'));
    }
    if ($row->td[2]->a == $subject2) {

      // The second thread should have no tags.
      $this
        ->assertEqual('', $row->td[1], t('Second thread is not tagged.'));
    }
  }
  $add_tag = array(
    'list[' . $thread_id2 . ']' => 1,
    'tag-add' => $tag2,
  );
  $this
    ->drupalPost(NULL, $add_tag, t('Apply Tag'));
  $rows = $this
    ->xpath('//tbody/tr');
  foreach ($rows as $row) {
    if ($row->td[2]->a == $subject1) {

      // The first thread should have both tags. Try both ways as the order
      // might change.
      $verify = $tag1 == $row->td[1]->a[0] && $tag2 == $row->td[1]->a[1] || $tag1 == $row->td[1]->a[1] && $tag2 == $row->td[1]->a[0];
      $this
        ->assertTrue($verify, t('First thread is correctly tagged.'));
    }
    if ($row->td[2]->a == $subject2) {

      // The second thread should have one tag.
      $this
        ->assertEqual($tag2, $row->td[1]->a, t('Second thread is correctly tagged.'));
    }
  }
  $remove_tag = array(
    'list[' . $thread_id . ']' => 1,
    'list[' . $thread_id2 . ']' => 1,
    'tag-remove' => 3,
  );
  $this
    ->drupalPost(NULL, $remove_tag, t('Remove Tag'));
  $rows = $this
    ->xpath('//tbody/tr');
  foreach ($rows as $row) {
    if ($row->td[2]->a == $subject1) {

      // The first thread should have only one tag now.
      $this
        ->assertEqual($tag1, $row->td[1]->a, t('First thread is correctly tagged.'));
    }
    if ($row->td[2]->a == $subject2) {

      // The second thread should have no tags.
      $this
        ->assertEqual('', $row->td[1], t('Second thread is not tagged.'));
    }
  }
  $this
    ->assertNoText($tag2, t('Second tag is not displayed anymore.'));
}