/** * This function edits the user's settings -> see locallib.php for the logic. * */ private function edit_settings() { global $USER; $inboxsetting = required_param('inboxsetting', PARAM_TEXT); $sentsetting = required_param('sentsetting', PARAM_TEXT); $displaypreference = required_param('displayonpagesetting', PARAM_TEXT); $olddisplaypreference = block_course_message_get_display_preference($USER->id); $displaypreference = $displaypreference == "new_page" ? BLOCK_CM_ON_PAGE : BLOCK_CM_IN_IFRAME; $result = true; $result = block_course_message_update_mail_preference('inbox', $inboxsetting); $result = block_course_message_update_mail_preference('sent', $sentsetting); $result = block_course_message_update_display_preference($displaypreference); if ($result) { echo json_encode(array('result' => true, 'text' => get_string('updatesettings', BLOCK_CM_LANG_TABLE))); } else { echo json_encode(array('result' => false, 'text' => get_string('updatesettingserror', BLOCK_CM_LANG_TABLE))); } }
/** * This function tests the block_course_message_update_mail_preference() function. It is quite simple * since the function itself is fairly straightforward. * */ public function test_update_mail_preference() { $this->setUser($this->craig); // Make sure it is true (inbox setting). $this->assertTrue((bool) block_course_message_get_mail_preference('inbox', $this->craig->id)); // Toggle to false. block_course_message_update_mail_preference('inbox', 'false'); $this->assertFalse((bool) block_course_message_get_mail_preference('inbox', $this->craig->id)); // Toggle back to true. block_course_message_update_mail_preference('inbox', 'true'); $this->assertTrue((bool) block_course_message_get_mail_preference('inbox', $this->craig->id)); // Make sure it is true (sent setting). $this->assertTrue((bool) block_course_message_get_mail_preference('sent', $this->craig->id)); // Toggle to false. block_course_message_update_mail_preference('sent', 'false'); $this->assertFalse((bool) block_course_message_get_mail_preference('sent', $this->craig->id)); // Toggle back to true. block_course_message_update_mail_preference('sent', 'true'); $this->assertTrue((bool) block_course_message_get_mail_preference('sent', $this->craig->id)); }
/** * This function sets the user preferences (emailing & display) for the four * test users. * */ protected function setup_user_preferences() { $this->setUser($this->craig); block_course_message_update_mail_preference('inbox', 'true'); block_course_message_update_mail_preference('sent', 'true'); block_course_message_update_display_preference('new_page'); $this->setUser($this->friend); block_course_message_update_mail_preference('inbox', 'true'); block_course_message_update_mail_preference('sent', 'false'); block_course_message_update_display_preference('iframe'); set_user_preferences(array('htmleditor' => 'tinymce')); $this->setUser($this->martha); block_course_message_update_mail_preference('inbox', 'false'); block_course_message_update_mail_preference('sent', 'true'); set_user_preferences(array('htmleditor' => 'atto')); $this->setUser($this->wade); block_course_message_update_mail_preference('inbox', 'false'); block_course_message_update_mail_preference('sent', 'false'); }
/** * This function tests the reply to all feature. Most of the logic that is * tested is in the update_for_parent() routine. But it also relies upon the * check_for_groups() routine in mail_record.class.php as well. * */ public function test_reply_to_all() { // Step 1) send mail from Craig to group + Friend. $params = array("subject" => 'Reply-to-all Test Subject', "message" => 'This message will be used to test reply-to-all.', "parentmessage" => 0, "replytype" => 'single', "draftid" => 0); $this->setUser($this->craig); $mailrecord = new mail_record(0, false); $mailrecord->set_send_params($params, array("g{$this->testgroupid}", "{$this->friend->id}")); $mailid = $this->send_mail($mailrecord, $this->testcourseid); /* Step 2) reply to all from "friend" (goes to "craig", "martha", "wade" * -> but only one copy for "craig", no inbox copy to "friend".*/ $this->setUser($this->friend); $params = array("subject" => 'This will get replaced', "message" => 'Reply to all from friend.', "parentmessage" => $mailid, "replytype" => 'all', "draftid" => 0); $mailrecord = new mail_record(0, false); $mailrecord->set_send_params($params, array("1")); $replyid = $this->send_mail($mailrecord, $this->testcourseid); $this->check_inbox_mail_map_count($replyid, $this->craig->id, 1); $this->check_inbox_mail_map_count($replyid, $this->friend->id, 0); $this->check_inbox_mail_map_count($replyid, $this->martha->id, 1); $this->check_inbox_mail_map_count($replyid, $this->wade->id, 1); /* Step 3) reply to all from "martha" (goes to "craig", "friend", "wade" * -> but only one copy for "craig", no inbox copy to "martha". */ $this->setUser($this->martha); // Make sure Martha doesn't get emails. block_course_message_update_mail_preference('sent', 'false'); block_course_message_update_mail_preference('inbox', 'false'); $params = array("subject" => 'This will get replaced', "message" => 'Reply to all from Martha.', "parentmessage" => $mailid, "replytype" => 'all', "draftid" => 0); $mailrecord = new mail_record(0, false); $mailrecord->set_send_params($params, array("1")); $replyid = $this->send_mail($mailrecord, $this->testcourseid); $this->check_inbox_mail_map_count($replyid, $this->craig->id, 1); $this->check_inbox_mail_map_count($replyid, $this->friend->id, 1); $this->check_inbox_mail_map_count($replyid, $this->martha->id, 0); $this->check_inbox_mail_map_count($replyid, $this->wade->id, 1); // Step 4) test reply to all with no parent (returns as fail). $this->setAdminUser(); $params["parentmessage"] = 0; $mailrecord = new mail_record(0, false); $mailrecord->set_send_params($params, array("1")); $this->send_mail($mailrecord, $this->testcourseid, 'bad reply'); }