Skip to content

Commit

Permalink
Merge branch 'MDL-55222-31' of git://github.com/jleyva/moodle into MO…
Browse files Browse the repository at this point in the history
…ODLE_31_STABLE
  • Loading branch information
David Monllao committed Oct 3, 2016
2 parents d65b822 + 23460f7 commit 72a0822
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions course/externallib.php
Expand Up @@ -431,8 +431,8 @@ public static function get_courses($options = array()) {

$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']) =
Expand Down
12 changes: 8 additions & 4 deletions course/tests/externallib_test.php
Expand Up @@ -531,7 +531,9 @@ public function test_get_courses () {

$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);
Expand Down Expand Up @@ -561,14 +563,16 @@ public function test_get_courses () {
$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);
Expand Down
2 changes: 2 additions & 0 deletions enrol/externallib.php
Expand Up @@ -323,6 +323,8 @@ public static function get_users_courses($userid) {

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,
Expand Down
4 changes: 4 additions & 0 deletions enrol/tests/externallib_test.php
Expand Up @@ -363,6 +363,8 @@ public function test_get_users_courses() {
$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',
Expand Down Expand Up @@ -401,6 +403,8 @@ public function test_get_users_courses() {

// 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) {
Expand Down
5 changes: 3 additions & 2 deletions mod/assign/externallib.php
Expand Up @@ -341,6 +341,7 @@ public static function get_assignments($courseids = array(), $capabilities = arr
if (!isset($courses[$cid])) {
$courses[$cid] = get_course($cid);
}
$courses[$cid]->contextid = $context->id;
} catch (Exception $e) {
unset($courses[$cid]);
$warnings[] = array(
Expand Down Expand Up @@ -473,8 +474,8 @@ public static function get_assignments($courseids = array(), $capabilities = arr
}
$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
);
Expand Down
4 changes: 3 additions & 1 deletion mod/assign/tests/externallib_test.php
Expand Up @@ -153,7 +153,8 @@ public function test_get_assignments() {
// 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
Expand Down Expand Up @@ -221,6 +222,7 @@ public function test_get_assignments() {
$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']);
Expand Down

0 comments on commit 72a0822

Please sign in to comment.