mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
MDL-64644 completion: ensure we return array for provider
This commit is contained in:
parent
b39f7194a8
commit
124c24eb0e
2 changed files with 59 additions and 40 deletions
|
@ -161,7 +161,9 @@ class provider implements
|
|||
$completioninfo = new \completion_info($course);
|
||||
$completion = $completioninfo->is_enabled();
|
||||
|
||||
if ($completion == COMPLETION_ENABLED) {
|
||||
if ($completion != COMPLETION_ENABLED) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$coursecomplete = $completioninfo->is_course_complete($user->id);
|
||||
$criteriacomplete = $completioninfo->count_course_user_data($user->id);
|
||||
|
@ -202,7 +204,6 @@ class provider implements
|
|||
}, $completions);
|
||||
return $coursecompletiondata;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete completion information for users.
|
||||
|
|
|
@ -202,4 +202,22 @@ class core_completion_privacy_test extends \core_privacy\tests\provider_testcase
|
|||
$hasyes = array_search('Yes', $coursecompletion1['criteria'], true);
|
||||
$this->assertFalse($hasyes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting course completion information with completion disabled.
|
||||
*/
|
||||
public function test_get_course_completion_info_completion_disabled() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 0]);
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, 'student');
|
||||
|
||||
$coursecompletion = \core_completion\privacy\provider::get_course_completion_info($user, $course);
|
||||
|
||||
$this->assertTrue(is_array($coursecompletion));
|
||||
$this->assertEmpty($coursecompletion);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue