function PrivatemsgAPITestCase::testPrivatemsgApiReply in Privatemsg 7.2
Same name and namespace in other branches
- 6.2 privatemsg.test \PrivatemsgAPITestCase::testPrivatemsgApiReply()
- 6 tests/privatemsgapi.test \PrivatemsgAPITestCase::testPrivatemsgApiReply()
- 7 privatemsg.test \PrivatemsgAPITestCase::testPrivatemsgApiReply()
File
- ./
privatemsg.test, line 1396 - 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');
$this
->assertEqual($thread_row->reply_to_mid, 0, t('First message is not a reply to a thread.'));
$resultok = privatemsg_reply($thread_row->mid, 'Test Body', array(
'author' => $author,
));
$this
->assertTrue($resultok['success'], 'Reply could be sent successfully');
$reply_to_mid = db_query('SELECT reply_to_mid FROM {pm_message} WHERE mid = :mid', array(
':mid' => $resultok['message']->mid,
))
->fetchField();
$this
->assertEqual($reply_to_mid, $thread_row->mid, t('Reply is marked as reply of first message.'));
$resultok = privatemsg_reply($thread_row->mid, 'Test Body', array(
'author' => $recipient1,
));
$this
->assertTrue($resultok['success'], 'Reply could be sent successfully');
$reply_to_mid = db_query('SELECT reply_to_mid FROM {pm_message} WHERE mid = :mid', array(
':mid' => $resultok['message']->mid,
))
->fetchField();
$this
->assertEqual($reply_to_mid, $thread_row->mid, t('Reply is marked as reply of first message.'));
$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');
}