/**
  * Test successful program enrolment creation.
  */
 public function test_success()
 {
     global $DB;
     $this->give_permissions(array('local/elisprogram:program_enrol'));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Create test program.
     $datagen = new elis_program_datagenerator($DB);
     $program = $datagen->create_program(array('idnumber' => 'TestProgramEnrolmentCreate'));
     $userid = $DB->get_field(user::TABLE, 'id', array('username' => 'assigninguser'));
     $data = array('program_idnumber' => $program->idnumber, 'user_username' => 'assigninguser', 'user_email' => '*****@*****.**', 'credits' => 1.1, 'locked' => 1, 'timecompleted' => 'May/28/2013', 'timeexpired' => 'May/28/2014');
     $expectdata = array('curriculumid' => $program->id, 'userid' => $userid, 'credits' => 1.1, 'locked' => 1, 'timecompleted' => $importplugin->parse_date('May/28/2013'), 'timeexpired' => $importplugin->parse_date('May/28/2014'));
     $response = local_datahub_elis_program_enrolment_create::program_enrolment_create($data);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     $this->assertEquals(get_string('ws_program_enrolment_create_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_program_enrolment_create_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get record.
     $curstu = $DB->get_record(curriculumstudent::TABLE, array('id' => $response['record']['id']));
     $this->assertNotEmpty($curstu);
     $curstu = (array) $curstu;
     foreach ($expectdata as $param => $val) {
         $this->assertArrayHasKey($param, $curstu, $param);
         $this->assertEquals($val, $curstu[$param], $param);
     }
 }
 /**
  * Test successful class enrolment creation.
  */
 public function test_success()
 {
     global $DB, $USER;
     $this->give_permissions(array('local/elisprogram:class_enrol'));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Create test course and class.
     $datagen = new elis_program_datagenerator($DB);
     $crs = $datagen->create_course(array('idnumber' => 'TestCourse'));
     $cls = $datagen->create_pmclass(array('idnumber' => 'TestClassEnrolmentCreate', 'courseid' => $crs->id));
     $data = array('class_idnumber' => $cls->idnumber, 'user_username' => 'assigninguser', 'user_email' => '*****@*****.**', 'completestatus' => 'passed', 'grade' => 67.89, 'credits' => 1.1, 'locked' => 1, 'enrolmenttime' => 'May/08/2013', 'completetime' => 'May/31/2013');
     $expectdata = array('classid' => $cls->id, 'userid' => $DB->get_field(user::TABLE, 'id', array('username' => 'assigninguser')), 'completestatusid' => STUSTATUS_PASSED, 'grade' => 67.89, 'credits' => 1.1, 'locked' => 1, 'enrolmenttime' => $importplugin->parse_date('May/08/2013'), 'completetime' => $importplugin->parse_date('May/31/2013'));
     $response = local_datahub_elis_class_enrolment_create::class_enrolment_create($data);
     $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_enrolment_create_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_class_enrolment_create_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get record.
     $stu = $DB->get_record(student::TABLE, array('id' => $response['record']['id']));
     $this->assertNotEmpty($stu);
     $stu = (array) $stu;
     foreach ($expectdata as $param => $val) {
         $this->assertArrayHasKey($param, $stu, $param);
         $this->assertEquals($val, $stu[$param], $param);
     }
 }
Ejemplo n.º 3
0
 /**
  * Performs class deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function class_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::class_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Get the class.
     $clsid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $data['idnumber']));
     if (empty($clsid)) {
         throw new data_object_exception('ws_class_delete_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:class_delete', \local_elisprogram\context\pmclass::instance($clsid));
     // Delete the class.
     $pmclass = new pmclass($clsid);
     $pmclass->delete();
     // Verify class deleted & respond.
     if (!$DB->record_exists(pmclass::TABLE, array('id' => $clsid))) {
         return array('messagecode' => get_string('ws_class_delete_success_code', 'local_datahub'), 'message' => get_string('ws_class_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_class_delete_fail', 'local_datahub');
     }
 }
Ejemplo n.º 4
0
/**
 * Retrieves a complete mapping from standard import field names to custom
 * field names
 *
 * @param string $entitytype The entity type to retrieve the mapping for
 * @return array The appropriate mapping
 */
function rlipimport_version1elis_get_mapping($entitytype)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/local/datahub/lib/rlip_dataplugin.class.php';
    $file = get_plugin_directory('dhimport', 'version1elis') . '/lib.php';
    require_once $file;
    //obtain the list of supported fields
    $plugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
    $fields = $plugin->get_available_fields($entitytype);
    if ($fields == false) {
        //invalid entitytype was supplied
        return false;
    }
    //by default, map each field to itself
    $result = array();
    foreach ($fields as $field) {
        $result[$field] = $field;
    }
    //apply mapping info from the database
    $params = array('entitytype' => $entitytype);
    if ($mappings = $DB->get_recordset(RLIPIMPORT_VERSION1ELIS_MAPPING_TABLE, $params)) {
        foreach ($mappings as $mapping) {
            $result[$mapping->standardfieldname] = $mapping->customfieldname;
        }
    }
    return $result;
}
 /**
  * Test successful program enrolment creation.
  */
 public function test_success()
 {
     global $DB, $USER;
     $this->give_permissions(array('local/elisprogram:userset_enrol'));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Create test userset.
     $datagen = new elis_program_datagenerator($DB);
     $userset = $datagen->create_userset(array('name' => 'TestUsersetEnrolmentCreate'));
     $userid = $DB->get_field(user::TABLE, 'id', array('username' => 'assigninguser'));
     $data = array('userset_name' => $userset->name, 'user_username' => 'assigninguser', 'user_email' => '*****@*****.**', 'leader' => true);
     $expectdata = array('clusterid' => $userset->id, 'userid' => $userid, 'plugin' => 'manual', 'leader' => '1');
     $response = local_datahub_elis_userset_enrolment_create::userset_enrolment_create($data);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     $this->assertEquals(get_string('ws_userset_enrolment_create_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_userset_enrolment_create_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get record.
     $clstass = $DB->get_record(clusterassignment::TABLE, array('id' => $response['record']['id']));
     $this->assertNotEmpty($clstass);
     $clstass = (array) $clstass;
     foreach ($expectdata as $param => $val) {
         $this->assertArrayHasKey($param, $clstass, $param);
         $this->assertEquals($val, $clstass[$param], $param);
     }
 }
Ejemplo n.º 6
0
 /**
  * Validate that the data plugin factory sets the right file plugin when
  * obtaining an export plugin instance
  */
 public function test_datapluginfactorysetscorrectfilepluginforexport()
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/datahub/lib/rlip_fileplugin.class.php';
     require_once $CFG->dirroot . '/local/datahub/lib/rlip_dataplugin.class.php';
     // Setup.
     $fileplugin = rlip_fileplugin_factory::factory('bogus');
     $exportplugin = rlip_dataplugin_factory::factory('dhexport_version1', null, $fileplugin);
     // Validation.
     $this->assertEquals($fileplugin, $exportplugin->get_file_plugin());
 }
 /**
  * Validates that the supplied data produces the expected error
  *
  * @param array $data The import data to process
  * @param string $expectederror The error we are expecting (message only)
  * @param user $entitytype One of 'user', 'course', 'enrolment'
  */
 protected function assert_data_produces_error($data, $expectederror, $entitytype)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/datahub/lib/rlip_fileplugin.class.php';
     require_once $CFG->dirroot . '/local/datahub/lib/rlip_dataplugin.class.php';
     // Set the log file location.
     $filepath = $CFG->dataroot . RLIP_DEFAULT_LOG_PATH;
     self::cleanup_log_files();
     // Run the import.
     $classname = "rlipimport_version1elis_importprovider_fslog{$entitytype}";
     $provider = new $classname($data);
     $instance = rlip_dataplugin_factory::factory('dhimport_version1elis', $provider, null, true);
     // Suppress output for now.
     ob_start();
     $instance->run();
     ob_end_clean();
     // Validate that a log file was created.
     $manual = true;
     // Get first summary record - at times, multiple summary records are created and this handles that problem.
     $records = $DB->get_records(RLIP_LOG_TABLE, null, 'starttime DESC');
     foreach ($records as $record) {
         $starttime = $record->starttime;
         break;
     }
     // Get logfile name.
     $plugintype = 'import';
     $plugin = 'dhimport_version1elis';
     $format = get_string('logfile_timestamp', 'local_datahub');
     $testfilename = $filepath . '/' . $plugintype . '_version1elis_manual_' . $entitytype . '_' . userdate($starttime, $format) . '.log';
     // Get most recent logfile.
     $filename = self::get_current_logfile($testfilename);
     if (!file_exists($filename)) {
         echo "\n can't find logfile: {$filename} for \n{$testfilename}";
     }
     $this->assertTrue(file_exists($filename));
     // Fetch log line.
     $pointer = fopen($filename, 'r');
     $prefixlength = strlen('[MMM/DD/YYYY:hh:mm:ss -zzzz] ');
     while (!feof($pointer)) {
         $error = fgets($pointer);
         if (!empty($error)) {
             // Could be an empty new line.
             if (is_array($expectederror)) {
                 $actualerror[] = substr($error, $prefixlength);
             } else {
                 $actualerror = substr($error, $prefixlength);
             }
         }
     }
     fclose($pointer);
     $this->assertEquals($expectederror, $actualerror);
 }
Ejemplo n.º 8
0
 /**
  * Validate that appropriate fields are synched over to Moodle when PM user is enrolled in a class instance during an import.
  */
 public function test_user_sync_on_pm_user_create()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/classmoodlecourse.class.php');
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/user.class.php');
     // Configure the elis enrolment plugin.
     $roleid = $DB->get_field('role', 'id', array(), IGNORE_MULTIPLE);
     set_config('roleid', $roleid, 'enrol_elis');
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA'));
     $user->save();
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $class->save();
     $category = new stdClass();
     $category->name = 'testcategoryname';
     $category->id = $DB->insert_record('course_categories', $category);
     // Create the associated context.
     context_coursecat::instance($category->id);
     $mdlcourse = new stdClass();
     $mdlcourse->category = $category->id;
     $mdlcourse->fullname = 'testcoursefullname';
     $mdlcourse = create_course($mdlcourse);
     // Associate class instance to Moodle course.
     $classmoodlecourse = new classmoodlecourse(array('classid' => $class->id, 'moodlecourseid' => $mdlcourse->id));
     $classmoodlecourse->save();
     // Run the enrolment create action.
     $record = new stdClass();
     $record->context = 'class_testclassidnumber';
     $record->user_username = '******';
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_enrolment_create($record, 'bogus', 'testclassidnumber');
     // Validate the enrolment.
     $enrolid = $DB->get_field('enrol', 'id', array('enrol' => 'elis', 'courseid' => $mdlcourse->id));
     $this->assertNotEquals(false, $enrolid);
     $mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
     $this->assertNotEquals(false, $mdluserid);
     $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $enrolid, 'userid' => $mdluserid)));
     // Validate the role assignment.
     $mdlcoursecontext = context_course::instance($mdlcourse->id);
     $this->assertTrue($DB->record_exists('role_assignments', array('roleid' => $roleid, 'contextid' => $mdlcoursecontext->id, 'userid' => $mdluserid)));
 }
