privatemsg.test

  1. 1 privatemsg.test
  2. 7-1 privatemsg.test
  3. 7-2 privatemsg.test
  4. 6-2 privatemsg.test

Test file for privatemsg.module

File

privatemsg.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test file for privatemsg.module
  5. *
  6. */
  7. /**
  8. * Base class for Privatemsg tests.
  9. */
  10. class PrivatemsgBaseTestCase extends DrupalWebTestCase {
  11. /**
  12. * Use testing profile.
  13. */
  14. protected $profile = 'testing';
  15. }
  16. class PrivatemsgTestCase extends PrivatemsgBaseTestCase {
  17. /**
  18. * Implements getInfo().
  19. */
  20. public static function getInfo() {
  21. return array
  22. (
  23. // 'name' should start with what is being tested (menu item) followed by what about it
  24. // is being tested (creation/deletion).
  25. 'name' => t('Privatemsg functionality.'),
  26. // 'description' should be one or more complete sentences that provide more details on what
  27. // exactly is being tested.
  28. 'description' => t('Test sending, receiving, listing, deleting messages and other features.'),
  29. // 'group' should be a logical grouping of test cases, like a category. In most cases, that
  30. // is the module the test case is for.
  31. 'group' => t('Privatemsg'),
  32. );
  33. }
  34. /**
  35. * Implements setUp().
  36. */
  37. function setUp() {
  38. parent::setUp('privatemsg');
  39. // Create the full html format.
  40. $full_html_format = array(
  41. 'format' => 'full_html',
  42. 'name' => 'Full HTML',
  43. 'weight' => 1,
  44. 'filters' => array(
  45. // URL filter.
  46. 'filter_url' => array(
  47. 'weight' => 0,
  48. 'status' => 1,
  49. ),
  50. // Line break filter.
  51. 'filter_autop' => array(
  52. 'weight' => 1,
  53. 'status' => 1,
  54. ),
  55. // HTML corrector filter.
  56. 'filter_htmlcorrector' => array(
  57. 'weight' => 10,
  58. 'status' => 1,
  59. ),
  60. ),
  61. );
  62. $full_html_format = (object) $full_html_format;
  63. filter_format_save($full_html_format);
  64. // Refresh permissions.
  65. $this->checkPermissions(array(), TRUE);
  66. }
  67. /**
  68. * Test user access to /messages
  69. * Create user with no 'read privatemsg' permission. Try to access mailbox and see if it gives access denied error
  70. * Create user with 'read privatemsg' permission. Try to access mailbox and see if it gives allows access
  71. */
  72. function testPrivatemsgReadPrivatemsgPermission() {
  73. $user_no_read_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
  74. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  75. $recipient = $this->drupalCreateUser(array('read privatemsg'));
  76. $no_recipient = $this->drupalCreateUser(array('read privatemsg'));
  77. $subject = $this->randomName(20);
  78. $body = $this->randomName(50);
  79. $response = privatemsg_new_thread(array($recipient), $subject, $body, array('author' => $author));
  80. $this->drupalLogin($user_no_read_msg);
  81. $this->drupalGet('messages');
  82. $this->assertResponse(403, t('HTTP Response 403: Access to mailbox was blocked to user without "<em>read privatemsg</em>" permission'));
  83. $this->drupalLogin($no_recipient);
  84. $this->drupalGet('messages');
  85. $this->assertResponse(200, t('HTTP Response 200: Access to mailbox was authorized to user with "<em>read privatemsg</em>" permission'));
  86. $this->drupalGet('messages/view/' . $response['message']->thread_id);
  87. $this->assertResponse(403, t('HTTP Response 403: Access to thread is blocked for non-recipients.'));
  88. $this->drupalLogin($recipient);
  89. $this->drupalGet('messages/view/' . $response['message']->thread_id);
  90. $this->assertText($subject, t('Access to thread for recipient allowed.'));
  91. $this->drupalGet('messages/view/' . $response['message']->thread_id + 1);
  92. $this->assertResponse(404, t('Non-existing thread lead to HTTP Response 404.'));
  93. }
  94. /**
  95. * Test user access to /messages/new
  96. * Create user with no 'write privatemsg' permission. Try to access Write New Message page and see if it gives access denied error
  97. * Create user with 'write privatemsg' permission. Try to access Write New Message page and see if it gives allows access
  98. */
  99. function testPrivatemsgWritePrivatemsgPermission() {
  100. $user_no_write_msg = $this->drupalCreateUser(); // set up user with default permissions (meaning: no read privatemsg permission
  101. $this->drupalLogin($user_no_write_msg);
  102. $this->drupalGet('messages/new');
  103. $this->assertResponse(403, t('HTTP Response 403: Access to Write New Message page was blocked to user without "<em>write privatemsg</em>" permission'));
  104. $user_write_msg = $this->drupalCreateUser(array('write privatemsg')); // set up user with write privatemsg permissions
  105. $this->drupalLogin($user_write_msg);
  106. $this->drupalGet('messages/new');
  107. $this->assertResponse(200, t('HTTP Response 200: Access to Write New Message page was authorized to user with "<em>write privatemsg</em>" permission'));
  108. }
  109. function testPaging() {
  110. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  111. $recipient = $this->drupalCreateUser(array('read privatemsg'));
  112. // Set lower values so that we don't need to generate 100's of messages.
  113. variable_set('privatemsg_view_default_amount', 5);
  114. variable_set('privatemsg_view_max_amount', 10);
  115. $subject_single = $this->randomName(20);
  116. $subject = $this->randomName(20);
  117. $bodies = array();
  118. for ($i = 0; $i < 24; $i++) {
  119. $bodies[$i] = $this->randomName(100);
  120. }
  121. privatemsg_new_thread(array($recipient), $subject_single, $bodies[23], array('author' => $author));
  122. $thread = privatemsg_new_thread(array($recipient), $subject, $bodies[0], array('author' => $author));
  123. for ($i = 1; $i < 23; $i++) {
  124. privatemsg_reply($thread['message']->thread_id, $bodies[$i], array('author' => $author));
  125. }
  126. $this->drupalLogin($recipient);
  127. $this->drupalGet('messages');
  128. $this->clickLink($subject_single);
  129. $this->assertNoText(t('Displaying messages 1 - 1 of 1'), t('Pager is displayed'));
  130. $this->assertNoText(t('&gt;&gt;'), t('Newer messages link not displayed.'));
  131. $this->assertNoText(t('&lt;&lt;'), t('Older messages link not displayed.'));
  132. $this->drupalGet('messages');
  133. $this->clickLink($subject);
  134. // Verify that only the last 10 messages are displayed.
  135. $this->assertText(t('&lt;&lt; Displaying messages 14 - 23 of 23'), t('Pager is displayed'));
  136. $this->assertNoText($bodies[0], t('First message is not displayed.'));
  137. $this->assertNoText($bodies[12], t('Hidden message is not displayed.'));
  138. $this->assertText($bodies[13], t('Message is displayed.'));
  139. $this->assertText($bodies[22], t('Message is displayed.'));
  140. $this->assertNoText(t('&gt;&gt;'), t('Newer messages link not displayed.'));
  141. variable_set('privatemsg_view_use_max_as_default', TRUE);
  142. $this->drupalGet('messages');
  143. $this->clickLink($subject);
  144. // Now with separate default value.
  145. // Verify that only the last 5 messages are displayed.
  146. $this->assertText(t('&lt;&lt; Displaying messages 19 - 23 of 23'), t('Pager is displayed'));
  147. $this->assertNoText($bodies[0], t('First message is not displayed.'));
  148. $this->assertNoText($bodies[17], t('Hidden message is not displayed.'));
  149. $this->assertText($bodies[18], t('Message is displayed.'));
  150. $this->assertText($bodies[22], t('Message is displayed.'));
  151. $this->assertNoText(t('>>'), t('Newer messages link not displayed.'));
  152. // Load older messages and verify again.
  153. $this->clickLink(t('<<'));
  154. $this->assertText(t('&lt;&lt; Displaying messages 9 - 18 of 23 &gt;&gt;'), t('Pager is displayed'));
  155. $this->assertNoText($bodies[0], t('First message is not displayed.'));
  156. $this->assertNoText($bodies[7], t('Hidden message is not displayed.'));
  157. $this->assertText($bodies[8], t('Message is displayed.'));
  158. $this->assertText($bodies[17], t('Message is displayed.'));
  159. $this->assertNoText($bodies[22], t('Hidden message is not displayed.'));
  160. // Load older messages and verify again.
  161. $this->clickLink(t('<<'));
  162. $this->assertText(t('Displaying messages 1 - 8 of 23 &gt;&gt;'), t('Pager is displayed'));
  163. $this->assertText($bodies[0], t('Message is displayed.'));
  164. $this->assertText($bodies[7], t('Message is displayed.'));
  165. $this->assertNoText($bodies[9], t('Hidden message is not displayed.'));
  166. $this->assertNoText(t('&lt;&lt;'), t('Older messages link not displayed.'));
  167. // Going back should follow the same order.
  168. $this->clickLink(t('>>'));
  169. $this->assertText(t('&lt;&lt; Displaying messages 9 - 18 of 23 &gt;&gt;'), t('Pager is displayed'));
  170. $this->assertNoText($bodies[0], t('First message is not displayed.'));
  171. $this->assertNoText($bodies[7], t('Hidden message is not displayed.'));
  172. $this->assertText($bodies[8], t('Message is displayed.'));
  173. $this->assertText($bodies[17], t('Message is displayed.'));
  174. $this->assertNoText($bodies[22], t('Hidden message is not displayed.'));
  175. variable_set('privatemsg_view_max_amount', PRIVATEMSG_UNLIMITED);
  176. $this->drupalGet('messages');
  177. $this->clickLink($subject);
  178. // Now with separate default value.
  179. // Verify that only the last 5 messages are displayed.
  180. $this->assertText(t('&lt;&lt; Displaying messages 19 - 23 of 23'), t('Pager is displayed'));
  181. $this->assertNoText($bodies[0], t('First message is not displayed.'));
  182. $this->assertNoText($bodies[17], t('Hidden message is not displayed.'));
  183. $this->assertText($bodies[18], t('Message is displayed.'));
  184. $this->assertText($bodies[22], t('Message is displayed.'));
  185. $this->assertNoText(t('&gt;&gt;'), t('Newer messages link not displayed.'));
  186. // Load older messages and verify again.
  187. $this->clickLink(t('<<'));
  188. $this->assertNoText(t('Displaying messages 1 - 23 of 23'), t('Pager is displayed'));
  189. $this->assertText($bodies[0], t('Message is displayed.'));
  190. $this->assertText($bodies[22], t('Message is displayed.'));
  191. $this->assertNoText(t('&gt;&gt;'), t('Newer messages link not displayed.'));
  192. $this->assertNoText(t('&lt;&lt;'), t('Older messages link not displayed.'));
  193. // Check with max_amount = UNLIMITED and different default amount disabled.
  194. variable_set('privatemsg_view_use_max_as_default', FALSE);
  195. $this->drupalGet('messages');
  196. $this->clickLink($subject);
  197. $this->assertNoText(t('Displaying messages 1 - 23 of 23'), t('Pager is displayed'));
  198. $this->assertText($bodies[0], t('Message is displayed.'));
  199. $this->assertText($bodies[22], t('Message is displayed.'));
  200. $this->assertNoText(t('&gt;&gt;'), t('Newer messages link not displayed.'));
  201. $this->assertNoText(t('&lt;&lt;'), t('Older messages link not displayed.'));
  202. }
  203. /**
  204. * Test sending message from the /messages/new page between two people
  205. */
  206. function testWriteReplyPrivatemsg() {
  207. // Create an author and two recipients.
  208. $author = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'select text format for privatemsg', filter_permission_name(filter_format_load('full_html'))));
  209. $recipient = $this->drupalCreateUser(array('read privatemsg'));
  210. $recipient2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  211. // Set up a user with "read/write privatemsg" permissions.
  212. $blocked_recipient = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  213. // Block this recipient to test users who cancelled their accounts.
  214. user_save($blocked_recipient, array('status' => 0));
  215. // Login author and go to new message form.
  216. $this->drupalLogin($author);
  217. $this->drupalGet('messages/new');
  218. // Prepare edit arrays, single recipient with [user].
  219. $edit = array(
  220. 'recipient' => $recipient->name . ' [user]',
  221. 'subject' => $this->randomName(20),
  222. 'body[value]' => $this->randomName(100),
  223. );
  224. // Two recipients.
  225. $edit2 = array(
  226. 'recipient' => $recipient->name . ', ' . $recipient2->name,
  227. 'subject' => $this->randomName(20),
  228. 'body[value]' => $this->randomName(100),
  229. );
  230. // No recipients.
  231. $editnone = array(
  232. 'recipient' => '',
  233. 'subject' => $this->randomName(20),
  234. 'body[value]' => $this->randomName(100),
  235. );
  236. // Invalid recipient.
  237. $editinvalid = array(
  238. 'recipient' => $this->randomName(5),
  239. 'subject' => $this->randomName(20),
  240. 'body[value]' => $this->randomName(100),
  241. );
  242. // Blocked recipient.
  243. $editrecipientblocked = array(
  244. 'recipient' => $blocked_recipient->name,
  245. 'subject' => $this->randomName(20),
  246. 'body[value]' => $this->randomName(100),
  247. );
  248. // Message for which the author will be blocked later.
  249. $editauthorblocked = array(
  250. 'recipient' => $recipient2->name,
  251. 'subject' => $this->randomName(20),
  252. 'body[value]' => $this->randomName(100),
  253. );
  254. // Empty body.
  255. $editnobody = array(
  256. 'recipient' => $recipient->name,
  257. 'subject' => $this->randomName(20),
  258. 'body[value]' => '',
  259. );
  260. // Empty subject.
  261. $editnosubject = array(
  262. 'recipient' => $recipient->name,
  263. 'subject' => '',
  264. 'body[value]' => $this->randomName(100),
  265. );
  266. // Empty subject and body.
  267. $editempty = array(
  268. 'recipient' => $recipient->name,
  269. 'subject' => '',
  270. 'body[value]' => '',
  271. );
  272. // Empty subject and body.
  273. $editonlyspace = array(
  274. 'recipient' => $recipient2->name,
  275. 'subject' => ' ',
  276. 'body[value]' => $this->randomName(10),
  277. );
  278. // Invalid and valid recipient
  279. $editmixed = array(
  280. 'recipient' => ($invalidmixed = $this->randomName(5)) . ', ' . $recipient->name,
  281. 'subject' => $this->randomName(20),
  282. 'body[value]' => $this->randomName(100),
  283. );
  284. // message with a bold part, not allowed with default format
  285. $editformatted = array(
  286. 'recipient' => $recipient2->name,
  287. 'subject' => $this->randomName(20),
  288. 'body[value]' => $this->randomName(100) . '<b>formatted message #1</b>',
  289. 'body[format]' => 'full_html',
  290. );
  291. // Submit the messages.
  292. $this->drupalPost('messages/new', $edit, t('Send message'));
  293. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');
  294. $this->drupalPost('messages/new', $edit2, t('Send message'));
  295. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => implode(', ', array($recipient->name, $recipient2->name)))), 'Message sent confirmation displayed.');
  296. $this->drupalPost('messages/new', $editnone, t('Send message'));
  297. $this->assertText(t('To field is required.'), 'Message was not sent.');
  298. $this->drupalPost('messages/new', $editinvalid, t('Send message'));
  299. $this->assertText(t('You must include at least one valid recipient.'), 'Message was not sent.');
  300. $this->assertText(t('The following recipients will not receive this private message: @recipients.', array('@recipients' => $editinvalid['recipient'])), 'Message about non-existing user displayed.');
  301. $this->drupalPost('messages/new', $editrecipientblocked, t('Send message'));
  302. $this->assertText(t('@recipients has disabled his or her account.', array('@recipients' => $blocked_recipient->name)), 'Message about blocked user displayed.');
  303. $this->assertText(t('You are not allowed to send this message because all recipients are blocked.'), 'Message was not sent.');
  304. // We will block the author later to test whether the reply form appears.
  305. $this->drupalPost('messages/new', $editauthorblocked, t('Send message'));
  306. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient2->name)), 'Message sent confirmation displayed.');
  307. $this->drupalPost('messages/new', $editnobody, t('Send message'));
  308. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');
  309. $this->drupalPost('messages/new', $editnosubject, t('Send message'));
  310. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');
  311. $this->drupalPost('messages/new', $editempty, t('Send message'));
  312. $this->assertText(t('You must include a subject line or a message.'), 'Empty subject message displayed.');
  313. $this->drupalPost('messages/new', $editonlyspace, t('Send message'));
  314. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient2->name)), 'Message sent confirmation displayed.');
  315. $this->drupalPost('messages/new', $editmixed, t('Send message'));
  316. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');
  317. $this->assertText(t('The following recipients will not receive this private message: @recipients.', array('@recipients' => $invalidmixed)), 'Message about non-existing user displayed.');
  318. $this->drupalPost('messages/new', $editformatted, t('Send message'));
  319. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient2->name)), 'Message sent confirmation displayed.');
  320. // Login as recipient2 and try to write some replies.
  321. $this->drupalLogin($recipient2);
  322. $this->drupalGet('messages');
  323. // Check that the message with only a space in the subject uses the body
  324. // as subject.
  325. $this->clickLink($editonlyspace['body[value]']);
  326. $this->drupalGet('messages');
  327. $this->assertNoText($edit['subject'], 'Message sent to other recipient not found.');
  328. $this->assertText($edit2['subject'], 'Sent message subject found.');
  329. $this->clickLink($edit2['subject']);
  330. $this->assertText($edit2['body[value]'], 'Found message body.');
  331. // Prepare replies.
  332. $reply = array(
  333. 'body[value]' => $this->randomName(100),
  334. );
  335. // Empty body.
  336. $replyempty = array(
  337. 'body[value]' => '',
  338. );
  339. $this->drupalPost(NULL, $reply, t('Send message'));
  340. $this->assertText($reply['body[value]'], 'New message body displayed.');
  341. $this->drupalPost(NULL, $replyempty, t('Send message'));
  342. $this->assertText(t('You must include a message in your reply.'));
  343. // reply with a bold part, not allowed with default format
  344. $replyformatted = array(
  345. 'body[value]' => $this->randomName(100) . '<b>formatted message #2</b>',
  346. );
  347. $this->drupalGet('messages');
  348. $this->clickLink($editformatted['subject']);
  349. $this->assertRaw($editformatted['body[value]'], 'Found formatted message body.');
  350. $this->drupalPost(NULL, $replyformatted, t('Send message'));
  351. $this->assertNoRaw($replyformatted['body[value]'], 'Did not find formatted reply body.');
  352. $this->assertText(check_plain($replyformatted['body[value]']), 'New reply body displayed.');
  353. // Login using recipient and try to read the message by going to inbox first.
  354. $this->drupalLogin($recipient);
  355. $this->drupalGet('messages');
  356. // Assert if we see the subject of the messages.
  357. $this->assertText($edit['subject'], 'Sent message subject found.');
  358. $this->assertText($edit2['subject'], 'Sent message subject found.');
  359. $this->assertText($editnobody['subject'], 'Sent message subject found.');
  360. $this->assertText(trim(truncate_utf8(strip_tags($editnosubject['body[value]']), 50, TRUE, TRUE)), 'Sent message subject found.');
  361. $this->assertText($editmixed['subject'], 'Sent message subject found.');
  362. // Assert that we don't see those that were invalid.
  363. $this->assertNoText($editnone['subject'], 'Invalid message subject not found.');
  364. $this->assertNoText($editinvalid['subject'], 'Invalid message subject not found.');
  365. // Navigate into the message.
  366. $this->clickLink($edit['subject']);
  367. // Confirm that we can read the message that was sent.
  368. $this->assertText($edit['body[value]'], 'Found message body.');
  369. $this->assertNoText(t('Reply to thread:'), 'Reply form is not displayed.');
  370. // Verify that the participants information is correct.
  371. $this->assertText(t('Between you and @author', array('@author' => $author->name)));
  372. // Navigate into the message.
  373. $this->drupalGet('messages');
  374. $this->clickLink($edit2['subject']);
  375. // Confirm that we can read the message that was sent.
  376. $this->assertText($edit2['body[value]'], 'Found message body.');
  377. // Confirm that we can read the reply that was sent.
  378. $this->assertText($reply['body[value]'], 'Found reply body.');
  379. // Block the author.
  380. user_save($author, array('status' => 0));
  381. $this->drupalLogin($recipient2);
  382. // Navigate into the message.
  383. $this->drupalGet('messages');
  384. $this->clickLink($editauthorblocked['subject']);
  385. // Confirm that the reply form is not shown.
  386. $this->assertNoText(t('Reply'), 'Reply form is not displayed.');
  387. $this->assertText(t('You can not reply to this conversation because all recipients are blocked.'));
  388. }
  389. /**
  390. * Test functionality around disabling private messaging.
  391. */
  392. function testDisablePrivatemsg() {
  393. $admin_user = $this->drupalCreateUser(array('administer permissions'));
  394. $enableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); // set up user with read/write privatemsg permissions
  395. $enableduser2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg')); // set up user with read/write privatemsg permissions
  396. $disableduser = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'allow disabling privatemsg')); // set up user with read/write privatemsg permissions
  397. // Create a message between the users that we can use to test
  398. $return = privatemsg_new_thread(array($disableduser), $this->randomName(20), $this->randomName(100), array('author' => $enableduser));
  399. $return['message']->thread_id;
  400. $this->drupalLogin($disableduser);
  401. // Now disable $disabledUser.
  402. $this->drupalGet('user/' . $disableduser->uid . '/edit');
  403. $edit['pm_enable'] = FALSE;
  404. $this->drupalPost('user/' . $disableduser->uid . '/edit', $edit, t('Save'));
  405. // Verify that disableduser can list messages.
  406. $this->drupalGet('messages');
  407. $this->assertResponse(200, t('HTTP Response 200: Access to reading messages page is allowed.'));
  408. // Verify that $disableduser can read messages but there is not reply form
  409. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  410. $this->assertResponse(200, t('HTTP Response 200: Access to message thread page is allowed.'));
  411. $this->assertNoText(t('Reply to thread'), 'No reply form shown.');
  412. // Verify that $disableduser cannot send a new message.
  413. $this->drupalGet('messages/new');
  414. $this->assertResponse(403, t('HTTP Response 403: Access to Write New Message page was blocked to user with private messaging disabled'));
  415. // Clear static cache.
  416. drupal_static_reset('privatemsg_settings');
  417. // Check that $disableduser cannot submit a reply
  418. $result = privatemsg_reply($return['message']->thread_id, $this->randomName(100), array('author' => $disableduser));
  419. $this->assertFalse($result['success'], 'Message reply was not sent.');
  420. // Log in as $enableduser and try to send to $disabled user.
  421. // Make sure that a message to multiple recipients still works if one is
  422. // disabled.
  423. $message = array(
  424. 'recipient' => $disableduser->name,
  425. 'subject' => $this->randomName(20),
  426. 'body[value]' => $this->randomName(100),
  427. );
  428. $this->drupalLogin($enableduser);
  429. $this->drupalPost('messages/new', $message, t('Send message'));
  430. $this->assertText(t('You are not allowed to send this message because all recipients are blocked.'));
  431. // Make sure that a message to multiple recipients still works if one is
  432. // disabled.
  433. $messagemultiple = array(
  434. 'recipient' => $enableduser2->name . ', ' . $disableduser->name,
  435. 'subject' => $this->randomName(20),
  436. 'body[value]' => $this->randomName(100),
  437. );
  438. $this->drupalPost('messages/new', $messagemultiple, t('Send message'));
  439. $this->assertText(t('@recipient has disabled private message receiving.', array('@recipient' => $disableduser->name)), 'Message about user with disabled private messaging.');
  440. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $enableduser2->name)), 'Message sent confirmation displayed.');
  441. // Remove the permission to disable privatemsg.
  442. $this->drupalLogin($admin_user);
  443. // 6 is the rid of the custom $disableduser role.
  444. $edit = array('6[allow disabling privatemsg]' => FALSE);
  445. $this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
  446. // Make sure that the option is not visible anymore.
  447. $this->drupalLogin($disableduser);
  448. $this->drupalGet('user/' . $disableduser->uid . '/edit');
  449. $this->assertNoText(t('Enable Private Messaging'), t('Disable privatemsg setting not displayed'));
  450. // Verify that the user is now allowed to write messages again.
  451. $this->drupalGet('messages/new');
  452. $this->assertNoText(t('You are not authorized to access this page.'), t('Access denied page is not displayed.'));
  453. $this->assertText(t('Write new message'), t('Write message form is displayed.'));
  454. }
  455. /**
  456. * Test correct handling of read all permissions.
  457. */
  458. function testReadAllPermission() {
  459. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  460. $recipient = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  461. $admin = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'read all private messages'));
  462. // Create new message.
  463. $edit = array(
  464. 'recipient' => $recipient->name,
  465. 'subject' => $this->randomName(20),
  466. 'body[value]' => $this->randomName(100),
  467. );
  468. $this->drupalLogin($author);
  469. $this->drupalPost('messages/new', $edit, t('Send message'));
  470. $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), t('Message sent confirmation displayed'));
  471. $this->drupalLogin($admin);
  472. $this->drupalGet('messages/view/1');
  473. $this->assertText(t('This conversation is being viewed with escalated privileges and may not be the same as shown to normal users.'), t('Notice about read all mode displayed.'));
  474. // Send a first response.
  475. $admin_edit = array(
  476. 'body[value]' => $this->randomName(100),
  477. );
  478. $this->drupalPost('messages/view/1', $admin_edit, t('Send message'));
  479. // Make sure that the notice is not displayed anymore.
  480. // @tod: Commented out because this does not work as expected.
  481. $this->assertNoText(t('This conversation is being viewed with escalated privileges and may not be the same as shown to normal users.'), t('Notice about read all mode not displayed.'));
  482. // Make sure that both the existing message body and the new one are displayed.
  483. $this->assertText($edit['body[value]'], t('First message body displayed.'));
  484. $this->assertText($admin_edit['body[value]'], t('New message body displayed.'));
  485. $admin_recipient_count = db_query("SELECT COUNT(*) FROM {pm_index} WHERE recipient = :recipient AND thread_id = :thread_id", array(
  486. ':recipient' => $admin->uid,
  487. ':thread_id' => 1,
  488. ))->fetchField();
  489. $this->assertEqual($admin_recipient_count, 2, t('Admin is listed as recipient for every message once.'));
  490. // Send a second response.
  491. $admin_edit2 = array(
  492. 'body[value]' => $this->randomName(100),
  493. );
  494. $this->drupalPost('messages/view/1', $admin_edit2, t('Send message'));
  495. // Make sure that both the existing message body and the new one are displayed.
  496. $this->assertText($edit['body[value]'], t('First message body displayed.'));
  497. $this->assertText($admin_edit['body[value]'], t('Second response body displayed.'));
  498. $this->assertText($admin_edit2['body[value]'], t('Third message body displayed.'));
  499. $admin_recipient_count = db_query("SELECT COUNT(*) FROM {pm_index} WHERE recipient = :recipient AND thread_id = :thread_id", array(
  500. ':recipient' => $admin->uid,
  501. ':thread_id' => 1,
  502. ))->fetchField();
  503. $this->assertEqual($admin_recipient_count, 3, t('Admin is listed as recipient for every message once.'));
  504. }
  505. /**
  506. * Tests for the flush feature
  507. */
  508. function testPrivatemsgFlush() {
  509. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  510. $recipient = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  511. // Send 10 messages.
  512. for ($i = 0; $i < 10; $i++) {
  513. privatemsg_new_thread(array($recipient), 'Message #' . $i, 'This is the body', array('author' => $author));
  514. }
  515. // Delete message 1, 3, 4, 6, 9 for author.
  516. foreach (array(1, 3, 4, 6, 9) as $pmid) {
  517. privatemsg_message_change_delete($pmid, TRUE, $author);
  518. }
  519. // Delete message 1, 2, 4, 6, 8 for recipient.
  520. foreach (array(1, 3, 4, 6, 9) as $pmid) {
  521. privatemsg_message_change_delete($pmid, TRUE, $recipient);
  522. }
  523. // Now, mid 1, 4 and 6 have been deleted by both.
  524. // Flush configuration, enable, delay is default, 30 days
  525. variable_set('privatemsg_flush_enabled', TRUE);
  526. // Set back the deleted timestamp 35 days back of mid 4.
  527. db_update('pm_index')
  528. ->fields(array('deleted' => REQUEST_TIME - 35 * 86400))
  529. ->condition('mid', 4)
  530. ->execute();
  531. // Set back the deleted timestamp of mid 6, but only 20 days back.
  532. db_update('pm_index')
  533. ->fields(array('deleted' => REQUEST_TIME - 20 * 86400))
  534. ->condition('mid', 6)
  535. ->execute();
  536. // Run flush.
  537. privatemsg_cron();
  538. // Check if the undeleted messages are still there.
  539. foreach (array(2, 3, 5, 7, 8, 9, 10) as $pmid) {
  540. $message = privatemsg_message_load($pmid, $author);
  541. $this->assertTrue(!empty($message), t('Undeleted message #%id is still in the system', array('%id' => $pmid)));
  542. }
  543. // Check if the "recently" deleted messages are still there.
  544. foreach (array(1, 6) as $pmid) {
  545. $message = privatemsg_message_load($pmid, $author);
  546. $this->assertTrue(!empty($message), t('Deleted message #%id is still in the system', array('%id' => $pmid)));
  547. }
  548. // Mid 4 should have been flushed.
  549. $message = privatemsg_message_load(4, $author);
  550. $this->assertTrue(empty($message), t('Message #4 has been flushed'));
  551. }
  552. function testDelete() {
  553. // Create users.
  554. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'delete privatemsg'));
  555. $recipient = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'delete privatemsg'));
  556. $recipient2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'cancel account'));
  557. $admin = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'delete privatemsg', 'read all private messages'));
  558. $dummy = $this->drupalCreateUser(array('cancel account'));
  559. // Create texts.
  560. $subject = $this->randomName(20);
  561. $body1 = $this->randomName(100);
  562. $body2 = $this->randomName(100);
  563. // Create message and response.
  564. $return = privatemsg_new_thread(array($recipient, $recipient2), $subject, $body1, array('author' => $author));
  565. privatemsg_reply($return['message']->thread_id, $body2, array('author' => $recipient));
  566. // Check with user without delete permission.
  567. $this->drupalLogin($recipient2);
  568. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  569. $this->assertText($subject, 'Subject is displayed');
  570. $this->assertText($body1, 'First message is displayed');
  571. $this->assertText($body2, 'Second message is displayed');
  572. $this->assertNoLink(t('Delete'), 'Delete message is link is not displayed for user without permission');
  573. // Check if access for that user is denied.
  574. $this->drupalGet('messages/delete/' . $return['message']->thread_id . '/' . $return['message']->mid);
  575. $this->assertText(t('Access denied'));
  576. // Check with user with delete access.
  577. $this->drupalLogin($recipient);
  578. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  579. $this->assertText(t('Delete'), 'Delete message is link is displayed for user without permission');
  580. // Click delete link of the second message and cancel.
  581. $this->clickLink(t('Delete'), 1);
  582. $this->assertText(t('Are you sure you want to delete this message?'), 'Confirmation message displayed');
  583. $this->clickLink(t('Cancel'));
  584. $this->assertText($body2, 'Second message is still displayed');
  585. // Confirm message deletion.
  586. $this->clickLink(t('Delete'), 1);
  587. $this->assertText(t('Are you sure you want to delete this message?'), 'Confirmation message displayed');
  588. $this->drupalPost(NULL, array(), t('Delete'));
  589. $this->assertText(t('Message has been deleted.'), 'Message has been deleted');
  590. $this->assertText($body1, 'First message is still displayed');
  591. $this->assertNoText($body2, 'Second message was deleted');
  592. // Click delete link of the first message and cancel.
  593. $this->clickLink(t('Delete'));
  594. $this->assertText(t('Are you sure you want to delete this message?'), 'Confirmation message displayed');
  595. $this->clickLink(t('Cancel'));
  596. $this->assertText($body1, 'First message is still displayed');
  597. // Confirm message deletion.
  598. $this->clickLink(t('Delete'));
  599. $this->assertText(t('Are you sure you want to delete this message?'), 'Confirmation message displayed');
  600. $this->drupalPost(NULL, array(), t('Delete'));
  601. $this->assertText(t('Message has been deleted.'), 'Message deleted has been deleted');
  602. $this->assertNoText($subject, 'All messages of that thread have been deleted');
  603. // Test if the message has not been deleted for other users.
  604. $this->drupalLogin($recipient2);
  605. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  606. $this->assertText($body1, 'First message is still displayed');
  607. $this->assertText($body2, 'First message is still displayed');
  608. // Test delete all checkbox.
  609. $this->drupalLogin($admin);
  610. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  611. $this->clickLink(t('Delete'), 1);
  612. $this->drupalPost(NULL, array('delete_options' => TRUE), t('Delete'));
  613. $this->assertText(t('Message has been deleted for all users.'), 'Message deleted has been deleted');
  614. // Test if the message has been deleted for all users.
  615. $this->drupalLogin($recipient2);
  616. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  617. $this->assertText($body1, 'First message is still displayed');
  618. $this->assertNoText($body2, 'Second message has been deleted for all users');
  619. // Check that messages of canceled users (user_cancel_delete) are deleted too.
  620. $edit = array('body[value]' => $this->randomName(100));
  621. $this->drupalPost(NULL, $edit, t('Send message'));
  622. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  623. $this->assertText($edit['body[value]'], t('New reply is displayed'));
  624. // Reload user object, don't use the cache.
  625. $recipient2 = user_load($recipient2->uid, TRUE);
  626. // Attempt to cancel account.
  627. variable_set('user_cancel_method', 'user_cancel_delete');
  628. $this->drupalGet('user/' . $recipient2->uid . '/edit');
  629. $this->drupalPost(NULL, NULL, t('Cancel account'));
  630. // Confirm account cancellation.
  631. // Explicitly use time(), REQUEST_TIME is not exact enough.
  632. $timestamp = time();
  633. $this->drupalPost(NULL, NULL, t('Cancel account'));
  634. // Confirm account cancellation request.
  635. $this->drupalGet("user/$recipient2->uid/cancel/confirm/$timestamp/" . user_pass_rehash($recipient2->pass, $timestamp, $recipient2->login));
  636. // Simpletest thinks that we are still logged in.
  637. $this->loggedInUser = NULL;
  638. $this->drupalLogin($admin);
  639. $this->drupalGet('messages/view/' . $return['message']->thread_id);
  640. $this->assertText($body1, 'First message is still displayed');
  641. $this->assertNoText($edit['body[value]'], t('Reply of deleted user is not displayed anymore'));
  642. // Test if admin is allowed to delete messages of other users.
  643. $this->drupalGet('user/' . $author->uid . '/messages');
  644. $this->checkThreadDelete($return['message']);
  645. // Check if user is allowed to delete messages.
  646. $this->drupalLogin($author);
  647. $this->drupalGet('messages');
  648. $this->checkThreadDelete($return['message']);
  649. // Check that deleting users that didn't send any message does not cause
  650. // errors.
  651. $this->drupalLogin($dummy);
  652. // Reload user object, don't use the cache.
  653. $dummy = user_load($dummy->uid, TRUE);
  654. // Attempt to cancel account.
  655. $this->drupalGet('user/' . $dummy->uid . '/edit');
  656. $this->drupalPost(NULL, NULL, t('Cancel account'));
  657. // Confirm account cancellation.
  658. // Explicitly use time(), REQUEST_TIME is not exact enough.
  659. $timestamp = time();
  660. $this->drupalPost(NULL, NULL, t('Cancel account'));
  661. // Confirm account cancellation request.
  662. $this->drupalGet("user/$dummy->uid/cancel/confirm/$timestamp/" . user_pass_rehash($dummy->pass, $timestamp, $dummy->login));
  663. }
  664. function checkThreadDelete($message) {
  665. $this->assertText($message->subject, t('Message is displayed.'));
  666. $delete = array(
  667. 'list[' . $message->thread_id . ']' => 1,
  668. );
  669. $this->drupalPost(NULL, $delete, t('Delete'));
  670. $this->assertText(t('Deleted @count thread.', array('@count' => 1)), t('Delete message displayed.'));
  671. $this->assertNoText($message->subject, t('Message is not displayed anymore.'));
  672. $this->assertText(t('No messages available.'), t('No messages available anymore.'));
  673. // Revert delete action.
  674. $this->clickLink(t('undone'));
  675. $this->assertText(t('Restored @count thread.', array('@count' => 1)), t('Restore message displayed'));
  676. $this->assertText($message->subject, t('Message is displayed again.'));
  677. $this->assertNoText(t('No messages available.'), t('Messages are available.'));
  678. }
  679. /**
  680. * Test preview functionality.
  681. */
  682. function testPreview() {
  683. $user = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  684. // Enable preview button.
  685. variable_set('privatemsg_display_preview_button', TRUE);
  686. $message = array(
  687. 'recipient' => $user->name,
  688. 'subject' => $this->randomName(),
  689. 'body[value]' => $this->randomName(50),
  690. );
  691. $this->drupalLogin($user);
  692. // Preview message.
  693. $this->drupalPost('messages/new', $message, t('Preview message'));
  694. $this->assertFieldByXPath($this->buildXPathQuery('//div[@class=:class]/p', array(':class' => 'privatemsg-message-body')), $message['body[value]'], t('Message body is previewed'));
  695. $this->assertFieldByName('body[value]', $message['body[value]'], t('Message body field has the correct default value.'));
  696. // Send message.
  697. $this->drupalPost(NULL, array(), t('Send message'));
  698. $this->assertText($message['subject'], t('Message subject is displayed.'));
  699. $this->assertText($message['body[value]'], t('Message body is displayed.'));
  700. $this->assertText(t('A message has been sent to @recipient.', array('@recipient' => $user->name)), t('Sent confirmation displayed.'));
  701. }
  702. /**
  703. * Test autocomplete.
  704. */
  705. function testAutocomplete() {
  706. $current = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  707. $user1 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  708. $user2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  709. $user3 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  710. $this->drupalLogin($current);
  711. // Use specific names to be able to test for specific name combinations.
  712. user_save($current, array('name' => 'whatever'));
  713. user_save($user1, array('name' => 'aaaa'));
  714. user_save($user2, array('name' => 'aaab'));
  715. user_save($user3, array('name' => 'bbbb'));
  716. $json = $this->drupalGet('messages/autocomplete/aa');
  717. $autocomplete = (array)json_decode($json);
  718. $this->assertEqual(count($autocomplete), 2, t('Autocomplete object contains two suggestions.'));
  719. $this->assertEqual($autocomplete['aaaa, '], 'aaaa');
  720. $this->assertEqual($autocomplete['aaab, '], 'aaab');
  721. $json = $this->drupalGet('messages/autocomplete/bb');
  722. $autocomplete = (array)json_decode($json);
  723. $this->assertEqual(count($autocomplete), 1, t('Autocomplete object contains one suggestion.'));
  724. $this->assertEqual($autocomplete['bbbb, '], 'bbbb');
  725. $json = $this->drupalGet('messages/autocomplete/cc');
  726. $autocomplete = (array)json_decode($json);
  727. $this->assertEqual(count($autocomplete), 0, t('Autocomplete object contains no suggestions.'));
  728. $json = $this->drupalGet('messages/autocomplete/aaaa, a');
  729. $autocomplete = (array)json_decode($json);
  730. $this->assertEqual(count($autocomplete), 1, t('Autocomplete object contains one suggestion.'));
  731. $this->assertEqual($autocomplete['aaaa, aaab, '], 'aaab');
  732. // Test XSS protection, create a username and check that the suggestion is
  733. // safe.
  734. $user4 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  735. $user4 = user_save($user4, array('name' => "<script>alert('XSS')</script>"));
  736. $json = $this->drupalGet('messages/autocomplete/<sc');
  737. $autocomplete = (array)json_decode($json);
  738. $this->assertEqual(count($autocomplete), 1, t('Autocomplete object contains one suggestion.'));
  739. $this->assertEqual($autocomplete[strip_tags($user4->name) . ', '], strip_tags($user4->name));
  740. }
  741. }
  742. /**
  743. * Tests for fields integration.
  744. */
  745. class PrivatemsgFieldsTestCase extends PrivatemsgBaseTestCase {
  746. /**
  747. * Implements getInfo().
  748. */
  749. public static function getInfo() {
  750. return array
  751. (
  752. 'name' => t('Privatemsg fields.'),
  753. 'description' => t('Tests integration with fields.'),
  754. 'group' => t('Privatemsg'),
  755. );
  756. }
  757. /**
  758. * Implements setUp().
  759. */
  760. function setUp() {
  761. parent::setUp('privatemsg', 'image', 'text', 'field_ui');
  762. }
  763. function testSingleField() {
  764. $admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
  765. $user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  766. $this->drupalLogin($admin);
  767. // Create a new field.
  768. $edit = array(
  769. 'fields[_add_new_field][label]' => $this->randomName(),
  770. 'fields[_add_new_field][field_name]' => $name = strtolower($this->randomName()),
  771. 'fields[_add_new_field][type]' => 'text',
  772. 'fields[_add_new_field][widget_type]' => 'text_textfield',
  773. );
  774. $this->drupalPost('admin/config/messaging/privatemsg/fields', $edit, t('Save'));
  775. $this->drupalPost(NULL, array(), t('Save field settings'));
  776. $this->drupalPost(NULL, array(), t('Save settings'));
  777. // Enable preview button.
  778. variable_set('privatemsg_display_preview_button', TRUE);
  779. // Preview message.
  780. $message = array(
  781. 'recipient' => $user->name,
  782. 'subject' => $this->randomName(),
  783. 'body[value]' => $this->randomName(50),
  784. 'field_' . $name . '[und][0][value]' => $this->randomName(50),
  785. );
  786. $this->drupalPost('messages/new', $message, t('Preview message'));
  787. // Send message.
  788. $this->drupalPost(NULL, array(), t('Send message'));
  789. // Check message.
  790. $this->drupalLogin($user);
  791. $this->drupalGet('messages');
  792. $this->clickLink($message['subject']);
  793. $this->assertText($message['body[value]'], t('Message body displayed.'));
  794. $this->assertText($message['field_' . $name . '[und][0][value]'], t('Content of new field is displayed.'));
  795. // Respond.
  796. $response = array(
  797. 'body[value]' => $this->randomName(50),
  798. 'field_' . $name . '[und][0][value]' => $this->randomName(50),
  799. );
  800. $this->drupalPost(NULL, $response, t('Send message'));
  801. // Check response.
  802. $this->drupalLogin($admin);
  803. $this->drupalGet('messages');
  804. $this->clickLink($message['subject']);
  805. $this->assertText($response['body[value]'], t('Message body displayed.'));
  806. $this->assertText($response['field_' . $name . '[und][0][value]'], t('Content of new field is displayed.'));
  807. }
  808. /**
  809. * Verify that a message with an empty image can be sent.
  810. */
  811. function testEmptyImage() {
  812. $admin = $this->drupalCreateUser(array('administer privatemsg settings', 'write privatemsg', 'read privatemsg'));
  813. $user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  814. $this->drupalLogin($admin);
  815. // Create a new field.
  816. $edit = array(
  817. 'fields[_add_new_field][label]' => $this->randomName(),
  818. 'fields[_add_new_field][field_name]' => strtolower($this->randomName()),
  819. 'fields[_add_new_field][type]' => 'image',
  820. 'fields[_add_new_field][widget_type]' => 'image_image',
  821. );
  822. $this->drupalPost('admin/config/messaging/privatemsg/fields', $edit, t('Save'));
  823. $this->drupalPost(NULL, array(), t('Save field settings'));
  824. $this->drupalPost(NULL, array(), t('Save settings'));
  825. // Enable preview button.
  826. variable_set('privatemsg_display_preview_button', TRUE);
  827. // Preview message.
  828. $message = array(
  829. 'recipient' => $user->name,
  830. 'subject' => $this->randomName(),
  831. 'body[value]' => $this->randomName(50),
  832. );
  833. $this->drupalPost('messages/new', $message, t('Preview message'));
  834. // Send message.
  835. $this->drupalPost(NULL, array(), t('Send message'));
  836. // Check message.
  837. $this->drupalLogin($user);
  838. $this->drupalGet('messages');
  839. $this->clickLink($message['subject']);
  840. $this->assertText($message['body[value]'], t('Message body displayed.'));
  841. }
  842. }
  843. /**
  844. * Tests for fields integration.
  845. */
  846. class PrivatemsgLinksTestCase extends PrivatemsgBaseTestCase {
  847. /**
  848. * Use testing profile.
  849. */
  850. protected $profile = 'standard';
  851. /**
  852. * Implements of getInfo().
  853. */
  854. public static function getInfo() {
  855. return array
  856. (
  857. 'name' => t('Privatemsg links'),
  858. 'description' => t('Tests links displayed in nodes, profiles and blocks.'),
  859. 'group' => t('Privatemsg'),
  860. );
  861. }
  862. /**
  863. * Implements setUp().
  864. */
  865. function setUp() {
  866. parent::setUp('privatemsg');
  867. }
  868. /**
  869. * Tests author links displayed on nodes and comments.
  870. */
  871. function testAuthorLinks() {
  872. $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'create article content', 'create page content'));
  873. $user = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  874. $this->drupalLogin($admin);
  875. $settings = array(
  876. 'privatemsg_display_link_self' => FALSE,
  877. 'privatemsg_link_node_types[article]' => TRUE,
  878. 'privatemsg_display_on_teaser' => FALSE,
  879. 'privatemsg_display_on_comments' => TRUE,
  880. );
  881. $this->drupalPost('admin/config/messaging/privatemsg', $settings, t('Save configuration'));
  882. $node1 = array(
  883. 'title' => $this->randomName(10),
  884. 'body[und][0][value]' => $this->randomString(50),
  885. );
  886. $this->drupalPost('node/add/article', $node1, t('Save'));
  887. $comment = array(
  888. 'comment_body[und][0][value]' => $this->randomName(20),
  889. );
  890. $this->drupalPost(NULL, $comment, t('Save'));
  891. $node2 = array(
  892. 'title' => $this->randomName(),
  893. 'body[und][0][value]' => $this->randomString(50),
  894. );
  895. $this->drupalPost('node/add/page', $node2, t('Save'));
  896. $this->drupalGet('node');
  897. $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
  898. $this->clickLink($node1['title']);
  899. $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
  900. $this->drupalLogin($user);
  901. $this->drupalGet('node');
  902. $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
  903. $this->clickLink($node1['title']);
  904. $this->assertNoUniqueText(t('Send author a message'), t('Send author a message link displayed.'));
  905. $this->clickLink(t('Send author a message'));
  906. // To field and subject should be correctly pre-filled now.
  907. $this->drupalPost(NULL, array(), t('Send message'));
  908. // Make sure the message was sent to the correct user.
  909. $this->assertText(t('A message has been sent to @user', array('@user' => $admin->name)));
  910. // @todo: Do not guess nid.
  911. $this->drupalGet('node/2');
  912. $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
  913. $this->drupalLogin($admin);
  914. $this->drupalGet('messages');
  915. $this->assertText(t('Message regarding @node', array('@node' => $node1['title'])));
  916. }
  917. /**
  918. * Tests menu block.
  919. */
  920. function testMenuBlock() {
  921. $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'administer blocks', 'administer menu'));
  922. $user = $this->drupalCreateUser(array('read privatemsg'));
  923. // Enable block.
  924. $this->drupalLogin($admin);
  925. $blocks = array(
  926. 'blocks[privatemsg_privatemsg-menu][region]' => 'sidebar_second',
  927. );
  928. $this->drupalPost('admin/structure/block', $blocks, t('Save blocks'));
  929. // Disable secondary menu.
  930. /* @todo: Not yet possible because simpletest needs a log out link to verify that the user is logged in.
  931. $menu_settings = array(
  932. 'menu_secondary_links_source' => '',
  933. );
  934. $this->drupalPost('admin/structure/menu/settings', $menu_settings, t('Save configuration'));
  935. *
  936. */
  937. $this->drupalGet('');
  938. $this->assertText(t('Private messages'), t('Privatemsg menu block title displayed.'));
  939. $this->assertText('Write new message', t('Write new message link displayed.'));
  940. $message = array(
  941. 'recipient' => $user->name,
  942. 'subject' => $this->randomName(),
  943. 'body[value]' => $this->randomName(50),
  944. );
  945. $this->drupalPost('messages/new', $message, t('Send message'));
  946. $this->drupalLogin($user);
  947. $this->assertNoText(t('Write new message'), t('Write new message link not displayed.'));
  948. $this->assertNoUniqueText(t('Messages (1 new)'), t('Messages link including new message information displayed'));
  949. }
  950. /**
  951. * Tests menu block.
  952. */
  953. function testNewBlock() {
  954. $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'administer blocks', 'administer menu'));
  955. $user = $this->drupalCreateUser(array('read privatemsg'));
  956. // Enable block.
  957. $this->drupalLogin($admin);
  958. $blocks = array(
  959. 'blocks[privatemsg_privatemsg-new][region]' => 'sidebar_second',
  960. );
  961. $this->drupalPost('admin/structure/block', $blocks, t('Save blocks'));
  962. $this->drupalGet('');
  963. $this->assertNoText(t('Unread message'), t('Privatemsg unread message block title not displayed.'));
  964. $message = array(
  965. 'recipient' => $user->name,
  966. 'subject' => $this->randomName(),
  967. 'body[value]' => $this->randomName(50),
  968. );
  969. $this->drupalPost('messages/new', $message, t('Send message'));
  970. $this->drupalLogin($user);
  971. $this->assertText(t('Unread message'), t('Privatemsg unread message block title displayed.'));
  972. $this->assertText(t('You have an unread message! Click here to read it.'), t('Unread message indication displayed.'));
  973. }
  974. }
  975. /**
  976. * Tests for fields integration.
  977. */
  978. class PrivatemsgTokenTestCase extends PrivatemsgBaseTestCase {
  979. /**
  980. * Implements of getInfo().
  981. */
  982. public static function getInfo() {
  983. return array
  984. (
  985. 'name' => t('Privatemsg tokens'),
  986. 'description' => t('Tests tokens in private messages.'),
  987. 'group' => t('Privatemsg'),
  988. 'dependencies' => array('token'),
  989. );
  990. }
  991. /**
  992. * Implements setUp().
  993. */
  994. function setUp() {
  995. parent::setUp('privatemsg', 'token');
  996. }
  997. /**
  998. * Basic token functionality.
  999. */
  1000. function testBasicTokens() {
  1001. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'use tokens in privatemsg'));
  1002. $recipient1 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  1003. $recipient2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  1004. $this->drupalLogin($author);
  1005. // Enable preview button.
  1006. variable_set('privatemsg_display_preview_button', TRUE);
  1007. // Create message with tokens and preview it.
  1008. $edit = array(
  1009. 'recipient' => $recipient1->name . ', ' . $recipient2->name,
  1010. 'subject' => 'Hey [privatemsg_message:recipient:name]',
  1011. 'body[value]' => "Testing a few tokens.\n\nSubject: [privatemsg_message:subject]\n\nAuthor: [privatemsg_message:author:name]\n\nInvalid token: [privatemsg_message:invalid_token]",
  1012. );
  1013. $this->drupalPost('messages/new', $edit, t('Preview message'));
  1014. // Make sure the tokens in subject and body are correctly displayed in the
  1015. // preview.
  1016. $this->assertText('Hey &lt; Token [privatemsg_message:recipient:name] &gt;', t('Token is displayed in subject.'));
  1017. $this->assertText('Subject: &lt; Token [privatemsg_message:subject] &gt;', t('Subject token is displayed.'));
  1018. $this->assertText('Author: &lt; Token [privatemsg_message:author:name] &gt;', t('Author token is displayed.'));
  1019. $this->assertText('Invalid token: &lt; INVALID TOKEN [privatemsg_message:invalid_token] &gt;', t('Invalid token is displayed.'));
  1020. $this->assertText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));
  1021. $this->drupalPost(NULL, array(), t('Send message'));
  1022. // Make sure the tokens in subject and body are correctly displayed in the
  1023. // sent message.
  1024. $this->assertText('Hey &lt; Token [privatemsg_message:recipient:name] &gt;', t('Token is displayed in subject.'));
  1025. $this->assertText('Subject: &lt; Token [privatemsg_message:subject] &gt;', t('Subject token is displayed.'));
  1026. $this->assertText('Author: &lt; Token [privatemsg_message:author:name] &gt;', t('Author token is displayed.'));
  1027. $this->assertText('Invalid token: &lt; INVALID TOKEN [privatemsg_message:invalid_token] &gt;', t('Invalid token is displayed.'));
  1028. $this->assertText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));
  1029. // Log in as the first recipient, verify that he sees the message with the
  1030. // replacements.
  1031. $this->drupalLogin($recipient1);
  1032. $this->drupalGet('messages');
  1033. $this->clickLink('Hey ' . $recipient1->name);
  1034. // Make sure the tokens in subject and body are correctly displayed in the
  1035. // message.
  1036. $this->assertText('Hey ' . $recipient1->name, t('Replaced token is displayed in subject.'));
  1037. $this->assertText('Subject: Hey ' . $recipient1->name, t('Subject token is replaced.'));
  1038. $this->assertText('Author: ' . $author->name, t('Author token is replaced.'));
  1039. $this->assertText('Invalid token: [privatemsg_message:invalid_token]', t('Invalid token is displayed.'));
  1040. $this->assertNoText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));
  1041. // Reply, verify that the message still shows the correct subject and
  1042. // tokens from this user are not replaced.
  1043. $reply = array(
  1044. 'body[value]' => 'Response with a token [privatemsg_message:mid]',
  1045. );
  1046. $this->drupalPost(NULL, $reply, t('Send message'));
  1047. $this->drupalLogin($recipient2);
  1048. $this->drupalGet('messages');
  1049. $this->clickLink('Hey ' . $recipient2->name);
  1050. // Make sure the tokens in subject and body are correctly displayed in the
  1051. // message.
  1052. $this->assertText('Hey ' . $recipient2->name, t('Replaced token is displayed in subject.'));
  1053. $this->assertText('Subject: Hey ' . $recipient2->name, t('Subject token is replaced.'));
  1054. $this->assertText('Author: ' . $author->name, t('Author token is replaced.'));
  1055. $this->assertText('Invalid token: [privatemsg_message:invalid_token]', t('Invalid token is displayed.'));
  1056. $this->assertText('Response with a token [privatemsg_message:mid]', t('Token from recipient is not replaced.'));
  1057. $this->assertNoText(t('Note: Valid tokens will be replaced when a recipient is reading this message.'), t('Token notice is displayed.'));
  1058. $this->drupalLogin($author);
  1059. $this->drupalGet('messages');
  1060. // Assert that token is displayed in the subject for the author.
  1061. $this->assertText('Hey &lt; Token [privatemsg_message:recipient:name] &gt;', t('Token is displayed correctly in subject for author.'));
  1062. }
  1063. }
  1064. /**
  1065. * Privatemsg API tests
  1066. */
  1067. class PrivatemsgAPITestCase extends PrivatemsgBaseTestCase {
  1068. /**
  1069. * Implements getInfo().
  1070. */
  1071. public static function getInfo() {
  1072. return array(
  1073. // 'name' should start with what is being tested (menu item) followed by what about it
  1074. // is being tested (creation/deletion).
  1075. 'name' => t('Privatemsg API functionality.'),
  1076. // 'description' should be one or more complete sentences that provide more details on what
  1077. // exactly is being tested.
  1078. 'description' => t('Test sending, receiving, listing, deleting messages and other features via API.'),
  1079. // 'group' should be a logical grouping of test cases, like a category. In most cases, that
  1080. // is the module the test case is for.
  1081. 'group' => t('Privatemsg'),
  1082. );
  1083. }
  1084. /**
  1085. * Implements setUp().
  1086. */
  1087. function setUp() {
  1088. parent::setUp('privatemsg', 'privatemsg_roles');
  1089. // Create the full html format.
  1090. $full_html_format = array(
  1091. 'format' => 'full_html',
  1092. 'name' => 'Full HTML',
  1093. 'weight' => 1,
  1094. 'filters' => array(
  1095. // URL filter.
  1096. 'filter_url' => array(
  1097. 'weight' => 0,
  1098. 'status' => 1,
  1099. ),
  1100. // Line break filter.
  1101. 'filter_autop' => array(
  1102. 'weight' => 1,
  1103. 'status' => 1,
  1104. ),
  1105. // HTML corrector filter.
  1106. 'filter_htmlcorrector' => array(
  1107. 'weight' => 10,
  1108. 'status' => 1,
  1109. ),
  1110. ),
  1111. );
  1112. $full_html_format = (object) $full_html_format;
  1113. filter_format_save($full_html_format);
  1114. // Refresh permissions.
  1115. $this->checkPermissions(array(), TRUE);
  1116. }
  1117. function testPrivatemsgApiNewThread() {
  1118. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  1119. $recipient1 = $this->drupalCreateUser(array('read privatemsg'));
  1120. $recipient2 = $this->drupalCreateUser(array('read privatemsg'));
  1121. $recipient3 = $this->drupalCreateUser(array('read privatemsg'));
  1122. // Reset user_access cache
  1123. user_access('', $author, TRUE);
  1124. $resultok1 = privatemsg_new_thread(array($recipient1, $recipient2, $recipient3), 'normal message', 'Body text', array('author' => $author));
  1125. $this->assertTrue($resultok1['success'], 'Private message could be sent successfully');
  1126. $message = $this->getMessageFromSubject('normal message');
  1127. $this->assertFalse(empty($message), 'Message was saved in database');
  1128. $this->assertEqual($message->author, $author->uid, 'Message was sent by author');
  1129. $resultok2 = privatemsg_new_thread(array($recipient1, $recipient2, $recipient3), 'empty body', '', array('author' => $author));
  1130. $this->assertTrue($resultok2['success'], 'API allowed to send message without body');
  1131. $resultf1 = privatemsg_new_thread(array($recipient1, $recipient2, $recipient3), '', 'No subject', array('author' => $author));
  1132. $this->assertEqual('A subject or message must be included.', $resultf1['messages']['error'][0], 'API denied to send message without a subject');
  1133. $resultf2 = privatemsg_new_thread(array(), 'no recipients', 'Body text', array('author' => $author));
  1134. $this->assertEqual('At least one valid recipient must be included with the message.', $resultf2['messages']['error'][0], 'API denied to send message without recipients');
  1135. $message = $this->getMessageFromSubject('no recipients');
  1136. $this->assertTrue(empty($message), 'Message was not saved in database');
  1137. $resultf3 = privatemsg_new_thread(array($recipient1, $recipient2, $recipient3), 'not allowed', 'Body text', array('author' => $recipient1));
  1138. $errormessage = t('@user is not allowed to write messages.', array('@user' => $recipient1->name));
  1139. $this->assertEqual($errormessage, $resultf3['messages']['error'][0], 'API denied to send message from user without permission');
  1140. $message = $this->getMessageFromSubject('not allowed');
  1141. $this->assertTrue(empty($message), 'Message was not saved in database');
  1142. // Test with an input format that the author is not allowed to use.
  1143. $resultf4 = privatemsg_new_thread(array($recipient1, $recipient2, $recipient3), 'input filter not allowed', 'Body text', array('author' => $author, 'format' => 'full_html'));
  1144. $errormessage = t('@user is not allowed to use the specified input format.', array('@user' => $author->name));
  1145. $this->assertEqual($errormessage, $resultf4['messages']['error'][0], t('User is not allowed to use the specified input format.'));
  1146. $message = $this->getMessageFromSubject('input filter not allowed');
  1147. $this->assertTrue(empty($message), 'Message was not saved in database');
  1148. // Send a message through the api to the same user and check if it marked
  1149. // as new.
  1150. privatemsg_new_thread(array($author), $subject = $this->randomName(10), $this->randomString(20), array('author' => $author));
  1151. $this->drupalLogin($author);
  1152. $this->drupalGet('messages');
  1153. $this->clickLink($subject);
  1154. $this->assertText(t('New'), t('Message is marked as new'));
  1155. }
  1156. function getMessageFromSubject($subject) {
  1157. return db_query("SELECT * FROM {pm_message} WHERE subject = :subject", array(':subject' => $subject))->fetchObject();
  1158. }
  1159. function testPrivatemsgApiReply() {
  1160. $author = $this->drupalCreateUser(array('write privatemsg'));
  1161. $recipient1 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  1162. $recipient2 = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
  1163. $recipient3 = $this->drupalCreateUser(array('read privatemsg'));
  1164. // Reset user_access cache
  1165. user_access('', $author, TRUE);
  1166. $resultok = privatemsg_new_thread(array($recipient2, $recipient1, $recipient3), 'test reply', 'body text', array('author' => $author));
  1167. $this->assertTrue($resultok['success'], 'Private message could be sent successfully');
  1168. $thread_row = $this->getMessageFromSubject('test reply');
  1169. $this->assertEqual($thread_row->reply_to_mid, 0, t('First message is not a reply to a thread.'));
  1170. $resultok = privatemsg_reply($thread_row->mid, 'Test Body', array('author' => $author));
  1171. $this->assertTrue($resultok['success'], 'Reply could be sent successfully');
  1172. $reply_to_mid = db_query('SELECT reply_to_mid FROM {pm_message} WHERE mid = :mid', array(':mid' => $resultok['message']->mid))->fetchField();
  1173. $this->assertEqual($reply_to_mid, $thread_row->mid, t('Reply is marked as reply of first message.'));
  1174. $resultok = privatemsg_reply($thread_row->mid, 'Test Body', array('author' => $recipient1));
  1175. $this->assertTrue($resultok['success'], 'Reply could be sent successfully');
  1176. $reply_to_mid = db_query('SELECT reply_to_mid FROM {pm_message} WHERE mid = :mid', array(':mid' => $resultok['message']->mid))->fetchField();
  1177. $this->assertEqual($reply_to_mid, $thread_row->mid, t('Reply is marked as reply of first message.'));
  1178. $resultf1 = privatemsg_reply($thread_row->mid, '', array('author' => $recipient2));
  1179. $this->assertFalse($resultf1['success'], 'API denied to send message without body.');
  1180. $this->assertEqual($resultf1['messages']['error'][0], t('A message must be included in your reply.'), 'Correct error returned when replying with an empty body.');
  1181. $resultf2 = privatemsg_reply($thread_row->mid, 'Test Body', array('author' => $recipient3));
  1182. $errormessage = t('@user is not allowed to write messages.', array('@user' => $recipient3->name));
  1183. $this->assertEqual($errormessage, $resultf2['messages']['error'][0], 'API denied to send message from user without permission');
  1184. }
  1185. /**
  1186. * Test various use cases for privatemsg_get_link().
  1187. */
  1188. function testGetLink() {
  1189. $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'write privatemsg to all roles'));
  1190. $author2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
  1191. $recipient1 = $this->drupalCreateUser(array('read privatemsg'));
  1192. $recipient2 = $this->drupalCreateUser(array('read privatemsg'));
  1193. $recipient3 = $this->drupalCreateUser(array('read privatemsg', 'allow disabling privatemsg'));
  1194. $recipient4 = $this->drupalCreateUser();
  1195. // Create role with the same name as recipient 2.
  1196. $role = $this->drupalCreateRole(array('read privatemsg'), $recipient2->name);
  1197. $this->drupalLogin($author);
  1198. $this->drupalGet(privatemsg_get_link(array($recipient1)));
  1199. $this->assertFieldByName('recipient', $recipient1->name);
  1200. // Because of there is a role with the same name like recipient 2,
  1201. // add the [user] for recipient 2.
  1202. $this->drupalGet(privatemsg_get_link(array($recipient1, $recipient2)));
  1203. $this->assertFieldByName('recipient', $recipient1->name . ', ' . $recipient2->name . ' [user]');
  1204. $this->drupalGet(privatemsg_get_link(array($recipient1, $recipient2), $author));
  1205. $this->assertFieldByName('recipient', $recipient1->name . ', ' . $recipient2->name . ' [user]');
  1206. $this->drupalGet(privatemsg_get_link(array($recipient1, $recipient2), $author, $subject = 'Str/"ang\\w3//'));
  1207. $this->assertFieldByName('recipient', $recipient1->name . ', ' . $recipient2->name . ' [user]');
  1208. $this->assertFieldByName('subject', $subject);
  1209. // Disable privatemsg for recipient 3.
  1210. privatemsg_set_setting('user', $recipient3->uid, 'disabled', 1);
  1211. $this->assertFalse(privatemsg_get_link(array($recipient3), $author));
  1212. $this->drupalGet(privatemsg_get_link(array($recipient1, $recipient3), $author));
  1213. $this->assertFieldByName('recipient', $recipient1->name);
  1214. // Disable links to self, verify that a link is only returned when the
  1215. // author is not the only recipient.
  1216. variable_set('privatemsg_display_link_self', FALSE);
  1217. $this->assertFalse(privatemsg_get_link(array($author), $author));
  1218. $this->drupalGet(privatemsg_get_link(array($recipient1, $author), $author));
  1219. $this->assertFieldByName('recipient', $recipient1->name);
  1220. // Verify that link is not shown when recipient doesn't have read
  1221. // permission.
  1222. $this->assertFalse(privatemsg_get_link(array($recipient4), $author));
  1223. $this->drupalGet(privatemsg_get_link(array($recipient1, $recipient4), $author));
  1224. $this->assertFieldByName('recipient', $recipient1->name);
  1225. // Verify that link is not shown when author does not have write permission.
  1226. $this->drupalLogin($recipient1);
  1227. $this->assertFalse(privatemsg_get_link(array($author), $recipient1));
  1228. // For user that has no permission to send message to role,
  1229. // the [user] suffix will not appear although there is a role with the same name as user.
  1230. $this->drupalLogin($author2);
  1231. $this->drupalGet(privatemsg_get_link(array($recipient2)));
  1232. $this->assertFieldByName('recipient', $recipient2->name);
  1233. }
  1234. /**
  1235. * Tests for the privatemsg_*_setting() functions.
  1236. */
  1237. function testSettings() {
  1238. $admin = user_load(1);
  1239. $user = $this->drupalCreateUser(array('write privatemsg'));
  1240. $user2 = $this->drupalCreateUser(array('write privatemsg'));
  1241. // Create some global and role default settings.
  1242. privatemsg_set_setting('global', 0, 'test', 1);
  1243. privatemsg_set_setting('role', array_shift(array_keys($user->roles)), 'test', 2);
  1244. // Add some user specific setting.
  1245. privatemsg_set_setting('user', $admin->uid, 'test', 3);
  1246. privatemsg_set_setting('user', $user->uid, 'test2', 4);
  1247. privatemsg_set_setting('user', $user2->uid, 'test2', -1);
  1248. // Clear the static cache.
  1249. drupal_static_reset('privatemsg_settings');
  1250. // Get the ids for each user.
  1251. $admin_ids = privatemsg_get_default_setting_ids($admin);
  1252. $user_ids = privatemsg_get_default_setting_ids($user);
  1253. $user2_ids = privatemsg_get_default_setting_ids($user2);
  1254. $this->assertEqual(privatemsg_get_setting('test', $admin_ids), 3, t('The admin has a user level setting.'));
  1255. $this->assertEqual(privatemsg_get_setting('test', $user_ids), 2, t('The first user has role-level default.'));
  1256. $this->assertEqual(privatemsg_get_setting('test', $user2_ids), 1, t('The second user defaults to the global.'));
  1257. $this->assertEqual(privatemsg_get_setting('test2', $user_ids), 4, t('The value for another setting is read correctly.'));
  1258. $this->assertEqual(privatemsg_get_setting('test2', $user2_ids), 0, t('Negative values are ignored.'));
  1259. // Update existing settings, verify that the updated value is used now.
  1260. privatemsg_set_setting('role', array_shift(array_keys($user->roles)), 'test', 5);
  1261. privatemsg_set_setting('user', $admin->uid, 'test', 6);
  1262. privatemsg_set_setting('user', $user2->uid, 'test', 7);
  1263. $this->assertEqual(privatemsg_get_setting('test', $admin_ids), 6, t('The updated user level setting is used.'));
  1264. $this->assertEqual(privatemsg_get_setting('test', $user_ids), 5, t('The updated role level setting is used.'));
  1265. $this->assertEqual(privatemsg_get_setting('test', $user2_ids), 7, t('The second user uses the new setting.'));
  1266. // Default some settings.
  1267. privatemsg_del_setting('role', array_shift(array_keys($user->roles)), 'test');
  1268. privatemsg_del_setting('user', $admin->uid, 'test');
  1269. $this->assertEqual(privatemsg_get_setting('test', $admin_ids), 1, t('The user level setting was deleted, the default is now used.'));
  1270. $this->assertEqual(privatemsg_get_setting('test', $user_ids), 1, t('The role level setting was deleted, the default is now used.'));
  1271. // Test variable_get() fallback.
  1272. variable_set('privatemsg_setting_test3', 10);
  1273. privatemsg_set_setting('user', $admin->uid, 'test3', 11);
  1274. $this->assertEqual(privatemsg_get_setting('test3', $user_ids), 10, t('The variable_get() fallback is used when no other value exists.'));
  1275. $this->assertEqual(privatemsg_get_setting('test3', $admin_ids),11, t('The updated user level setting is used.'));
  1276. // Explicitly set a global default now.
  1277. privatemsg_set_setting('global', 0, 'test3', 12);
  1278. $this->assertEqual(privatemsg_get_setting('test3', $user_ids), 12, t('The variable_get() fallback is not used when other values exists.'));
  1279. // Test argument fallback.
  1280. privatemsg_set_setting('user', $admin->uid, 'test4', 14);
  1281. $this->assertEqual(privatemsg_get_setting('test4', $user_ids, 13), 13, t('The argument fallback is used when no other value exists.'));
  1282. $this->assertEqual(privatemsg_get_setting('test4', $admin_ids),14, t('The user level setting is used.'));
  1283. // Explicitly set a global default now.
  1284. privatemsg_set_setting('global', 0, 'test4', 15);
  1285. $this->assertEqual(privatemsg_get_setting('test4', $user_ids, 13), 15, t('The variable_get() fallback is not used when other values exists.'));
  1286. }
  1287. }

Classes

Namesort descending Description
PrivatemsgAPITestCase Privatemsg API tests
PrivatemsgBaseTestCase Base class for Privatemsg tests.
PrivatemsgFieldsTestCase Tests for fields integration.
PrivatemsgLinksTestCase Tests for fields integration.
PrivatemsgTestCase
PrivatemsgTokenTestCase Tests for fields integration.