MDL-53674 event monitor: Do not send HTML as plain text formatted emails
[moodle.git] / admin / tool / monitor / tests / eventobservers_test.php
index 79356c6..9239e16 100644 (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);
     }
 
     /**