You are here

function PrivatemsgAPITestCase::testPrivatemsgApiReply in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg.test \PrivatemsgAPITestCase::testPrivatemsgApiReply()
  2. 6 tests/privatemsgapi.test \PrivatemsgAPITestCase::testPrivatemsgApiReply()
  3. 7.2 privatemsg.test \PrivatemsgAPITestCase::testPrivatemsgApiReply()

File

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

Class

PrivatemsgAPITestCase
Privatemsg API tests

Code

function testPrivatemsgApiReply() {
  $author = $this
    ->drupalCreateUser(array(
    'write privatemsg',
  ));
  $recipient1 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
  ));
  $recipient2 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
  ));
  $recipient3 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
  ));

  // Reset user_access cache
  user_access('', $author, TRUE);
  $resultok = privatemsg_new_thread(array(
    $recipient2,
    $recipient1,
    $recipient3,
  ), 'test reply', 'body text', array(
    'author' => $author,
  ));
  $this
    ->assertTrue($resultok['success'], 'Private message could be sent successfully');
  $thread_row = $this
    ->getMessageFromSubject('test reply');
  $resultok = privatemsg_reply($thread_row->mid, 'Test Body', array(
    'author' => $author,
  ));
  $this
    ->assertTrue($resultok['success'], 'Reply could be sent successfully');
  $resultok = privatemsg_reply($thread_row->mid, 'Test Body', array(
    'author' => $recipient1,
  ));
  $this
    ->assertTrue($resultok['success'], 'Reply could be sent successfully');
  $resultf1 = privatemsg_reply($thread_row->mid, '', array(
    'author' => $recipient2,
  ));
  $this
    ->assertFalse($resultf1['success'], 'API denied to send message without body.');
  $this
    ->assertEqual($resultf1['messages']['error'][0], t('A message must be included in your reply.'), 'Correct error returned when replying with an empty body.');
  $resultf2 = privatemsg_reply($thread_row->mid, 'Test Body', array(
    'author' => $recipient3,
  ));
  $errormessage = t('@user is not allowed to write messages.', array(
    '@user' => $recipient3->name,
  ));
  $this
    ->assertEqual($errormessage, $resultf2['messages']['error'][0], 'API denied to send message from user without permission');
}