예제 #1
0
 /**
  * Test addclasstable->get_item_display_options()
  */
 public function test_get_item_display_options()
 {
     $this->load_csv_data();
     $class = new pmclass(100);
     $class->load();
     $items = array();
     $url = new moodle_url('http://localhost/');
     $addclasstable = new addclasstable($items, $url);
     $option = $addclasstable->get_item_display_options('', $class);
     $expected = '<a href="index.php?s=crscat&amp;section=curr&amp;clsid=100&amp;action=savenew">Choose</a>';
     $this->assertEquals($expected, $option);
 }
예제 #2
0
 /**
  * Test block_elisadmin_load_menu_children_course function.
  */
 public function test_block_elisadmin_load_menu_children_course()
 {
     global $DB, $USER;
     accesslib_clear_all_caches(true);
     // Create test user - ensure the returned user is NOT a site admin. if they are, our capability restrictions won't work.
     $testuser = new user();
     $testuser->username = '******';
     $testuser->idnumber = 'testELIS4093';
     $testuser->firstname = 'testELIS4093';
     $testuser->lastname = 'testELIS4093';
     $testuser->email = '*****@*****.**';
     $testuser->country = 'CA';
     $testuser->save();
     $testmuser = $testuser->get_moodleuser();
     // Create role with cap: 'local/elisprogram:class_view'.
     $testrole = new stdClass();
     $testrole->name = 'ELIS Class View';
     $testrole->shortname = '_test_ELIS_4093';
     $testrole->description = 'ELIS Class View';
     $testrole->archetype = '';
     $testrole->id = create_role($testrole->name, $testrole->shortname, $testrole->description, $testrole->archetype);
     // Ensure our new role is assignable to ELIS class contexts.
     set_role_contextlevels($testrole->id, array(CONTEXT_ELIS_CLASS));
     // Ensure the role has our required capability assigned.
     $sitecontext = context_system::instance();
     assign_capability('local/elisprogram:class_view', CAP_ALLOW, $testrole->id, $sitecontext->id, true);
     $sitecontext->mark_dirty();
     // Create ELIS Course Description.
     $testcrs = new course(array('name' => 'CD-ELIS-4093', 'idnumber' => 'CDELIS4093', 'syllabus' => ''));
     $testcrs->save();
     $testcrs->load();
     // Create three(3) Class Instances for Course Descrption.
     $testcls1 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.1'));
     $testcls1->save();
     $testcls1->load();
     $testcls2 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.2'));
     $testcls2->save();
     $testcls2->load();
     $testcls3 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.3'));
     $testcls3->save();
     $testcls3->load();
     // Assign testuser new role in one Class Instance.
     $context = \local_elisprogram\context\pmclass::instance($testcls2->id);
     role_assign($testrole->id, $testmuser->id, $context->id);
     // Switch to testuser.
     $USER = $testmuser;
     $this->setUser($testmuser);
     $items = block_elisadmin_load_menu_children_course($testcrs->id, 0, 0, 5, '');
     $this->assertEquals(1, count($items));
     $this->assertTrue($items[0]->name == 'pmclass_2');
 }
