MDL-52471 completion: fix deprecated use of 'object'

And add a unit test covering completion_can_view_data() without
full course object passed.
This commit is contained in:
Dan Poltawski 2015-12-10 14:45:57 +00:00
parent 8440c780bd
commit 194a02e409
2 changed files with 12 additions and 1 deletions

View File

@ -158,7 +158,7 @@ function completion_can_view_data($userid, $course = null) {
if (!is_object($course)) {
$cid = $course;
$course = new object();
$course = new stdClass();
$course->id = $cid;
}

View File

@ -858,6 +858,17 @@ class core_completionlib_testcase extends advanced_testcase {
$expectedlegacylog = array($this->course->id, 'course', 'completion updated', 'completion.php?id='.$this->course->id);
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
public function test_completion_can_view_data() {
$this->setup_data();
$student = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($student->id, $this->course->id);
$this->setUser($student);
$this->assertTrue(completion_can_view_data($student->id, $this->course->id));
$this->assertFalse(completion_can_view_data($this->user->id, $this->course->id));
}
}
class core_completionlib_fake_recordset implements Iterator {