/** * @runInSeparateProcess */ public function test_student_courses() { $this->resetAfterTest(true); $user = $this->getDataGenerator()->create_user(); $row = array(); $row['user_id'] = $user->id; $row['email'] = null; $row['timestamp'] = time(); G\addvaliduser($row); $this->setUser($user); $course = $this->getDataGenerator()->create_course(); $cohort = $this->getDataGenerator()->create_cohort(array('idnumber' => 1234.56789)); cohort_add_member($cohort->id, $user->id); G\addtermid('1234'); $enrol = enrol_get_plugin('cohort'); $instance = array(); $instance['name'] = 'name'; $instance['status'] = ENROL_INSTANCE_ENABLED; // Enable it. $instance['customint1'] = $cohort->id; // Used to store the cohort id. $instance['roleid'] = $enrol->get_config('roleid'); // Default role for cohort enrol which is usually student. $instance['customint2'] = 0; // Optional group id. $enrol->add_instance($course, $instance); $trace = new null_progress_trace(); enrol_cohort_sync($trace, $course->id); $trace->finished(); $courses = G\coursesas($user->id, 'student'); $courseids = array(); foreach ($courses as $newcourse) { array_push($courseids, $newcourse->id); } $this->assertContains($course->id, $courseids); }
/** * @runInSeparateProcess */ public function test_report() { $this->resetAfterTest(true); $user = $this->getDataGenerator()->create_user(); $this->adduser($user->id); $this->setUser($user); $course = $this->getDataGenerator()->create_course(); $cohort = $this->getDataGenerator()->create_cohort(array('idnumber' => 1234.56789)); cohort_add_member($cohort->id, $user->id); G\addtermid('1234'); $this->enroluserincourse($course, $cohort, 'teacher'); $user2 = $this->getDataGenerator()->create_user(); $this->adduser($user2->id); $user3 = $this->getDataGenerator()->create_user(); $this->adduser($user3->id); $user4 = $this->getDataGenerator()->create_user(); $this->adduser($user4->id); $cohort2 = $this->getDataGenerator()->create_cohort(array('idnumber' => 9876.54321)); cohort_add_member($cohort2->id, $user2->id); cohort_add_member($cohort2->id, $user3->id); cohort_add_member($cohort2->id, $user4->id); G\addtermid('9876'); $this->enroluserincourse($course, $cohort2, 'student'); $year = date("Y"); $sem = G\semOfDate(date("d"), date("m")); G\newassessment($user3->id, time(), 121, $sem, "Student"); $students = G\studentsofcourse($course->id); $numofstudents = count($students); $numofstudentsdoneassessment = 0; if (count($students) > 0) { foreach ($students as $studentid) { if (G\doneassessment($studentid, $sem, $year)) { $numofstudentsdoneassessment++; } } } $this->assertEquals(3, $numofstudents); $this->assertEquals(1, $numofstudentsdoneassessment); }
} else { if ($act == "deleteAtt") { // If form submited to delete Attribute. $deleteid = optional_param("deleteid", null, PARAM_TEXT); G\deleteattribute($deleteid); } else { if ($act == "deleteSubAtt") { // If form submited to delete sub-attribute. $deleteid = optional_param("deleteid", null, PARAM_TEXT); G\deletesubattribute($deleteid); } else { if ($act == "cohorts") { $str2 = optional_param("cohorts", null, PARAM_TEXT); $strs = explode(",", $str2); foreach ($strs as $str) { G\addtermid($str); } } else { if ($act == "deletecohorts") { $DB->delete_records("local_gas_activeterm"); } else { if ($act == "deletesems") { $DB->delete_records("local_gas_semesters"); } else { if ($act == "addsems") { $str2 = optional_param("text", null, PARAM_TEXT); $str = str_replace(PHP_EOL, '', $str2); $str = preg_replace('/\\s+/', ' ', trim($str)); $strs = explode("#", $str); $semnum = intval(trim(current($strs))); for ($i = 0; $i < $semnum; $i++) {