示例#1
0
 /**
  * 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 version1elis_get_userid_for_user_actions_dataprovider
  */
 public function test_version1elis_get_userid_for_user_actions($usersdata, $inputdata, $expected)
 {
     global $CFG, $DB;
     $dir = get_plugin_directory('dhimport', 'version1elis');
     require_once $dir . '/lib.php';
     // Create users for test saving ids for later comparison
     $uids = array(false);
     foreach ($usersdata as $userdata) {
         $uids[] = $DB->insert_record(user::TABLE, (object) $userdata);
     }
     $provider = new rlipimport_version1elis_importprovider_mockuser(array());
     $importplugin = new open_rlip_importplugin_version1elis($provider);
     $importplugin->mappings = rlipimport_version1elis_get_mapping('user');
     $importplugin->fslogger = $provider->get_fslogger('dhimport_version1elis', '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));
         }
     }
 }
 /**
  * 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);
 }
示例#3
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', 'version1elis') . '/lib.php';
     require_once $file;
     //store field mappings for this entity type
     $this->mappings = rlipimport_version1elis_get_mapping($entity);
     return parent::process_import_file($entity, $maxruntime, $state);
 }
示例#4
0
//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_version1elis_page_setup($baseurl);
echo $OUTPUT->header();
//tabs
$tabs = rlipimport_version1elis_get_tabs($baseurl);
print_tabs(array($tabs), $tab);
//TODO: implement all necessary calls, etc, to make the rest of this code work
//data from db
$mappingdata = rlipimport_version1elis_get_mapping($tab);
//options
$plugin = new rlip_importplugin_version1elis(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_version1elis_save_mapping($tab, $options, $data);
        //notify to the user that settings were saved
        echo $OUTPUT->heading(get_string('mappingssaved', 'dhimport_version1elis'));
    } else {
        if (isset($data->reset)) {
            rlipimport_version1elis_reset_mappings($tab);
            redirect($baseurl . "?tab={$tab}&resetmessage=1", '', 0);
 /**
  * Validate that false is returned when obtaining field mapping for an
  * invalid entity type
  */
 public function testgetmappingreturnsfalseforinvalidentitytype()
 {
     // Obtain data.
     $fields = rlipimport_version1elis_get_mapping('bogus');
     // Data validation.
     $this->assertEquals($fields, false);
 }