MDL-54955 webservice: Apply external_format_string in course names

This commit is contained in:
Juan Leyva
2016-06-20 13:16:52 +01:00
parent 49619ce243
commit d889b58747
6 changed files with 22 additions and 9 deletions
+2 -2
View File
@@ -429,8 +429,8 @@ class core_course_external extends external_api {
$courseinfo = array();
$courseinfo['id'] = $course->id;
$courseinfo['fullname'] = $course->fullname;
$courseinfo['shortname'] = $course->shortname;
$courseinfo['fullname'] = external_format_string($course->fullname, $context->id);
$courseinfo['shortname'] = external_format_string($course->shortname, $context->id);
$courseinfo['displayname'] = external_format_string(get_course_display_name_for_list($course), $context->id);
$courseinfo['categoryid'] = $course->category;
list($courseinfo['summary'], $courseinfo['summaryformat']) =
+8 -4
View File
@@ -521,7 +521,9 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$generatedcourses = array();
$coursedata['idnumber'] = 'idnumbercourse1';
$coursedata['fullname'] = 'Course 1 for PHPunit test';
// Adding tags here to check that format_string is applied.
$coursedata['fullname'] = '<b>Course 1 for PHPunit test</b>';
$coursedata['shortname'] = '<b>Course 1 for PHPunit test</b>';
$coursedata['summary'] = 'Course 1 description';
$coursedata['summaryformat'] = FORMAT_MOODLE;
$course1 = self::getDataGenerator()->create_course($coursedata);
@@ -551,14 +553,16 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals(2, count($courses));
foreach ($courses as $course) {
$coursecontext = context_course::instance($course['id']);
$dbcourse = $generatedcourses[$course['id']];
$this->assertEquals($course['idnumber'], $dbcourse->idnumber);
$this->assertEquals($course['fullname'], $dbcourse->fullname);
$this->assertEquals($course['displayname'], get_course_display_name_for_list($dbcourse));
$this->assertEquals($course['fullname'], external_format_string($dbcourse->fullname, $coursecontext->id));
$this->assertEquals($course['displayname'], external_format_string(get_course_display_name_for_list($dbcourse),
$coursecontext->id));
// Summary was converted to the HTML format.
$this->assertEquals($course['summary'], format_text($dbcourse->summary, FORMAT_MOODLE, array('para' => false)));
$this->assertEquals($course['summaryformat'], FORMAT_HTML);
$this->assertEquals($course['shortname'], $dbcourse->shortname);
$this->assertEquals($course['shortname'], external_format_string($dbcourse->shortname, $coursecontext->id));
$this->assertEquals($course['categoryid'], $dbcourse->category);
$this->assertEquals($course['format'], $dbcourse->format);
$this->assertEquals($course['showgrades'], $dbcourse->showgrades);
+2
View File
@@ -323,6 +323,8 @@ class core_enrol_external extends external_api {
list($course->summary, $course->summaryformat) =
external_format_text($course->summary, $course->summaryformat, $context->id, 'course', 'summary', null);
$course->fullname = external_format_string($course->fullname, $context->id);
$course->shortname = external_format_string($course->shortname, $context->id);
$result[] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname,
'idnumber' => $course->idnumber, 'visible' => $course->visible, 'enrolledusercount' => $enrolledusercount,
+4
View File
@@ -363,6 +363,8 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
$this->resetAfterTest(true);
$coursedata1 = array(
'fullname' => '<b>Course 1</b>', // Adding tags here to check that external_format_string works.
'shortname' => '<b>Course 1</b>', // Adding tags here to check that external_format_string works.
'summary' => 'Lightwork Course 1 description',
'summaryformat' => FORMAT_MOODLE,
'lang' => 'en',
@@ -401,6 +403,8 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
// Check there are no differences between $course1 properties and course values returned by the webservice
// only for those fields listed in the $coursedata1 array.
$course1->fullname = external_format_string($course1->fullname, $contexts[$course1->id]->id);
$course1->shortname = external_format_string($course1->shortname, $contexts[$course1->id]->id);
foreach ($enrolledincourses as $courseenrol) {
if ($courseenrol['id'] == $course1->id) {
foreach ($coursedata1 as $fieldname => $value) {
+3 -2
View File
@@ -341,6 +341,7 @@ class mod_assign_external extends external_api {
if (!isset($courses[$cid])) {
$courses[$cid] = get_course($cid);
}
$courses[$cid]->contextid = $context->id;
} catch (Exception $e) {
unset($courses[$cid]);
$warnings[] = array(
@@ -473,8 +474,8 @@ class mod_assign_external extends external_api {
}
$coursearray[]= array(
'id' => $courses[$id]->id,
'fullname' => $courses[$id]->fullname,
'shortname' => $courses[$id]->shortname,
'fullname' => external_format_string($courses[$id]->fullname, $course->contextid),
'shortname' => external_format_string($courses[$id]->shortname, $course->contextid),
'timemodified' => $courses[$id]->timemodified,
'assignments' => $assignmentarray
);
+3 -1
View File
@@ -153,7 +153,8 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
// Create a course.
$course1 = self::getDataGenerator()->create_course(array(
'idnumber' => 'idnumbercourse1',
'fullname' => 'Lightwork Course 1',
'fullname' => '<b>Lightwork Course 1</b>', // Adding tags here to check that external_format_string works.
'shortname' => '<b>Lightwork Course 1</b>', // Adding tags here to check that external_format_string works.
'summary' => 'Lightwork Course 1 description',
'summaryformat' => FORMAT_MOODLE,
'category' => $category->id
@@ -221,6 +222,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
$this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0];
$this->assertEquals('Lightwork Course 1', $course['fullname']);
$this->assertEquals('Lightwork Course 1', $course['shortname']);
$this->assertEquals(1, count($course['assignments']));
$assignment = $course['assignments'][0];
$this->assertEquals($assign1->id, $assignment['id']);