MDL-54049 core_message: Add missing external format text
This commit is contained in:
@@ -241,6 +241,9 @@ class core_calendar_external extends external_api {
|
||||
|
||||
foreach ($eventlist as $eventid => $eventobj) {
|
||||
$event = (array) $eventobj;
|
||||
// Description formatting.
|
||||
$calendareventobj = new calendar_event($event);
|
||||
list($event['description'], $event['format']) = $calendareventobj->format_external_text();
|
||||
|
||||
if ($hassystemcap) {
|
||||
// User can see everything, no further check is needed.
|
||||
|
||||
@@ -2671,6 +2671,36 @@ class calendar_event {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the text using the external API.
|
||||
* This function should we used when text formatting is required in external functions.
|
||||
*
|
||||
* @return array an array containing the text formatted and the text format
|
||||
*/
|
||||
public function format_external_text() {
|
||||
|
||||
if ($this->editorcontext === null) {
|
||||
// Switch on the event type to decide upon the appropriate context to use for this event.
|
||||
$this->editorcontext = $this->properties->context;
|
||||
|
||||
if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course'
|
||||
&& $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
|
||||
// We don't have a context here, do a normal format_text.
|
||||
return array(format_text($this->properties->description, $this->properties->format), $this->properties->format);
|
||||
}
|
||||
}
|
||||
|
||||
// Work out the item id for the editor, if this is a repeated event then the files will be associated with the original.
|
||||
if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
|
||||
$itemid = $this->properties->repeatid;
|
||||
} else {
|
||||
$itemid = $this->properties->id;
|
||||
}
|
||||
|
||||
return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id,
|
||||
'calendar', 'event_description', $itemid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -277,8 +277,28 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Let's create a few events.
|
||||
$siteevent = $this->create_calendar_event('site', $USER->id, 'site');
|
||||
|
||||
// This event will have description with an inline fake image.
|
||||
$draftidfile = file_get_unused_draft_itemid();
|
||||
$usercontext = context_course::instance($course->id);
|
||||
$filerecord = array(
|
||||
'contextid' => $usercontext->id,
|
||||
'component' => 'user',
|
||||
'filearea' => 'draft',
|
||||
'itemid' => $draftidfile,
|
||||
'filepath' => '/',
|
||||
'filename' => 'fakeimage.png',
|
||||
);
|
||||
$fs = get_file_storage();
|
||||
$fs->create_file_from_string($filerecord, 'img contents');
|
||||
|
||||
$record = new stdClass();
|
||||
$record->courseid = $course->id;
|
||||
$record->description = array(
|
||||
'format' => FORMAT_HTML,
|
||||
'text' => 'Text with img <img src="@@PLUGINFILE@@/fakeimage.png">',
|
||||
'itemid' => $draftidfile
|
||||
);
|
||||
$courseevent = $this->create_calendar_event('course', $USER->id, 'course', 2, time(), $record);
|
||||
$userevent = $this->create_calendar_event('user', $USER->id);
|
||||
$record = new stdClass();
|
||||
@@ -300,6 +320,18 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals(5, count($events['events']));
|
||||
$this->assertEquals(0, count($events['warnings']));
|
||||
|
||||
// Expect the same URL in the description of two different events (because they are repeated).
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$expectedurl = "webservice/pluginfile.php/$coursecontext->id/calendar/event_description/$courseevent->id/fakeimage.png";
|
||||
$withdescription = 0;
|
||||
foreach ($events['events'] as $event) {
|
||||
if (!empty($event['description'])) {
|
||||
$withdescription++;
|
||||
$this->assertContains($expectedurl, $event['description']);
|
||||
}
|
||||
}
|
||||
$this->assertEquals(2, $withdescription);
|
||||
|
||||
// Let's play around with caps.
|
||||
$this->setUser($user);
|
||||
$events = core_calendar_external::get_calendar_events($paramevents, $options);
|
||||
|
||||
Reference in New Issue
Block a user