/** * Test coursecatalogpage->display_savenew() for setting of class enrolment time (ELIS-8518) * @uses $DB * @uses $USER */ public function test_display_savenew_classenrolmenttime() { global $DB, $USER; $this->load_csv_data_for_enrolment_test(); $USER = $DB->get_record('user', array('id' => 100)); // Set user to the test user. $_GET['clsid'] = 100; // Class GET parameter is expected by coursecatalogpage function. $now = time(); // Set the startdate on the ELIS class to a day in the future. $pmclass = new pmclass(100); $pmclass->startdate = $now + 60 * 60 * 24; $pmclass->save(); // Set the startdate on the associated Moodle course to a day in the past. $course = new stdClass(); $course->id = 100; $course->startdate = $now - 60 * 60 * 24; $DB->update_record('course', $course); $coursecatalogpage = new coursecatalogpage(); try { $coursecatalogpage->display_savenew(); } catch (Exception $e) { // Ignore the redirect error message because we are not testing that here. } $enrolmenttime = $DB->get_field('local_elisprogram_cls_enrol', 'enrolmenttime', array('classid' => 100, 'userid' => 103)); $difference = abs($now - $enrolmenttime); $this->assertLessThanOrEqual(1, $difference); // Allow for 1 second variance, just in case. }