public function PrivatemsgServiceTestCase::testPrivatemsgServiceReply in Privatemsg 6.2
Test privatemsg.send service (reply to a thread through services)
File
- privatemsg_service/
privatemsg_service.test, line 181 - Privatemsg Services test
Class
- PrivatemsgServiceTestCase
- Tests for services integration.
Code
public function testPrivatemsgServiceReply() {
// Setup 2 users.
$author_permissions = array(
'write privatemsg',
'administer services',
'access administration pages',
'get private messages from remote',
);
$author = $this
->drupalCreateUser($author_permissions);
$recipient_permissions = array(
'write privatemsg',
'administer services',
'access administration pages',
'get private messages from remote',
'send private messages from remote',
);
$recipient = $this
->drupalCreateUser($recipient_permissions);
// Author sends a message to recipient.
$subject = 'My First Message';
$body = $this
->randomName(20);
$message = privatemsg_new_thread(array(
$recipient,
), $subject, $body, array(
'author' => $author,
));
// Recipient logs in and navigates to the services admin page to send a message.
$this
->drupalLogin($recipient);
$this
->drupalGet('admin/build/services/browse/privatemsg.reply');
// Recipient replies to the first thread sent by author.
$edit = array(
'arg[0]' => 'This is my reply body.',
'arg[1]' => $message['message']['thread_id'],
);
$this
->drupalPost('admin/build/services/browse/privatemsg.reply', $edit, t('Call method'));
// Make sure the reply got sent out successfully.
$this
->assertRaw('<h3>Result</h3><code><pre>1</pre></code>', t('Reply was successfully sent by recipient.'));
// Login the author and make sure he received the reply (testing through services call).
$this
->drupalLogin($author);
$this
->drupalGet('admin/build/services/browse/privatemsg.getThread');
// Have recipient click on the "Call method" button.
$edit = array(
'arg[0]' => $message['message']['thread_id'],
);
$this
->drupalPost('admin/build/services/browse/privatemsg.getThread', $edit, t('Call method'));
// Make sure the that the reply from the recipient is visible in thread #1.
$this
->assertRaw('This is my reply', t('Verify that author received the reply from recipient.'));
}