/** * 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 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_display_preference() function. * The ability to load in an iframe has been removed: no longer tested. * * To be clear: the function to change the preference will still do so, however, the * function that reads the preference will always return BLOCK_CM_ON_PAGE. * */ public function test_update_display_preference() { $this->setUser($this->craig); // Toggle to on page. block_course_message_update_display_preference(BLOCK_CM_ON_PAGE); $this->assertEquals(block_course_message_get_display_preference($this->craig->id), BLOCK_CM_ON_PAGE); // Toggle back to iframe -- no longer possible (no assert to test). block_course_message_update_display_preference(BLOCK_CM_IN_IFRAME); }