예제 #3
0
 /**
  * Test successful user creation.
  */
 public function test_success()
 {
     global $DB;
     $this->give_permissions(array('local/elisprogram:class_create'));
     // Create custom field.
     $fieldcat = new field_category();
     $fieldcat->name = 'Test';
     $fieldcat->save();
     $field = new field();
     $field->categoryid = $fieldcat->id;
     $field->shortname = 'testfield';
     $field->name = 'Test Field';
     $field->datatype = 'text';
     $field->save();
     $fieldctx = new field_contextlevel();
     $fieldctx->fieldid = $field->id;
     $fieldctx->contextlevel = CONTEXT_ELIS_CLASS;
     $fieldctx->save();
     $course = new course();
     $course->idnumber = 'testcourse1';
     $course->name = 'Test Course 1';
     $course->syllabus = 'Test';
     $course->save();
     $class = array('idnumber' => 'testuser', 'startdate' => 'Jan/01/2013', 'enddate' => 'Feb/01/2013', 'assignment' => $course->idnumber, 'field_testfield' => 'Test Field');
     $response = local_datahub_elis_class_create::class_create($class);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     $this->assertEquals(get_string('ws_class_create_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_class_create_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get class.
     $expectedclass = array('idnumber' => $class['idnumber'], 'courseid' => $course->id, 'field_testfield' => 'Test Field');
     $createdclass = new pmclass($response['record']['id']);
     $createdclass->load();
     $createdclass = $createdclass->to_array();
     foreach ($expectedclass as $param => $val) {
         $this->assertArrayHasKey($param, $createdclass);
         $this->assertEquals($val, $createdclass[$param], $param);
     }
 }
예제 #4
0
 /**
  * Test the autoenrol after course completion function.
  */
 public function test_check_autoenrol_after_course_completion()
 {
     $dataset = $this->createCsvDataSet(array(course::TABLE => elispm::file('tests/fixtures/pmcourse.csv'), pmclass::TABLE => elispm::file('tests/fixtures/pmclass.csv'), user::TABLE => elispm::file('tests/fixtures/pmuser.csv'), student::TABLE => elispm::file('tests/fixtures/student.csv'), waitlist::TABLE => elispm::file('tests/fixtures/waitlist2.csv')));
     $this->loadDataSet($dataset);
     $class = new pmclass(100);
     $class->load();
     $class->maxstudents = 2;
     $class->enrol_from_waitlist = 1;
     $class->save();
     $student = new student(array('userid' => 103, 'classid' => 100));
     $student->completestatusid = STUSTATUS_PASSED;
     $student->save();
     $return = waitlist::check_autoenrol_after_course_completion($student);
     $this->assertTrue($return);
 }
예제 #5
0
 /**
  * display_confirmunenrol() new page to allow users to self-unenrol, if enabled
  * ELIS-8524
  * @uses $OUTPUT
  */
 public function display_confirmunenrol()
 {
     global $OUTPUT;
     $stuid = $this->optional_param('stuid', 0, PARAM_INT);
     $wlid = $this->optional_param('wlid', 0, PARAM_INT);
     $buttoncancel = new single_button(new moodle_url('index.php', array('s' => $this->pagename, 'action' => 'available')), get_string('no'));
     $prompt = null;
     if (!empty($stuid) && ($stu = new student($stuid))) {
         $pmclass = new pmclass($stu->classid);
         $pmclass->load();
         $prompt = get_string('unenrol_student', 'local_elisprogram', $pmclass->to_object());
         $buttoncontinue = new single_button(new moodle_url('index.php', array('s' => $this->pagename, 'action' => 'unenrol', 'stuid' => $stuid)), get_string('yes'));
     } else {
         if (!empty($wlid) && ($waitlist = new waitlist($wlid))) {
             $pmclass = new pmclass($waitlist->classid);
             $pmclass->load();
             $prompt = get_string('unenrol_waitlist', 'local_elisprogram', $pmclass->to_object());
             $buttoncontinue = new single_button(new moodle_url('index.php', array('s' => $this->pagename, 'action' => 'unenrol', 'wlid' => $wlid)), get_string('yes'));
         }
     }
     if ($prompt) {
         echo $OUTPUT->confirm($prompt, $buttoncontinue, $buttoncancel);
     } else {
         $this->display('available');
     }
 }
예제 #6
0
 public static function check_autoenrol_after_course_completion($enrolment)
 {
     if ($enrolment->completestatusid != STUSTATUS_NOTCOMPLETE) {
         $pmclass = new pmclass($enrolment->classid);
         $pmclass->load();
         if ((empty($pmclass->maxstudents) || $pmclass->maxstudents > student::count_enroled($pmclass->id)) && !empty($pmclass->enrol_from_waitlist)) {
             $wlst = waitlist::get_next($enrolment->classid);
             if (!empty($wlst)) {
                 $crsid = $pmclass->course->id;
                 foreach ($pmclass->course->curriculumcourse as $curcrs) {
                     if ($curcrs->courseid == $crsid && $curcrs->prerequisites_satisfied($wlst->userid)) {
                         $wlst->enrol();
                     }
                 }
             }
         }
     }
     return true;
 }
예제 #7
0
 /**
  * Validate the $student->validate_class_enrolment_limit function.
  */
 public function test_validate_class_enrolment_limit()
 {
     $this->load_csv_data();
     $student = new student(array('userid' => 104, 'classid' => 101));
     $student->load();
     $student->save();
     try {
         $result = $student->validate_class_enrolment_limit();
         $this->assertTrue($result);
     } catch (Exception $e) {
         // Should not reach here.
         $this->assertFalse(true);
     }
     $class = new pmclass(101);
     $class->load();
     $class->maxstudents = 1;
     $class->save();
     $student = new student(array('userid' => 103, 'classid' => 101));
     try {
         $result = $student->validate_class_enrolment_limit();
     } catch (Exception $e) {
         $this->assertTrue($e instanceof pmclass_enrolment_limit_validation_exception);
     }
 }