diff --git a/course/externallib.php b/course/externallib.php index b348aa1a21e..d5fb71335d2 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -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']) = diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 9ad5d73aab3..07e7de04a55 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -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'] = 'Course 1 for PHPunit test'; + $coursedata['shortname'] = 'Course 1 for PHPunit test'; $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); diff --git a/enrol/externallib.php b/enrol/externallib.php index 8db19d9186c..669f50f68a7 100644 --- a/enrol/externallib.php +++ b/enrol/externallib.php @@ -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, diff --git a/enrol/tests/externallib_test.php b/enrol/tests/externallib_test.php index 21ad04d8bdf..a7d35ad4a38 100644 --- a/enrol/tests/externallib_test.php +++ b/enrol/tests/externallib_test.php @@ -363,6 +363,8 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { $this->resetAfterTest(true); $coursedata1 = array( + 'fullname' => 'Course 1', // Adding tags here to check that external_format_string works. + 'shortname' => 'Course 1', // 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) { diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index d0924caafa0..3cac4ed1baa 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -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 ); diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index c0805d4e07c..fccdbef4d01 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -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' => 'Lightwork Course 1', // Adding tags here to check that external_format_string works. + 'shortname' => 'Lightwork Course 1', // 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']);