Skip to content

Commit

Permalink
Merge branch 'MDL-59019-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jul 11, 2017
2 parents d77c73a + 7ddb5f2 commit b4a5f2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ public static function get_course_module_returns() {
'completionexpected' => new external_value(PARAM_INT, 'Completion time expected', VALUE_OPTIONAL),
'showdescription' => new external_value(PARAM_INT, 'If the description is showed', VALUE_OPTIONAL),
'availability' => new external_value(PARAM_RAW, 'Availability settings', VALUE_OPTIONAL),
'grade' => new external_value(PARAM_INT, 'Grade (max value or scale id)', VALUE_OPTIONAL),
'grade' => new external_value(PARAM_FLOAT, 'Grade (max value or scale id)', VALUE_OPTIONAL),
'scale' => new external_value(PARAM_TEXT, 'Scale items (if used)', VALUE_OPTIONAL),
'gradepass' => new external_value(PARAM_RAW, 'Grade to pass (float)', VALUE_OPTIONAL),
'gradecat' => new external_value(PARAM_INT, 'Grade category', VALUE_OPTIONAL),
Expand Down
24 changes: 13 additions & 11 deletions course/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1809,23 +1809,25 @@ public function test_get_course_module_by_instance() {
$course = self::getDataGenerator()->create_course();
$record = array(
'course' => $course->id,
'name' => 'First Chat'
'name' => 'First quiz',
'grade' => 90.00
);
$options = array(
'idnumber' => 'ABC',
'visible' => 0
);
// Hidden activity.
$chat = self::getDataGenerator()->create_module('chat', $record, $options);
$quiz = self::getDataGenerator()->create_module('quiz', $record, $options);

// Test admin user can see the complete hidden activity.
$result = core_course_external::get_course_module_by_instance('chat', $chat->id);
$result = core_course_external::get_course_module_by_instance('quiz', $quiz->id);
$result = external_api::clean_returnvalue(core_course_external::get_course_module_by_instance_returns(), $result);

$this->assertCount(0, $result['warnings']);
// Test we retrieve all the fields.
$this->assertCount(23, $result['cm']);
$this->assertCount(26, $result['cm']);
$this->assertEquals($record['name'], $result['cm']['name']);
$this->assertEquals($record['grade'], $result['cm']['grade']);
$this->assertEquals($options['idnumber'], $result['cm']['idnumber']);

$student = $this->getDataGenerator()->create_user();
Expand All @@ -1836,30 +1838,30 @@ public function test_get_course_module_by_instance() {

// The user shouldn't be able to see the activity.
try {
core_course_external::get_course_module_by_instance('chat', $chat->id);
core_course_external::get_course_module_by_instance('quiz', $quiz->id);
$this->fail('Exception expected due to invalid permissions.');
} catch (moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}

// Make module visible.
set_coursemodule_visible($chat->cmid, 1);
set_coursemodule_visible($quiz->cmid, 1);

// Test student user.
$result = core_course_external::get_course_module_by_instance('chat', $chat->id);
$result = core_course_external::get_course_module_by_instance('quiz', $quiz->id);
$result = external_api::clean_returnvalue(core_course_external::get_course_module_by_instance_returns(), $result);

$this->assertCount(0, $result['warnings']);
// Test we retrieve only the few files we can see.
$this->assertCount(11, $result['cm']);
$this->assertEquals($chat->cmid, $result['cm']['id']);
$this->assertEquals($quiz->cmid, $result['cm']['id']);
$this->assertEquals($course->id, $result['cm']['course']);
$this->assertEquals('chat', $result['cm']['modname']);
$this->assertEquals($chat->id, $result['cm']['instance']);
$this->assertEquals('quiz', $result['cm']['modname']);
$this->assertEquals($quiz->id, $result['cm']['instance']);

// Try with an invalid module name.
try {
core_course_external::get_course_module_by_instance('abc', $chat->id);
core_course_external::get_course_module_by_instance('abc', $quiz->id);
$this->fail('Exception expected due to invalid module name.');
} catch (dml_read_exception $e) {
$this->assertEquals('dmlreadexception', $e->errorcode);
Expand Down

0 comments on commit b4a5f2b

Please sign in to comment.