Merge branch 'MDL-86330-405' of https://github.com/yerairogo/moodle into MOODLE_405_STABLE

This commit is contained in:
Paul Holden
2025-09-10 16:26:45 +01:00
2 changed files with 11 additions and 4 deletions
+10 -2
View File
@@ -43,6 +43,9 @@ final class enrollib_test extends advanced_testcase {
$this->resetAfterTest();
// Use a mock incrementing clock to ensure deterministic and testable time values.
$clock = $this->mock_clock_with_incrementing(1750000000);
$studentrole = $DB->get_record('role', array('shortname'=>'student'));
$this->assertNotEmpty($studentrole);
$teacherrole = $DB->get_record('role', array('shortname'=>'teacher'));
@@ -96,13 +99,14 @@ final class enrollib_test extends advanced_testcase {
$manual->enrol_user($maninstance2, $user1->id);
$manual->enrol_user($maninstance2, $user2->id);
$manual->enrol_user($maninstance2, $user3->id, 0, 1, time()+(60*60));
$manual->enrol_user($maninstance2, $user3->id, 0, 1, $clock->time() + HOURSECS);
$manual->enrol_user($maninstance3, $user1->id);
$manual->enrol_user($maninstance3, $user2->id);
$manual->enrol_user($maninstance3, $user3->id, 0, 1, time()-(60*60));
$manual->enrol_user($maninstance3, $user3->id, 0, 1, $clock->time() - HOURSECS);
$manual->enrol_user($maninstance3, $user4->id, 0, 0, 0, ENROL_USER_SUSPENDED);
$manual->enrol_user($maninstance4, $user5->id, 0, $clock->time());
$courses = enrol_get_all_users_courses($CFG->siteguest);
$this->assertSame(array(), $courses);
@@ -152,6 +156,10 @@ final class enrollib_test extends advanced_testcase {
$this->assertCount(0, $courses);
$this->assertEquals(array(), array_keys($courses));
$courses = enrol_get_all_users_courses($user5->id, true);
$this->assertCount(1, $courses);
$this->assertEquals([$course4->id], array_keys($courses));
// Make sure sorting and columns work.
$basefields = array('id', 'category', 'sortorder', 'shortname', 'fullname', 'idnumber',
+1 -2
View File
@@ -1111,8 +1111,7 @@ function enrol_get_all_users_courses($userid, $onlyactive = false, $fields = nul
if ($onlyactive) {
$subwhere = "WHERE ue.status = :active AND e.status = :enabled AND ue.timestart < :now1 AND (ue.timeend = 0 OR ue.timeend > :now2)";
$params['now1'] = round(time(), -2); // improves db caching
$params['now2'] = $params['now1'];
$params['now1'] = $params['now2'] = \core\di::get(\core\clock::class)->time();
$params['active'] = ENROL_USER_ACTIVE;
$params['enabled'] = ENROL_INSTANCE_ENABLED;
} else {