/**
  * 
  * @param type $user
  * @param type $course
  * @param type $cohort
  * @param type $mode
  */
 private function enroluserincourse($course, $cohort, $mode)
 {
     $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.
     $teacherroleid = $enrol->get_config('roleid');
     if ($mode == 'teacher') {
         $teacherroleid = G\getteacherroleid();
     }
     $instance['roleid'] = $teacherroleid;
     $instance['customint2'] = 0;
     // Optional group id.
     $enrol->add_instance($course, $instance);
     $trace = new null_progress_trace();
     enrol_cohort_sync($trace, $course->id);
     $trace->finished();
 }
 /**
  * @runInSeparateProcess
  */
 public function test_teacher_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.
     $teacherroleid = G\getteacherroleid();
     $instance['roleid'] = $teacherroleid;
     $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, 'teacher');
     $courseids = array();
     foreach ($courses as $newcourse) {
         array_push($courseids, $newcourse->id);
     }
     $this->assertContains($course->id, $courseids);
 }