Ejemplo n.º 9
0
 /**
  * Performs user deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function user_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::user_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Get the user we're updating via identifying fields.
     $idfields = array('idnumber', 'username', 'email');
     $userid = null;
     foreach ($idfields as $field) {
         if (isset($data[$field])) {
             $user = $DB->get_record(user::TABLE, array($field => $data[$field]));
             if (!empty($user)) {
                 if (!empty($userid) && $userid !== $user->id) {
                     // If we already have a userid from a previous field and this user doesn't match that user, throw exception.
                     throw new moodle_exception('ws_user_delete_fail_conflictingidfields', 'local_datahub');
                 } else {
                     $userid = $user->id;
                 }
             }
         }
     }
     if (empty($userid)) {
         // No valid identifying fields found.
         throw new moodle_exception('ws_user_delete_fail_noidfields', 'local_datahub');
     }
     // Capability checking.
     require_capability('local/elisprogram:user_delete', \local_elisprogram\context\user::instance($userid));
     // Delete the user.
     $user = new user($userid);
     $user->delete();
     // Verify user deleted & respond
     if (!$DB->record_exists(user::TABLE, array('id' => $userid))) {
         return array('messagecode' => get_string('ws_user_delete_success_code', 'local_datahub'), 'message' => get_string('ws_user_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_user_delete_fail', 'local_datahub');
     }
 }
 /**
  * Validate that an appropriate error is logged when maximum runtime is
  * exceeded during a manual or scheduled export
  *
  * @param bool $manual True if the run should be manual, or false for scheduled
  * @param string $expectederror The error we are expecting to find in the log file
  * @dataProvider dataprovider_exporttype
  */
 public function test_filesystemlogginglogsruntimeexceeded($manual, $expectederror)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/datahub/lib/rlip_dataplugin.class.php';
     require_once $CFG->dirroot . '/local/datahub/exportplugins/version1elis/tests/other/rlip_fileplugin_export.class.php';
     // Setup.
     $this->load_csv_data();
     set_config('nonincremental', 1, 'dhexport_version1elis');
     $filepath = $CFG->dataroot . RLIP_DEFAULT_LOG_PATH;
     set_config('export_path', '/datahub/dhexport_version1elis', 'dhexport_version1elis');
     set_config('export_file', 'dhexport_version1elis.csv', 'dhexport_version1elis');
     $fileplugin = new rlip_fileplugin_export();
     $plugin = rlip_dataplugin_factory::factory('dhexport_version1elis', null, $fileplugin, $manual);
     // Suppress output.
     ob_start();
     $plugin->run(0, 0, -1);
     ob_end_clean();
     // Get most recent record.
     $records = $DB->get_records(RLIP_LOG_TABLE, null, 'starttime DESC');
     foreach ($records as $record) {
         $starttime = $record->starttime;
         break;
     }
     // Validate log file existence existence.
     // Set the filepath to the dataroot.
     $plugintype = 'export';
     $format = get_string('logfile_timestamp', 'local_datahub');
     $logtype = $manual ? 'manual' : 'scheduled';
     $testfilename = $filepath . '/' . $plugintype . '_version1elis_' . $logtype . '_' . userdate($starttime, $format) . '.log';
     $filename = self::get_current_logfile($testfilename);
     $this->assertTrue(file_exists($filename));
     // Fetch log line.
     $pointer = fopen($filename, 'r');
     $line = fgets($pointer);
     fclose($pointer);
     if ($line == false) {
         // No line found.
         $this->assertEquals(0, 1);
     }
     // Data validation.
     $prefixlength = strlen('[MMM/DD/YYYY:hh:mm:ss -zzzz] ');
     $actualerror = substr($line, $prefixlength);
     $this->assertEquals($expectederror, $actualerror);
 }
 /**
  * Test successful track enrolment creation.
  */
 public function test_success()
 {
     global $DB, $USER;
     set_config('notify_trackenrol_user', 1, 'local_elisprogram');
     $this->setAdminUser();
     unset_config('noemailever');
     $this->give_permissions(array('local/elisprogram:track_enrol'));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Create test program and track.
     $datagen = new elis_program_datagenerator($DB);
     $program = $datagen->create_program(array('idnumber' => 'TestProgramForTrack'));
     $track = $datagen->create_track(array('idnumber' => 'TestTrackForProgram', 'curid' => $program->id));
     $userid = $DB->get_field(user::TABLE, 'id', array('username' => 'assigninguser'));
     $data = array('track_idnumber' => $track->idnumber, 'user_username' => 'assigninguser', 'user_email' => '*****@*****.**');
     $expectdata = array('userid' => $userid, 'trackid' => $track->id);
     // Redirect emails.
     $sink = $this->redirectEmails();
     // Run track enrolment create.
     $response = local_datahub_elis_track_enrolment_create::track_enrolment_create($data);
     // Assert we sent a message.
     $this->assertEquals(1, count($sink->get_messages()));
     $sink->close();
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     $this->assertEquals(get_string('ws_track_enrolment_create_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_track_enrolment_create_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get record.
     $usertrack = $DB->get_record(usertrack::TABLE, array('id' => $response['record']['id']));
     $this->assertNotEmpty($usertrack);
     $usertrack = (array) $usertrack;
     foreach ($expectdata as $param => $val) {
         $this->assertArrayHasKey($param, $usertrack, $param);
         $this->assertEquals($val, $usertrack[$param], $param);
     }
 }
 /**
  * Test successful track enrolment deletion.
  */
 public function test_success()
 {
     global $DB, $USER;
     $this->give_permissions(array('local/elisprogram:track_enrol'));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Create test program and track.
     $datagen = new elis_program_datagenerator($DB);
     $program = $datagen->create_program(array('idnumber' => 'TestProgramForTrack'));
     $track = $datagen->create_track(array('idnumber' => 'TestTrackForProgram', 'curid' => $program->id));
     $userid = $DB->get_field(user::TABLE, 'id', array('username' => 'assigninguser'));
     // Create the track enrolment record to delete.
     $datagen->assign_user_to_track($userid, $track->id);
     $data = array('track_idnumber' => $track->idnumber, 'user_username' => 'assigninguser', 'user_email' => '*****@*****.**');
     $response = local_datahub_elis_track_enrolment_delete::track_enrolment_delete($data);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertEquals(get_string('ws_track_enrolment_delete_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_track_enrolment_delete_success_msg', 'local_datahub'), $response['message']);
     $this->assertFalse($DB->record_exists(usertrack::TABLE, array('userid' => $userid, 'trackid' => $track->id)));
 }
 /**
  * Test successful userset enrolment deletion.
  */
 public function test_success()
 {
     global $DB, $USER;
     $this->give_permissions(array('local/elisprogram:userset_enrol'));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Create test userset.
     $datagen = new elis_program_datagenerator($DB);
     $userset = $datagen->create_userset(array('name' => 'TestUsersetEnrolmentDelete'));
     $userid = $DB->get_field(user::TABLE, 'id', array('username' => 'assigninguser'));
     // Create the userset enrolment record to delete.
     $clstass = new clusterassignment(array('clusterid' => $userset->id, 'userid' => $userid, 'plugin' => 'manual'));
     $clstass->save();
     $data = array('userset_name' => $userset->name, 'user_username' => 'assigninguser', 'user_email' => '*****@*****.**');
     $response = local_datahub_elis_userset_enrolment_delete::userset_enrolment_delete($data);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertEquals(get_string('ws_userset_enrolment_delete_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_userset_enrolment_delete_success_msg', 'local_datahub'), $response['message']);
     $this->assertFalse($DB->record_exists(clusterassignment::TABLE, array('clusterid' => $userset->id, 'userid' => $userid, 'plugin' => 'manual')));
 }
 /**
  * Test successful program enrolment creation.
  */
 public function test_success()
 {
     global $DB;
     $this->give_permissions(array('local/elisprogram:program_enrol'));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Create test program.
     $datagen = new elis_program_datagenerator($DB);
     $program = $datagen->create_program(array('idnumber' => 'TestProgramEnrolmentCreate'));
     $userid = $DB->get_field(user::TABLE, 'id', array('username' => 'assigninguser'));
     // Create the program enrolment record to delete.
     $stucur = new curriculumstudent(array('curriculumid' => $program->id, 'userid' => $userid));
     $stucur->save();
     // Perform enrolment delete.
     $data = array('program_idnumber' => $program->idnumber, 'user_username' => 'assigninguser', 'user_email' => '*****@*****.**');
     $response = local_datahub_elis_program_enrolment_delete::program_enrolment_delete($data);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertEquals(get_string('ws_program_enrolment_delete_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_program_enrolment_delete_success_msg', 'local_datahub'), $response['message']);
     $this->assertFalse($DB->record_exists(curriculumstudent::TABLE, array('curriculumid' => $program->id, 'userid' => $userid)));
 }
Ejemplo n.º 15
0
 /**
  * Validate that track-class associations can be created during a class instance
  * update action
  *
  * @param mixed $autoenrol The appropriate autoenrol value specified
  * @param int $dbautoenrol The value expected to be set in the db for autoenrol
  * @dataProvider autoenrol_provider
  */
 public function test_associate_track_during_class_update($autoenrol, $dbautoenrol)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/curriculum.class.php');
     require_once elispm::lib('data/curriculumcourse.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/track.class.php');
     // Create the course description.
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     // Create the class instance.
     $pmclass = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $pmclass->save();
     // Create the curriculum / program.
     $curriculum = new curriculum(array('idnumber' => 'testcurriculumidnumber'));
     $curriculum->save();
     // Associate the course description to the program.
     $curriculumcourse = new curriculumcourse(array('curriculumid' => $curriculum->id, 'courseid' => $course->id));
     $curriculumcourse->save();
     // Create the track.
     $track = new track(array('curid' => $curriculum->id, 'idnumber' => 'testtrackidnumber'));
     $track->save();
     // Run the class instance update action.
     $record = new stdClass();
     $record->assignment = 'testcourseidnumber';
     $record->idnumber = 'testclassidnumber';
     $record->track = 'testtrackidnumber';
     if ($autoenrol !== null) {
         $record->autoenrol = $autoenrol;
     }
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_update($record, 'bogus');
     // Validation.
     $classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => 'testclassidnumber'));
     $this->assertTrue($DB->record_exists(trackassignment::TABLE, array('trackid' => $track->id, 'classid' => $classid, 'autoenrol' => $dbautoenrol)));
 }
