/** * Validate restoring default field mappings */ public function test_restoredefaultmappingupdatesrecords() { global $CFG, $DB; $file = get_plugin_directory('dhimport', 'version1') . '/lib.php'; require_once $file; // Obtain available fields. $plugin = new rlip_importplugin_version1(null, false); $options = $plugin->get_available_fields('user'); // Persist default field. rlipimport_version1_save_mapping('user', $options, array()); // Setup validation. $select = 'standardfieldname = customfieldname'; $count = $DB->count_records_select(RLIPIMPORT_VERSION1_MAPPING_TABLE, $select); $this->assertEquals($count, count($options)); // Update all mapping values. $data = array(); foreach ($options as $option) { $data[$option] = $option . 'updated'; } // Persist updated values and validate. rlipimport_version1_save_mapping('user', $options, $data); $select = 'standardfieldname != customfieldname'; $count = $DB->count_records_select(RLIPIMPORT_VERSION1_MAPPING_TABLE, $select); $this->assertEquals($count, count($options)); // Reset and validate state. rlipimport_version1_reset_mappings('user'); $select = 'standardfieldname = customfieldname'; $count = $DB->count_records_select(RLIPIMPORT_VERSION1_MAPPING_TABLE, $select); $this->assertEquals($count, count($options)); }
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); } } } else { if ($form->is_cancelled()) { redirect($baseurl . "?tab={$tab}&cancelmessage=1", '', 0); } } //message handling $resetmessage = optional_param('resetmessage', 0, PARAM_INT);