Merge branch 'MDL-53674-master-eventmsg' of git://github.com/mudrd8mz/moodle

This commit is contained in:
Dan Poltawski 2016-04-11 14:29:14 +01:00
commit 6ff935c206
2 changed files with 25 additions and 10 deletions

View File

@ -82,15 +82,16 @@ class notification_task extends \core\task\adhoc_task {
$template = $subscription->template;
$template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
$htmlmessage = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata = new \stdClass();
$msgdata->component = 'tool_monitor'; // Your component name.
$msgdata->name = 'notification'; // This is the message name from messages.php.
$msgdata->userfrom = \core_user::get_noreply_user();
$msgdata->userto = $user;
$msgdata->subject = $subscription->get_name($context);
$msgdata->fullmessage = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata->fullmessageformat = $subscription->templateformat;
$msgdata->fullmessagehtml = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata->fullmessage = html_to_text($htmlmessage);
$msgdata->fullmessageformat = FORMAT_PLAIN;
$msgdata->fullmessagehtml = $htmlmessage;
$msgdata->smallmessage = '';
$msgdata->notification = 1; // This is only set to 0 for personal messages between users.

View File

@ -467,7 +467,13 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$rulerecord->eventname = '\mod_book\event\course_module_viewed';
$rulerecord->cmid = $book->cmid;
$rulerecord->frequency = 1;
$rulerecord->template = '{link} {modulelink} {rulename} {description} {eventname}';
$rulerecord->template = '## {link} ##
* {modulelink}
* __{rulename}__
* {description}
* {eventname}';
$rulerecord->templateformat = FORMAT_MARKDOWN;
$rule = $toolgenerator->create_rule($rulerecord);
@ -491,13 +497,21 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$msg = array_pop($msgs);
$modurl = new moodle_url('/mod/book/view.php', array('id' => $book->cmid));
$expectedmsg = $event->get_url()->out() . ' ' .
$modurl->out() . ' ' .
$rule->get_name($context) . ' ' .
$rule->get_description($context) . ' ' .
$rule->get_event_name();
$this->assertEquals($expectedmsg, $msg->fullmessage);
$this->assertContains('<h2>'.$event->get_url()->out().'</h2>', $msg->fullmessagehtml);
$this->assertContains('<li>'.$modurl->out().'</li>', $msg->fullmessagehtml);
$this->assertContains('<li><strong>'.$rule->get_name($context).'</strong></li>', $msg->fullmessagehtml);
$this->assertContains('<li>'.$rule->get_description($context).'</li>', $msg->fullmessagehtml);
$this->assertContains('<li>'.$rule->get_event_name().'</li>', $msg->fullmessagehtml);
$this->assertEquals(FORMAT_PLAIN, $msg->fullmessageformat);
$this->assertNotContains('<h2>', $msg->fullmessage);
$this->assertNotContains('##', $msg->fullmessage);
$this->assertContains(strtoupper($event->get_url()->out()), $msg->fullmessage);
$this->assertContains('* '.$modurl->out(), $msg->fullmessage);
$this->assertContains('* '.strtoupper($rule->get_name($context)), $msg->fullmessage);
$this->assertContains('* '.$rule->get_description($context), $msg->fullmessage);
$this->assertContains('* '.$rule->get_event_name(), $msg->fullmessage);
}
/**