Ejemplo n.º 16
0
 echo $OUTPUT->box_end();
 //initialize table
 $table = new html_table();
 $table->head = array(get_string('name'), get_string('settings'), get_string('schedule'), get_string('runmanually', 'local_datahub'));
 $table->align = array('left', 'center', 'center', 'center');
 $table->size = array('60%', '13%', '13%', '13%');
 $table->data = array();
 $table->width = '40%';
 //obtain plugins and iterate through them
 $plugins = get_plugin_list($plugintype);
 //base directory
 $directory = $directories[$plugintype];
 $directory = str_replace($CFG->dirroot, $CFG->wwwroot, $directory);
 foreach ($plugins as $name => $path) {
     //skip plugins used for testing only / ones that are not available
     $instance = rlip_dataplugin_factory::factory("{$plugintype}_{$name}");
     if (!$instance->is_available()) {
         continue;
     }
     //get the display name from the plugin-specific language string
     $displayname = get_string('pluginname', "{$plugintype}_{$name}");
     //configuration link
     $url = $CFG->wwwroot . "/admin/settings.php?section=rlipsetting{$plugintype}_{$name}";
     $attributes = array('href' => $url);
     $config_tag = html_writer::tag('a', get_string('edit'), $attributes);
     // schedule link
     $url = $CFG->wwwroot . "/local/datahub/schedulepage.php?plugin={$plugintype}_{$name}";
     $attributes = array('href' => $url);
     $sched_tag = html_writer::tag('a', get_string('managesched', 'local_datahub'), $attributes);
     //manual run link
     $url = "{$directory}/manualrun.php?plugin={$plugintype}_{$name}";
Ejemplo n.º 17
0
 /**
  * Validate that updating a user that will be auto-assigned to a user set
  * triggers group and grouping functionality
  */
 public function test_elis_user_update_triggers_group_and_grouping_setup()
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
     $this->set_up_required_data(true, false, true);
     // Set up the necessary config data.
     set_config('site_course_userset_groups', 1, 'elisprogram_usetgroups');
     set_config('userset_groupings', 1, 'elisprogram_usetgroups');
     set_config('siteguest', '');
     // Run the user update action.
     $record = new stdClass();
     $record->action = 'update';
     $record->idnumber = 'testuseridnumber';
     $record->autoassociate = 1;
     $temp = new user();
     $temp->reset_custom_field_list();
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     // Need to call process_record so that custom field mappings are handled.
     $importplugin->process_record('user', $record, 'bogus');
     $this->validate_end_result();
 }
