Skip to content

Commit

Permalink
MDL-48377 forum: do not swallow spaces in notification emails
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Nov 26, 2014
1 parent 702e65c commit 9e74aef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ function forum_cron() {
$a->courseshortname = $shortname;
$a->forumname = $cleanforumname;
$a->subject = format_string($post->subject, true);
$postsubject = html_to_text(get_string('postmailsubject', 'forum', $a));
$postsubject = html_to_text(get_string('postmailsubject', 'forum', $a), 0);
$posttext = forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfrom, $userto, false,
$replyaddress);
$posthtml = forum_make_mail_html($course, $cm, $forum, $discussion, $post, $userfrom, $userto,
Expand Down
30 changes: 28 additions & 2 deletions mod/forum/tests/mail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ protected function helper_create_users($course, $count) {
*
* @param stdClass $forum The forum to post in
* @param stdClass $author The author to post as
* @param array $fields any other fields in discussion (name, message, messageformat, ...)
* @param array An array containing the discussion object, and the post object
*/
protected function helper_post_to_forum($forum, $author) {
protected function helper_post_to_forum($forum, $author, $fields = array()) {
global $DB;
$generator = $this->getDataGenerator()->get_plugin_generator('mod_forum');

// Create a discussion in the forum, and then add a post to that discussion.
$record = new stdClass();
$record = (object)$fields;
$record->course = $forum->course;
$record->userid = $author->id;
$record->forum = $forum->id;
Expand Down Expand Up @@ -810,4 +811,29 @@ public function test_forum_message_inbound_multiple_posts() {
$this->assertRegExp('/Reply-To: moodlemoodle123\+[^@]*@example.com/', $message->header);
}
}

public function test_long_subject() {
$this->resetAfterTest(true);

// Create a course, with a forum.
$course = $this->getDataGenerator()->create_course();

$options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE);
$forum = $this->getDataGenerator()->create_module('forum', $options);

// Create a user enrolled in the course as student.
list($author) = $this->helper_create_users($course, 1);

// Post a discussion to the forum.
$subject = 'This is the very long forum post subject that somebody was very kind of leaving, it is intended to check if long subject comes in mail correctly. Thank you.';
$a = (object)array('courseshortname' => $course->shortname, 'forumname' => $forum->name, 'subject' => $subject);
$expectedsubject = get_string('postmailsubject', 'forum', $a);
list($discussion, $post) = $this->helper_post_to_forum($forum, $author, array('name' => $subject));

// Run cron and check that the expected number of users received the notification.
$messages = $this->helper_run_cron_check_count($post, 1);
$message = reset($messages);
$this->assertEquals($author->id, $message->useridfrom);
$this->assertEquals($expectedsubject, $message->subject);
}
}

0 comments on commit 9e74aef

Please sign in to comment.