You are here

function PrivatemsgAPITestCase::testPrivatemsgApiReply in Privatemsg 6

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

File

tests/privatemsgapi.test, line 87
Privatemsg API tests

Class

PrivatemsgAPITestCase
@file 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('Disallowed to send reply without a message.'), 'Correct error returned when replying with an empty body.');
  $resultf2 = privatemsg_reply($thread_row['mid'], 'Test Body', array(
    'author' => $recipient3,
  ));
  $errormessage = 'User ' . $recipient3->name . ' is not allowed to write messages';
  $this
    ->assertEqual($errormessage, $resultf2['messages']['error'][0], 'API denied to send message from user without permission');
}