Ejemplo n.º 18
0
 /**
  * Performs track update
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error creating the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function track_update(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::track_update_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     $record = new stdClass();
     $record = $data;
     // need all custom fields, etc.
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Validate
     if (empty($data->idnumber) || !($trkid = $DB->get_field(track::TABLE, 'id', array('idnumber' => $data->idnumber)))) {
         throw new data_object_exception('ws_track_update_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     unset($record->idnumber);
     // Capability checking.
     require_capability('local/elisprogram:track_edit', \local_elisprogram\context\track::instance($trkid));
     if (isset($data->startdate)) {
         $startdate = $importplugin->parse_date($data->startdate);
         if (empty($startdate)) {
             throw new data_object_exception('ws_track_update_fail_invalid_startdate', 'local_datahub', '', $data);
         } else {
             $record->startdate = $startdate;
         }
     }
     if (isset($data->enddate)) {
         $enddate = $importplugin->parse_date($data->enddate);
         if (empty($enddate)) {
             throw new data_object_exception('ws_track_update_fail_invalid_enddate', 'local_datahub', '', $data);
         } else {
             $record->enddate = $enddate;
         }
     }
     $track = new track($trkid);
     $track->load();
     $track->set_from_data($record);
     $track->save();
     // Respond.
     if (!empty($track->id)) {
         $trackrec = (array) $DB->get_record(track::TABLE, array('id' => $track->id));
         $trackobj = $track->to_array();
         // convert multi-valued custom field arrays to comma-separated listing
         $fields = self::get_track_custom_fields();
         foreach ($fields as $field) {
             // Generate name using custom field prefix.
             $fullfieldname = data_object_with_custom_fields::CUSTOM_FIELD_PREFIX . $field->shortname;
             if ($field->multivalued && isset($trackobj[$fullfieldname]) && is_array($trackobj[$fullfieldname])) {
                 $trackobj[$fullfieldname] = implode(',', $trackobj[$fullfieldname]);
             }
         }
         return array('messagecode' => get_string('ws_track_update_success_code', 'local_datahub'), 'message' => get_string('ws_track_update_success_msg', 'local_datahub'), 'record' => array_merge($trackrec, $trackobj));
     } else {
         throw new data_object_exception('ws_track_update_fail', 'local_datahub');
     }
 }
Ejemplo n.º 19
0
/**
 * Task to create a zip file from today's log files
 *
 * @param string $taskname local_eliscore_sched_tasks task name (unused).
 * @param int    $runtime  elis_scheduled tasks suggested run time (unused).
 * @param int    $time     day to archive logs - default (0) => yesterday's logs
 *                         (used for testing)
 * @uses $CFG
 * @return array           names of zip files created (used for testing)
 */
