function PrivatemsgURLPrefixTestCase::checkPrefix in Privatemsg 6.2
Take a URL prefix and try some private message functionality to ensure that everything is working as expected.
2 calls to PrivatemsgURLPrefixTestCase::checkPrefix()
- PrivatemsgURLPrefixTestCase::testPrefix in ./
privatemsg.test - Test that basic URL prefixes work properly.
- PrivatemsgURLPrefixTestCase::testPrefixUser in ./
privatemsg.test - Test that basic URL prefixes with %user work properly.
File
- ./
privatemsg.test, line 952 - Test file for privatemsg.module
Class
- PrivatemsgURLPrefixTestCase
- Test privatemsg URL prefixes.
Code
function checkPrefix($url_prefix) {
$author = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
));
$recipient = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
'tag private messages',
'create private message tags',
));
$admin = $this
->drupalCreateUser(array(
'write privatemsg',
'read privatemsg',
'read all private messages',
'administer privatemsg settings',
'administer blocks',
));
// Create a node that is used later to test link generation.
$node = $this
->drupalCreateNode();
// Login as admin, set prefix, and set blocks.
$this
->drupalLogin($admin);
$settings = array(
'privatemsg_url_prefix' => $url_prefix,
'privatemsg_display_fields[tags]' => 'tags',
);
$this
->drupalPost('admin/settings/messages', $settings, t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
// Check that 'Messages' link does not show up in main nav if using %user token. Do this before enabling blocks.
if (strpos($url_prefix, '%user') !== FALSE) {
$this
->drupalGet('');
$this
->assertNoText(t('Messages'), t('Messages link should not be found in navigation menu.'));
}
$blocks = array(
'privatemsg_privatemsg-new[region]' => 'left',
'privatemsg_privatemsg-menu[region]' => 'left',
);
$this
->drupalPost('admin/build/block', $blocks, t('Save blocks'));
// Login as author.
$this
->drupalLogin($author);
// Create new message.
$edit = array(
'recipient' => $recipient->name,
'subject' => $this
->randomName(20),
'body' => $this
->randomName(100),
);
$this
->drupalPost(privatemsg_get_dynamic_url_prefix($author->uid) . '/new', $edit, t('Send message'));
$this
->assertText(t('A message has been sent to @recipients.', array(
'@recipients' => $recipient->name,
)), t('Message sent confirmation displayed'));
$this
->assertText($edit['body'], t('Message body found using default submit redirect (<new-message>).'));
// From privatemsg_filter.
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($author->uid) . '/sent');
$this
->assertText($edit['subject'], t('Message found on message sent page.'));
// Check for correct !message URL in sent email from pm_email_notify.
$captured_emails = $this
->drupalGetMails();
$this
->drupalSetContent($captured_emails['0']['body']);
$this
->assertText(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/view/', t('Found correct message link (' . privatemsg_get_dynamic_url_prefix($recipient->uid) . ') in email body: ') . $captured_emails['0']['body']);
// Login as recipient.
$this
->drupalLogin($recipient);
$this
->assertText(t('You have 1 unread message'), t('New message text found after login.'));
$this
->clickLink(t('1 unread message'));
$this
->assertText($edit['subject'], t('Message found after clicking on login message link.'));
// Go to the previously created node to verify that it does not use the nid
// as the user id.
$this
->drupalGet('node/' . $node->nid);
$this
->clickLink(t('You have a new message! Click here to read it.'));
$this
->assertText($edit['subject'], t('Message found on root message list page.'));
// Try the private message block links.
$this
->clickLink(t('Messages (@count new)', array(
'@count' => 1,
)));
$this
->assertText($edit['subject'], t('Message found on root message after clicking from Private Messages block.'));
$this
->clickLink(t('Write new message'));
$this
->assertText(t('Write new message'), t('Write new message title found.'));
$this
->clickLink(t('You have a new message! Click here to read it.'));
$this
->assertText($edit['subject'], t('Message found after clicking link on new message block.'));
// From privatemsg_filter.
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/inbox');
$this
->assertText($edit['subject'], t('Message found on inbox message list page.'));
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/list');
$this
->assertText($edit['subject'], t('Message found on message list page.'));
// Click on the message.
$this
->clickLink($edit['subject']);
$this
->assertText($edit['body'], t('Message body found on message view.'));
// Tag a message to verify that the tag shows up.
$tagging = array(
'tags' => $this
->randomName(5),
);
$this
->clickLink(t('Tag this conversation'));
$this
->drupalPost(NULL, $tagging, t('Tag this conversation'));
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/inbox');
$this
->assertText($tagging['tags'], t('Tag found in inbox.'));
$this
->clickLink($edit['subject']);
// Check that blocked users path works as expected.
$this
->clickLink('Block');
$this
->drupalPost(NULL, NULL, t('Block @user', array(
'@user' => $author->name,
)));
$this
->assertText(t('@author has been blocked from sending you any further messages.', array(
'@author' => $author->name,
)), 'Check for block confirmation text.');
$this
->assertText($edit['body'], t('Check that we were taken back to message after block.'));
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/blocked');
$this
->assertText($author->name, t('Author name found on blocked user page.'));
// Since this user doesn't have read all, test that they are actually denied on other user's message page.
if (strpos($url_prefix, '%user') !== FALSE) {
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($author->uid));
}
else {
$this
->drupalGet('user/' . $author->uid . '/messages');
}
$this
->assertResponse(403, t('Access denied on other users messages page for users without read all permission.'));
// Log back in as $admin to test read all.
$this
->drupalLogin($admin);
if (strpos($url_prefix, '%user') !== FALSE) {
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($recipient->uid));
}
else {
$this
->drupalGet('user/' . $recipient->uid . '/messages');
}
$this
->assertText($edit['subject'], t('Message found on author list page with read all permission.'));
$this
->clickLink($edit['subject']);
$this
->assertText($edit['body'], t('Message body found on profile message view.'));
$this
->assertTrue(strpos($this
->getUrl(), privatemsg_get_dynamic_url_prefix($recipient->uid)), t('Check that message view link from profile is in the proper place.'));
// Check that write message and block are denied from user/%uid/foo/{new|blocked}.
if (strpos($url_prefix, '%user') !== FALSE) {
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/new');
$this
->assertResponse(403, t('Access denied for write new message on profile page'));
$this
->drupalGet(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/blocked');
$this
->assertResponse(403, t('Access denied for blocked users page on profile page'));
}
}