/**
  * Validate that false is returned when obtaining field mapping for an
  * invalid entity type
  */
 public function test_getmappingreturnsfalseforinvalidentitytype()
 {
     // Obtain data.
     $fields = rlipimport_version1_get_mapping('bogus');
     // Data validation.
     $this->assertEquals($fields, false);
 }
 /**
  * Validate that field mapping does not use a field if its name should be
  * mapped to some other value
  */
 public function test_version1importenrolmentfieldimportpreventsstandardfielduse()
 {
     global $CFG, $DB;
     $plugindir = get_plugin_directory('dhimport', 'version1');
     require_once $plugindir . '/lib.php';
     require_once $plugindir . '/version1.class.php';
     // Create the mapping record.
     $record = new stdClass();
     $record->entitytype = 'enrolment';
     $record->standardfieldname = 'context';
     $record->customfieldname = 'context2';
     $DB->insert_record(RLIPIMPORT_VERSION1_MAPPING_TABLE, $record);
     // Get the import plugin set up.
     $data = array();
     $provider = new rlipimport_version1_importprovider_mockenrolment($data);
     $importplugin = new rlip_importplugin_version1($provider);
     $importplugin->mappings = rlipimport_version1_get_mapping('enrolment');
     // Transform a sample record.
     $record = new stdClass();
     $record->context = 'course';
     $record = $importplugin->apply_mapping('enrolment', $record);
     $DB->delete_records(RLIPIMPORT_VERSION1_MAPPING_TABLE);
     // Validate that the field was unset.
     $this->assertEquals(isset($record->context), false);
 }
 /**
  * Validate method get_userid_for_user_actions
  * @param array  $usersdata list of users w/ data to insert before test
  * @param array  $inputdata the user import record
  * @param array  $expected array of expected return param values
  * @dataProvider version1_get_userid_for_user_actions_dataprovider
  */
 public function test_version1_get_userid_for_user_actions($usersdata, $inputdata, $expected)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/datahub/importplugins/version1/lib.php';
     // Create users for test saving ids for later comparison
     $uids = array(false);
     foreach ($usersdata as $userdata) {
         if (!isset($userdata['mnethostid'])) {
             $userdata['mnethostid'] = $CFG->mnet_localhost_id;
         }
         $uids[] = $DB->insert_record('user', (object) $userdata);
     }
     $provider = new rlipimport_version1_importprovider_mockuser(array());
     $importplugin = new open_rlip_importplugin_version1($provider);
     $importplugin->mappings = rlipimport_version1_get_mapping('user');
     $importplugin->fslogger = $provider->get_fslogger('dhimport_version1', 'user');
     $error = 0;
     $errors = array();
     $errsuffix = '';
     // Cannot use ReflectionMethod for pass-by-reference params in method
     $uid = $importplugin->get_userid_for_user_actions((object) $inputdata, 'user.csv', $error, $errors, $errsuffix);
     $expecteduid = $expected['uid'];
     if ($expecteduid) {
         $expecteduid = $uids[$expecteduid];
     }
     $this->assertEquals($expecteduid, $uid);
     $this->assertEquals($expected['error'], $error);
     if (isset($expected['errsuffix'])) {
         $this->assertEquals($expected['errsuffix'], $errsuffix);
     }
     if (isset($expected['errors'])) {
         foreach ($expected['errors'] as $err) {
             $this->assertTrue(in_array($err, $errors));
         }
     }
 }
Example #4
0
require_once $CFG->dirroot . '/local/datahub/form/rlip_importfield_form.class.php';
//permissions checking
require_login();
$context = context_system::instance();
require_capability('moodle/site:config', $context);
$pluginwwwroot = str_replace($CFG->dirroot, $CFG->wwwroot, $plugindir);
$baseurl = $pluginwwwroot . '/config_fields.php';
$tab = optional_param('tab', 'user', PARAM_CLEAN);
//page header
rlipimport_version1_page_setup($baseurl);
echo $OUTPUT->header();
//tabs
$tabs = rlipimport_version1_get_tabs($baseurl);
print_tabs(array($tabs), $tab);
//data from db
$mappingdata = rlipimport_version1_get_mapping($tab);
//options
$plugin = new rlip_importplugin_version1(NULL, false);
$options = $plugin->get_available_fields($tab);
//body
$form = new rlip_importfield_form(null, $options);
//handle data submission
if ($data = $form->get_data()) {
    if (isset($data->submitbutton)) {
        rlipimport_version1_save_mapping($tab, $options, $data);
        //notify to the user that settings were saved
        echo $OUTPUT->heading(get_string('mappingssaved', 'dhimport_version1'));
    } else {
        if (isset($data->reset)) {
            rlipimport_version1_reset_mappings($tab);
            redirect($baseurl . "?tab={$tab}&resetmessage=1", '', 0);
Example #5
0
 /**
  * Entry point for processing an import file
  *
  * @param string $entity       The type of entity
  * @param int    $maxruntime   The max time in seconds to complete import
  *                             default: 0 => unlimited time
  * @param object $state        Previous ran state data to continue from
  * @return mixed object        Current state of import processing
  *                             or null for success.
  */
 function process_import_file($entity, $maxruntime = 0, $state = null)
 {
     $file = get_plugin_directory('dhimport', 'version1') . '/lib.php';
     require_once $file;
     //store field mappings for this entity type
     $this->mappings = rlipimport_version1_get_mapping($entity);
     return parent::process_import_file($entity, $maxruntime, $state);
 }