function rlip_compress_logs_cron($taskname, $runtime = 0, $time = 0)
{
    global $CFG;
    $zipfiles = array();
    require_once $CFG->libdir . '/filestorage/zip_archive.php';
    if (empty($time)) {
        $time = time() - DAYSECS;
        //get yesterday's date
    }
    //the types of plugins we are considering
    $plugintypes = array('dhimport' => 'import', 'dhexport' => 'export');
    //lookup for the directory paths for plugins
    $directories = get_plugin_types();
    //Loop through all plugins...
    $timestamp = userdate($time, get_string('logfiledaily_timestamp', 'local_datahub'), 99);
    foreach ($plugintypes as $plugintype => $pluginvalue) {
        //base directory
        $directory = $directories[$plugintype];
        //obtain plugins and iterate through them
        $plugins = get_plugin_list($plugintype);
        foreach ($plugins as $name => $path) {
            //skip plugins used for testing only / ones that are not available
            $instance = rlip_dataplugin_factory::factory("{$plugintype}_{$name}");
            if (!$instance->is_available()) {
                continue;
            }
            //get the display name from the plugin-specific language string
            $plugin_name = "{$plugintype}_{$name}";
            //figure out the location (directory) configured for log file storage
            $logfilelocation = get_config($plugin_name, 'logfilelocation');
            if (empty($logfilelocation)) {
                $logfilelocation = RLIP_DEFAULT_LOG_PATH;
            }
            $logfilelocation = rtrim($CFG->dataroot, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . trim($logfilelocation, DIRECTORY_SEPARATOR);
            $logfileprefix = "{$pluginvalue}_{$name}";
            $logfiledate = $timestamp;
            //do a glob of all log files of this plugin name and of the previous day's date
            $files = array();
            foreach (glob("{$logfilelocation}/{$logfileprefix}_*{$logfiledate}*.log") as $file) {
                $files[] = $file;
            }
            //create a zip file if there are files to archive
            if (!empty($files)) {
                $zipfile = "{$logfilelocation}/{$logfileprefix}_{$timestamp}.zip";
                //create the archive
                $zip = new zip_archive();
                if (!$zip->open($zipfile)) {
                    continue;
                }
                $zipfiles[] = $zipfile;
                foreach ($files as $file) {
                    //add the file
                    $zip->add_file_from_pathname(basename($file), $file);
                }
                //close the zip -- done!
                $zip->close();
                //remove the archived file(s) from the system
                foreach ($files as $file) {
                    @unlink($file);
                }
            }
        }
    }
    return $zipfiles;
}
 /**
  * Validate the "userset" general message
  */
 public function test_userseterrorcontainscorrectprefix()
 {
     $record = new stdClass();
     $record->action = 'create';
     $record->context = 'cluster';
     $record->name = 'testusersetname';
     $record->display = str_repeat('a', 256);
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->mappings = rlipimport_version1elis_get_mapping('course');
     $importplugin->fslogger = new capture_fslogger(null);
     $importplugin->check_userset_field_lengths($record, 'bogus');
     $expectedmessage = "User set with name \"testusersetname\" could not be created.";
     $this->assertStringStartsWith($expectedmessage, $importplugin->fslogger->message);
 }
Ejemplo n.º 21
0
 /**
  * Validate that the version 1 import plugin logs the exact message required to the
  * database when the import runs for too long on a manual run
  */
 public function test_version1manualimportlogsruntimedatabaseerror()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/datahub/lib.php';
     // Our import data.
     $data = array(array('action', 'username', 'password', 'firstname', 'lastname', 'email', 'city', 'country'), array('create', 'testuser', 'Password!0', 'firstname', 'lastname', 'a@b.c', 'test', 'CA'), array('create', 'testuser', 'Password!0', 'firstname', 'lastname', 'a@b.c', 'test', 'CA'), array('create', 'testuser', 'Password!0', 'firstname', 'lastname', 'a@b.c', 'test', 'CA'));
     // Import provider that creates an instance of a file plugin that delays two seconds between reading the third and
     // fourth entry.
     $provider = new rlip_importprovider_delay_after_three_users($data);
     $manual = true;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1', $provider, null, $manual);
     // We should run out of time after processing the second real entry.
     ob_start();
     // Using three seconds to allow for one slow read when counting lines.
     $importplugin->run(0, 0, 3);
     ob_end_clean();
     $expectedmsg = "Failed importing all lines from import file bogus due to time limit exceeded. Processed 2 of 3 records.";
     // Validation.
     $select = "{$DB->sql_compare_text('statusmessage')} = :message";
     $params = array('message' => $expectedmsg);
     $exists = $DB->record_exists_select(RLIP_LOG_TABLE, $select, $params);
     $this->assertTrue($exists);
 }
 /**
  * Performs userset_enrolment deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the association.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function userset_enrolment_delete(array $data)
 {
     global $DB, $USER;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::userset_enrolment_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Parse Userset
     if (empty($data->userset_name) || !($clstid = $DB->get_field(userset::TABLE, 'id', array('name' => $data->userset_name)))) {
         throw new data_object_exception('ws_userset_enrolment_delete_fail_invalid_userset', 'local_datahub', '', $data);
     }
     if (empty($data->plugin)) {
         $data->plugin = 'manual';
     }
     // Capability checking.
     require_capability('local/elisprogram:userset_enrol', \local_elisprogram\context\userset::instance($clstid));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $userparams = array();
     $userid = $importplugin->get_userid_from_record($data, '', $userparams);
     if ($userid == false) {
         $a = new stdClass();
         if (empty($userparams)) {
             $a->userparams = '{empty}';
         } else {
             $a->userparams = '';
             foreach ($userparams as $userfield => $uservalue) {
                 $subfield = strpos($userfield, '_');
                 $userfield = substr($userfield, $subfield === false ? 0 : $subfield + 1);
                 if (!empty($a->userparams)) {
                     $a->userparams .= ', ';
                 }
                 $a->userparams .= "{$userfield}: '{$uservalue}'";
             }
         }
         throw new data_object_exception('ws_userset_enrolment_delete_fail_invalid_user', 'local_datahub', '', $a);
     }
     $id = $DB->get_field(clusterassignment::TABLE, 'id', array('clusterid' => $clstid, 'userid' => $userid, 'plugin' => $data->plugin));
     // Respond.
     if (!empty($id) && ($clstass = new clusterassignment($id))) {
         $clstass->delete();
         return array('messagecode' => get_string('ws_userset_enrolment_delete_success_code', 'local_datahub'), 'message' => get_string('ws_userset_enrolment_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_userset_enrolment_delete_fail', 'local_datahub');
     }
 }
Ejemplo n.º 23
0
 /**
  * Performs course update
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error updating the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function course_update(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::course_update_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Validate course exists
     if (!($crsid = $DB->get_field(course::TABLE, 'id', array('idnumber' => $data->idnumber)))) {
         throw new data_object_exception('ws_course_update_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:course_edit', \local_elisprogram\context\course::instance($crsid));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Validate credits.
     if (isset($data->credits) && !(is_numeric($data->credits) && $data->credits >= 0)) {
         throw new data_object_exception('ws_course_update_fail_invalid_credits', 'local_datahub', '', $data);
     }
     // Validate completion grade.
     if (isset($data->completion_grade) && !(is_numeric($data->completion_grade) && $data->completion_grade >= 0 && $data->completion_grade <= 100)) {
         throw new data_object_exception('ws_course_update_fail_invalid_completion_grade', 'local_datahub', '', $data);
     }
     // Handle assignment to program.
     if (isset($data->assignment) && !empty($data->assignment)) {
         $programid = $DB->get_field(curriculum::TABLE, 'id', array('idnumber' => $data->assignment));
         if ($programid) {
             $curriculumcourseid = $DB->get_field(curriculumcourse::TABLE, 'id', array('curriculumid' => $programid, 'courseid' => $crsid));
             // Only assign if it is not already assigned
             if (!$curriculumcourseid) {
                 $data->curriculum = array($programid);
             }
         } else {
             throw new data_object_exception('ws_course_update_fail_invalid_assignment', 'local_datahub', '', $data);
         }
     }
     $course = new course($crsid);
     $course->load();
     $course->set_from_data($data);
     $course->save();
     // Handle linking to Moodle course.
     if (isset($data->link) && !empty($data->link)) {
         $moodlecourseid = $DB->get_field('course', 'id', array('shortname' => $data->link));
         if ($moodlecourseid) {
             $importplugin->associate_course_to_moodle_course($data, $course->id);
         } else {
             throw new data_object_exception('ws_course_update_fail_invalid_link', 'local_datahub', '', $data);
         }
     }
     // Respond.
     if (!empty($course->id)) {
         $courserec = (array) $DB->get_record(course::TABLE, array('id' => $course->id));
         $courseobj = $course->to_array();
         // convert multi-valued custom field arrays to comma-separated listing
         $fields = self::get_course_custom_fields();
         foreach ($fields as $field) {
             // Generate name using custom field prefix.
             $fullfieldname = data_object_with_custom_fields::CUSTOM_FIELD_PREFIX . $field->shortname;
             if ($field->multivalued && isset($courseobj[$fullfieldname]) && is_array($courseobj[$fullfieldname])) {
                 $courseobj[$fullfieldname] = implode(',', $courseobj[$fullfieldname]);
             }
         }
         return array('messagecode' => get_string('ws_course_update_success_code', 'local_datahub'), 'message' => get_string('ws_course_update_success_msg', 'local_datahub'), 'record' => array_merge($courserec, $courseobj));
     } else {
         throw new data_object_exception('ws_course_update_fail', 'local_datahub');
     }
 }
Ejemplo n.º 24
0
 /**
  * Performs updating of user identifiers.
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error editing the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function user_update_identifiers(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::user_update_identifiers_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $userparams = array();
     $data = (object) $data;
     $userid = $importplugin->get_userid_from_record($data, '', $userparams);
     if ($userid == false) {
         $a = new stdClass();
         if (empty($userparams)) {
             $a->userparams = '{empty}';
         } else {
             $a->userparams = '';
             foreach ($userparams as $userfield => $uservalue) {
                 $subfield = strpos($userfield, '_');
                 $userfield = substr($userfield, $subfield === false ? 0 : $subfield + 1);
                 if (!empty($a->userparams)) {
                     $a->userparams .= ', ';
                 }
                 $a->userparams .= "{$userfield}: '{$uservalue}'";
             }
         }
         throw new data_object_exception('ws_user_update_identifiers_fail_invalid_user', 'local_datahub', '', $a);
     }
     // Capability checking.
     require_capability('local/elisprogram:user_edit', \local_elisprogram\context\user::instance($userid));
     $user = new user($userid);
     $user->load();
     if (isset($data->username)) {
         $user->username = $data->username;
     }
     if (isset($data->idnumber)) {
         $user->idnumber = $data->idnumber;
     }
     if (isset($data->email)) {
         $user->email = $data->email;
     }
     $user->save();
     // Respond.
     $userrec = (array) $DB->get_record(user::TABLE, array('id' => $user->id));
     $userobj = $user->to_array();
     // Convert multi-valued custom field arrays to comma-separated listing.
     $fields = self::get_user_custom_fields();
     foreach ($fields as $field) {
         // Generate name using custom field prefix.
         $fullfieldname = data_object_with_custom_fields::CUSTOM_FIELD_PREFIX . $field->shortname;
         if ($field->multivalued && isset($userobj[$fullfieldname]) && is_array($userobj[$fullfieldname])) {
             $userobj[$fullfieldname] = implode(',', $userobj[$fullfieldname]);
         }
     }
     return array('messagecode' => get_string('ws_user_update_identifiers_success_code', 'local_datahub'), 'message' => get_string('ws_user_update_identifiers_success_msg', 'local_datahub'), 'record' => array_merge($userrec, $userobj));
 }
Ejemplo n.º 25
0
 /**
  * Validating that enrolling a user in a track instance triggers the enrolment
  * notification
  */
 public function test_track_enrolment_sends_class_enrolment_notification()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/curriculum.class.php');
     require_once elispm::lib('data/track.class.php');
     require_once elispm::lib('data/user.class.php');
     // Configuration.
     set_config('popup_provider_elis_program_notify_pm_permitted', 1, 'message');
     set_config('email_provider_elis_program_notify_pm_permitted', 1, 'message');
     set_config('notify_trackenrol_user', 1, 'local_elisprogram');
     $message = '%%userenrolname%% has been enrolled in the track %%trackname%%.';
     set_config('notify_trackenrol_message', $message, 'local_elisprogram');
     // Force refreshing of configuration.
     elis::$config = new elis_config();
     $this->setAdminUser();
     unset_config('noemailever');
     // Setup.
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => '*****@*****.**', 'country' => 'CA'));
     $user->save();
     $program = new curriculum(array('idnumber' => 'testprogramidnumber'));
     $program->save();
     $track = new track(array('curid' => $program->id, 'idnumber' => 'testtrackidnumber', 'name' => 'testtrackname'));
     $track->save();
     // Run the enrolment create action.
     $record = new stdClass();
     $record->context = 'track_testtrackidnumber';
     $record->user_username = '******';
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $sink = $this->redirectEmails();
     $importplugin->track_enrolment_create($record, 'bogus', 'testtrackidnumber');
     $this->assertEquals(1, count($sink->get_messages()));
     $sink->close();
     // Validation.
     $mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
     $expectedmessage = "{$user->firstname} {$user->lastname} has been enrolled in the track {$track->name}.";
     $like = $DB->sql_like('fullmessagehtml', ':message');
     $select = "useridto = :userid\n                   AND {$like}";
     $this->assertTrue($DB->record_exists_select('message', $select, array('userid' => $mdluserid, 'message' => "{$expectedmessage}%")));
 }
Ejemplo n.º 26
0
 /**
  * Validate that valid date formats in custom fields don't invalidate actions
  * @param string $value The value to use for the custom field
  * @param string $message The expected error message
  * @param array $otherparams Other parameters to give to the field owner
  * @dataProvider valid_date_format_provider
  */
 public function test_logging_does_not_invalidate_date_customfield_formatsaccepted($value, $otherparams)
 {
     // TODO: consider removing once we have unit tests properly validating.
     // Date/time custom field imports.
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/accesslib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
     $this->create_custom_field(CONTEXT_ELIS_USER, 'datetime', $otherparams);
     $data = array('action' => 'create', 'username' => 'testuserusername', 'email' => '*****@*****.**', 'idnumber' => 'testuseridnumber', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'country' => 'CA', 'testfieldshortname' => $value);
     // Run the import.
     $provider = new rlipimport_version1elis_importprovider_fsloguser($data);
     $instance = rlip_dataplugin_factory::factory('dhimport_version1elis', $provider, null, true);
     // Suppress output for now.
     ob_start();
     $instance->run();
     ob_end_clean();
     // Validate that a user is actually created.
     $this->assertEquals(1, $DB->count_records(user::TABLE));
 }
Ejemplo n.º 27
0
 /**
  * Validates that a standard export run, using the data plugin factory,
  * correctly opens and closes the export file via the file plugin
  */
 public function test_versionexportopensandclosesfile()
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/datahub/lib/rlip_dataplugin.class.php';
     // Run run the export.
     $fileplugin = new rlip_fileplugin_openclose();
     $instance = rlip_dataplugin_factory::factory('dhexport_version1', null, $fileplugin);
     $instance->run();
     // Validate that the export file was opened.
     $this->assertEquals($fileplugin->get_opened(), true);
     // Validat that the export file was closed.
     $this->assertEquals($fileplugin->get_closed(), true);
 }
 /**
  * Validate that the verison 1 import plugin logs the exact message required to the
  * file system when the import runs for too long on a manual run
  */
 public function test_version1elismanualimportlogsruntimefilesystemerror()
 {
     global $CFG, $DB;
     // Set up the log file location.
     set_config('logfilelocation', '', 'dhimport_version1elis');
     // Our import data.
     $data = array(array('action', 'username', 'password', 'firstname', 'lastname', 'email', 'city', 'country'), array('create', 'testuser', 'Password!0', 'firstname', 'lastname', 'a@b.c', 'test', 'CA'), array('create', 'testuser', 'Password!0', 'firstname', 'lastname', 'a@b.c', 'test', 'CA'), array('create', 'testuser', 'Password!0', 'firstname', 'lastname', 'a@b.c', 'test', 'CA'));
     // Import provider that creates an instance of a file plugin that delays two seconds.
     // Between reading the third and fourth entry.
     $provider = new rlip_importprovider_delay_after_three_users($data);
     $manual = true;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis', $provider, null, $manual);
     // We should run out of time after processing the second real entry.
     ob_start();
     // Using three seconds to allow for one slow read when counting lines.
     $importplugin->run(0, 0, 3);
     ob_end_clean();
     // Get most recent record.
     $records = $DB->get_records(RLIP_LOG_TABLE, null, 'starttime DESC');
     $filename = '';
     foreach ($records as $record) {
         $filename = $record->logpath;
         break;
     }
     // Validate that the right log file was created.
     $this->assertTrue(file_exists($filename));
     // Obtain log file lines.
     $contents = file_get_contents($filename);
     $contents = explode("\n", $contents);
     // Validate line count, accounting for blank line at end.
     $this->assertEquals(count($contents), 4);
     // Obtain the line we care about.
     $line = $contents[2];
     $expectederror = 'Import processing of entity \'user\' partially processed due to time restrictions. ';
     $expectederror .= 'Processed 2 of 3 total records.';
     // Data validation.
     $prefixlength = strlen('[MMM/DD/YYYY:hh:mm:ss -zzzz] ');
     $actualerror = substr($line, $prefixlength);
     $this->assertEquals($expectederror, $actualerror);
 }
 /**
  * Validate that class instance-moodle course associations can be created during a class instance update action.
  *
  * @param string $link The link attribute to use in the import, or 'auto' to auto-create from template.
  * @dataProvider link_course_provider
  */
 public function test_associate_moodle_course_during_class_update($link)
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/classmoodlecourse.class.php');
     require_once elispm::lib('data/coursetemplate.class.php');
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     // Make sure $USER is set up for backup/restore.
     $USER->id = $DB->get_field_select('user', 'id', "username != 'guest' AND deleted = 0", array(), IGNORE_MULTIPLE);
     // Need the moodle/backup:backupcourse capability.
     $guestroleid = create_role('guestrole', 'guestrole', 'guestrole');
     set_config('guestroleid', $guestroleid);
     set_config('siteguest', '');
     $systemcontext = context_system::instance();
     $roleid = create_role('testrole', 'testrole', 'testrole');
     assign_capability('moodle/backup:backupcourse', CAP_ALLOW, $roleid, $systemcontext->id);
     role_assign($roleid, $USER->id, $systemcontext->id);
     $coursecategory = new stdClass();
     $coursecategory->name = 'testcoursecategoryname';
     $coursecategory->id = $DB->insert_record('course_categories', $coursecategory);
     $moodlecourse = new stdClass();
     $moodlecourse->category = $coursecategory->id;
     $moodlecourse->shortname = 'testcourseshortname';
     $moodlecourse->fullname = 'testcoursefullname';
     $moodlecourse = create_course($moodlecourse);
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $class->save();
     // Need this for the 'auto' case, at the very least.
     $coursetemplate = new coursetemplate(array('courseid' => $course->id, 'location' => $moodlecourse->id, 'templateclass' => 'moodlecourseurl'));
     $coursetemplate->save();
     // Run the class instance create action.
     $record = new stdClass();
     $record->idnumber = 'testclassidnumber';
     $record->assignment = 'testcourseidnumber';
     $record->link = $link;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_update($record, 'bogus');
     // Validation.
     if ($record->link == 'auto') {
         $moodlecourseid = $moodlecourse->id + 1;
     } else {
         $moodlecourseid = $moodlecourse->id;
     }
     $dbautocreated = $record->link == 'auto' ? 1 : 0;
     $this->assertTrue($DB->record_exists(classmoodlecourse::TABLE, array('classid' => $class->id, 'moodlecourseid' => $moodlecourseid, 'enroltype' => 0, 'enrolplugin' => 'crlm', 'autocreated' => $dbautocreated)));
     ini_set('max_execution_time', '0');
 }
Ejemplo n.º 30
0
 /**
  * @dataProvider field_provider
  * @param string The import data (0, 1, yes, no)
  * @param string The expected data (0, 1)
  */
 public function test_elis_user_inactive_field($data, $expected)
 {
     global $DB;
     $record = array();
     $record = $this->testsetupdata[0];
     $record['inactive'] = $data;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->process_record('user', (object) $record, 'bogus');
     $params = array('idnumber' => $record['idnumber'], 'inactive' => $expected);
     $this->assertEquals(true, $DB->record_exists(user::TABLE, $params));
 }