本文整理汇总了PHP中user::reset_custom_field_list方法的典型用法代码示例。如果您正苦于以下问题:PHP user::reset_custom_field_list方法的具体用法?PHP user::reset_custom_field_list怎么用?PHP user::reset_custom_field_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user
的用法示例。
在下文中一共展示了user::reset_custom_field_list方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_syncpmuserfieldtodeletedmoodleprofilefield
/**
* Test sync-ing an ELIS User Profile field to a DELETED Moodle User Profile field
*/
public function test_syncpmuserfieldtodeletedmoodleprofilefield()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/definelib.php';
$this->load_csv_data();
// Set PM Custom User field(s) to Sync to Moodle.
$ctxlvl = CONTEXT_ELIS_USER;
$fields = field::get_for_context_level($ctxlvl);
foreach ($fields as $field) {
$fieldobj = new field($field);
if (!isset($fieldobj->owners['moodle_profile'])) {
$fieldobj->owners['moodle_profile'] = new stdClass();
}
$owner = new field_owner($fieldobj->owners['moodle_profile']);
$owner->exclude = pm_moodle_profile::sync_from_moodle;
$owner->save();
$fieldobj->save();
}
// Read a record.
$src = new user(103, null, array(), false, array());
$src->reset_custom_field_list();
// Modify the data.
$src->firstname = 'Testuser';
$src->lastname = 'One';
$src->field_sometext = 'boo';
$src->field_sometextfrompm = 'bla';
$src->save();
// Delete some custom Moodle Profile field(s) to cause old error (pre ELIS-4499).
$fields = field::get_for_context_level($ctxlvl);
foreach ($fields as $field) {
$fieldobj = new field($field);
if ($moodlefield = $DB->get_record('user_info_field', array('shortname' => $fieldobj->shortname))) {
profile_delete_field($moodlefield->id);
}
}
// Run the library sync - throws errors not exceptions :(.
$CFG->mnet_localhost_id = 1;
// ???
$mu = cm_get_moodleuser(103);
try {
$result = pm_moodle_user_to_pm($mu);
$this->assertTrue($result);
} catch (Exception $ex) {
$this->assertTrue(false, $ex->message);
}
}
示例2: test_success
/**
* Test successful user creation.
*/
public function test_success()
{
global $DB;
// 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_USER;
$fieldctx->save();
$user = array('idnumber' => 'testuser', 'username' => 'testuser', 'firstname' => 'testuser', 'lastname' => 'testuser', 'email' => 'testuser@example.com', 'country' => 'CA', 'field_testfield' => 'Test Field');
$tempuser = new user();
$tempuser->reset_custom_field_list();
$this->give_permissions(array('local/elisprogram:user_create'));
$response = local_datahub_elis_user_create::user_create($user);
$this->assertNotEmpty($response);
$this->assertInternalType('array', $response);
$this->assertArrayHasKey('messagecode', $response);
$this->assertArrayHasKey('message', $response);
$this->assertArrayHasKey('record', $response);
$this->assertEquals(get_string('ws_user_create_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_user_create_success_msg', 'local_datahub'), $response['message']);
$this->assertInternalType('array', $response['record']);
$this->assertArrayHasKey('id', $response['record']);
// Get user.
$createduser = new user($response['record']['id']);
$createduser->load();
$createduser = $createduser->to_array();
foreach ($user as $param => $val) {
$this->assertArrayHasKey($param, $createduser);
$this->assertEquals($val, $createduser[$param]);
}
}
示例3: test_modifyingmoodleuserupdatespmuser
/**
* Test that modifying a Moodle user also updates the corresponding PM user.
*/
public function test_modifyingmoodleuserupdatespmuser()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/admin/tool/uploaduser/locallib.php';
$this->load_csv_data();
// Update a record.
$src = new stdClass();
$src->id = 100;
$src->firstname = 'Testuser';
$src->lastname = 'One';
$src->profile_field_sometext = 'boo';
$src->profile_field_sometextfrompm = 'bla';
$DB->update_record('user', $src);
$mdluser = $DB->get_record('user', array('id' => 100));
$mcopy = clone $src;
$mcopy = uu_pre_process_custom_profile_data($mcopy);
profile_save_data($mcopy);
events_trigger('user_updated', $mdluser);
// Read the PM user and compare.
$retr = new user(103, null, array(), false, array());
$retr->reset_custom_field_list();
$this->assertEquals($mdluser->firstname, $retr->firstname);
$this->assertEquals($mdluser->lastname, $retr->lastname);
// Check custom fields.
$result = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet();
$result->addTable(new moodle_recordset_phpunit_datatable(field_data_int::TABLE, $DB->get_recordset(field_data_int::TABLE, null, '', 'contextid, fieldid, data')));
$result->addTable(new moodle_recordset_phpunit_datatable(field_data_char::TABLE, $DB->get_recordset(field_data_char::TABLE, null, '', 'contextid, fieldid, data')));
$result->addTable(new moodle_recordset_phpunit_datatable(field_data_text::TABLE, $DB->get_recordset(field_data_text::TABLE, null, '', 'contextid, fieldid, data')));
$usercontext = \local_elisprogram\context\user::instance(103);
$dataset = new PHPUnit_Extensions_Database_DataSet_CsvDataSet();
$dataset->addTable(field_data_int::TABLE, elispm::file('tests/fixtures/user_field_data_int.csv'));
$dataset->addTable(field_data_char::TABLE, elispm::file('tests/fixtures/user_field_data_char.csv'));
$dataset->addTable(field_data_text::TABLE, elispm::file('tests/fixtures/user_field_data_text.csv'));
$dataset = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($dataset);
$dataset->addFullReplacement('##USERCTXID##', $usercontext->id);
$dataset->addFullReplacement('##USERCTXLVL##', CONTEXT_ELIS_USER);
// Only the first text field should be changed; everything else should be the same.
$dataset->addFullReplacement('First text entry field', $src->profile_field_sometext);
$ret = $dataset->addFullReplacement('Second text entry field', $src->profile_field_sometextfrompm);
$this->assertDataSetsEqual($dataset, $result);
}
示例4: test_elis_user_update_triggers_group_and_grouping_setup
/**
* 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();
}
示例5: test_mapping_applied_during_user_update
/**
* Validate that mappings are applied during the user update action
*/
public function test_mapping_applied_during_user_update()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php';
require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
$this->init_mapping();
$customfieldid = $this->create_custom_field();
// Clear the cached custom field list.
$usertoclearcustomfieldlist = new user();
$usertoclearcustomfieldlist->reset_custom_field_list();
$user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'testuser@email.com', 'country' => 'CA'));
$user->save();
// Run the user update action.
$record = new stdClass();
$record->customaction = 'update';
$record->customusername = 'testuserusername';
$record->custompassword = 'updatedTestpassword!0';
$record->customidnumber = 'testuseridnumber';
$record->customfirstname = 'updatedtestuserfirstname';
$record->customlastname = 'updatedtestuserlastname';
$record->custommi = 'updatedtestusermi';
$record->customemail = 'testuser@email.com';
$record->customemail2 = 'updatedtestuser@email2.com';
$record->customaddress = 'updatedtestuseraddress';
$record->customaddress2 = 'updatedtestuseraddress2';
$record->customcity = 'updatedtestusercity';
$record->customstate = 'updatedtestuserstate';
$record->custompostalcode = 'updatedtestuserpostalcode';
$record->customcountry = 'FR';
$record->customphone = 'updatedtestuserphone';
$record->customphone2 = 'updatedtestuserphone2';
$record->customfax = 'updatedtestuserfax';
$record->custombirthdate = 'Jan/02/2012';
$record->customgender = 'F';
$record->customlanguage = 'fr';
$record->customtransfercredits = '2';
$record->customcomments = 'updatedtestusercomments';
$record->customnotes = 'updatedtestusernotes';
$record->custominactive = '1';
$record->customtestfieldshortname = '1';
$this->run_user_import((array) $record);
// Validation.
$data = array('username' => 'testuserusername', 'idnumber' => 'testuseridnumber', 'firstname' => 'updatedtestuserfirstname', 'lastname' => 'updatedtestuserlastname', 'mi' => 'updatedtestusermi', 'email' => 'testuser@email.com', 'email2' => 'updatedtestuser@email2.com', 'address' => 'updatedtestuseraddress', 'address2' => 'updatedtestuseraddress2', 'city' => 'updatedtestusercity', 'state' => 'updatedtestuserstate', 'postalcode' => 'updatedtestuserpostalcode', 'country' => 'FR', 'phone' => 'updatedtestuserphone', 'phone2' => 'updatedtestuserphone2', 'fax' => 'updatedtestuserfax', 'birthdate' => '2012/01/02', 'gender' => 'F', 'language' => 'fr', 'transfercredits' => 2, 'inactive' => 1);
$this->assertTrue($DB->record_exists(user::TABLE, $data));
// Validate password.
$userrec = $DB->get_record('user', array('username' => $data['username']));
$this->assertTrue(validate_internal_user_password($userrec, 'updatedTestpassword!0'));
$record = $DB->get_record(user::TABLE, array('username' => 'testuserusername'));
$this->assertEquals('updatedtestusercomments', $record->comments);
$this->assertEquals('updatedtestusernotes', $record->notes);
$instance = \local_elisprogram\context\user::instance(1);
$this->assertTrue($DB->record_exists(field_data_int::TABLE, array('fieldid' => $customfieldid, 'contextid' => $instance->id, 'data' => 1)));
}
示例6: test_class_completion_sends_class_completed_notification_on_enrolment_create
/**
* Validating that enrolling a user in a class instance with a passed status triggers the class
* completed notification
*
* @param int $completestatus The completion status to enrol the user with
* @param boolean $expectmessage Whether we expect the notification message to be sent
* @dataProvider enrolment_completion_on_create_provider
*/
public function test_class_completion_sends_class_completed_notification_on_enrolment_create($completestatus, $expectmessage)
{
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/pmclass.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_classcompleted_user', 1, 'local_elisprogram');
$message = '%%userenrolname%% has completed the class instance %%classname%%.';
set_config('notify_classcompleted_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' => 'test@user.com', 'country' => 'CA'));
$user->reset_custom_field_list();
$user->save();
$course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
$course->reset_custom_field_list();
$course->save();
$class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
$class->reset_custom_field_list();
$class->save();
// Run the enrolment create action.
$record = new stdClass();
$record->context = 'class_testclassidnumber';
$record->user_username = 'testuserusername';
$record->completestatusid = $completestatus;
$importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
$importplugin->fslogger = new silent_fslogger(null);
$sink = $this->redirectEmails();
$importplugin->class_enrolment_create($record, 'bogus', 'testclassidnumber');
if ($completestatus !== student::STUSTATUS_NOTCOMPLETE) {
$this->assertEquals(1, count($sink->get_messages()));
} else {
$this->assertEquals(0, count($sink->get_messages()));
}
$sink->close();
// Validation.
$mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
$expectedmessage = "{$user->firstname} {$user->lastname} has completed the class instance {$course->name}.";
$like = $DB->sql_like('fullmessagehtml', ':message');
$select = "useridto = :userid\n AND {$like}";
if ($expectmessage) {
$this->assertTrue($DB->record_exists_select('message', $select, array('userid' => $mdluserid, 'message' => "{$expectedmessage}%")));
} else {
$this->assertFalse($DB->record_exists_select('message', $select, array('userid' => $mdluserid, 'message' => "{$expectedmessage}%")));
}
}
示例7: testmenuofchoicesignorescarriagereturns
/**
* Validate that the "menu of choices" custom field type works correctly
* when options are separated by a carriage return and a line feed
*/
public function testmenuofchoicesignorescarriagereturns()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::lib('data/customfield.class.php');
require_once elispm::file('accesslib.php');
require_once elispm::lib('data/user.class.php');
// Setup.
$field = new field(array('shortname' => 'testcustomfieldshortname', 'name' => 'testcustomfieldname', 'datatype' => 'char'));
$category = new field_category(array('name' => 'testcategoryname'));
field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USER, $category);
$ownerparams = array('control' => 'menu', 'options' => "option1\r\noption2");
field_owner::ensure_field_owner_exists($field, 'manual', $ownerparams);
// Run the create action.
$record = new stdClass();
$record->action = 'create';
$record->email = 'testuser@mail.com';
$record->username = 'testuser';
$record->idnumber = 'testuserid';
$record->firstname = 'testuserfirstname';
$record->lastname = 'testuserlastname';
$record->country = 'CA';
$record->testcustomfieldshortname = 'option1';
$user = new user();
$user->reset_custom_field_list();
$importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
$importplugin->fslogger = new silent_fslogger(null);
$importplugin->process_record('user', (object) $record, 'bogus');
// Validation.
$user = new user(1);
$user->load();
$this->assertEquals('option1', $user->field_testcustomfieldshortname);
}
示例8: test_user_multi_custom_field_on_user_create
/**
* Validate that custom user fields are synched over to Moodle when PM user is created
* during an import
*/
public function test_user_multi_custom_field_on_user_create()
{
global $CFG, $DB, $USER;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::lib('data/customfield.class.php');
require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
require_once elispm::file('accesslib.php');
require_once elispm::lib('data/user.class.php');
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/profile/definelib.php';
require_once $CFG->dirroot . '/user/profile/field/menu/define.class.php';
$CFG->filterall = true;
$USER = get_admin();
$context = context_user::instance($USER->id);
/*
$filternames = filter_get_all_installed();
ob_start();
var_dump($filternames);
$tmp = ob_get_contents();
ob_end_clean();
error_log("test_user_multi_custom_field_on_user_create: all-filters => {$tmp}");
*/
// Note: >= m25 filter paths no longer prefixed with 'filter/'
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
$multilangoption1 = '<span class="multilang" lang="en">Male</span><span class="multilang" lang="pt_br">Masculino</span>' . '<span class="multilang" lang="es">Masculino</span>';
$multilangoption2 = '<span class="multilang" lang="en">Female</span><span class="multilang" lang="pt_br">Feminino</span>' . '<span class="multilang" lang="es">Femenino</span>';
// The associated Moodle user profile field.
$profiledefinemenu = new profile_define_menu();
$data = new stdClass();
$data->datatype = 'menu';
$data->categoryid = 99999;
$data->shortname = 'testfieldgender';
$data->name = 'testfieldgender';
$data->param1 = "{$multilangoption1}\n{$multilangoption2}";
$data->defaultdata = $multilangoption2;
$profiledefinemenu->define_save($data);
// Reset cached custom fields.
$user = new user();
$user->reset_custom_field_list();
// Field category.
$fieldcategory = new field_category(array('name' => 'testcategoryname'));
$fieldcategory->save();
// Custom field.
$field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldgender', 'name' => 'testfieldgender', 'datatype' => 'text', 'multivalued' => 1));
$field->save();
// Field owners
field_owner::ensure_field_owner_exists($field, 'moodle_profile');
$manualowneroptions = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'menu', 'options' => "{$multilangoption1}\n{$multilangoption2}");
field_owner::ensure_field_owner_exists($field, 'manual', $manualowneroptions);
// Field context level assocation.
$fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER));
$fieldcontextlevel->save();
// Run the user create action.
$record = new stdClass();
$record->action = 'create';
$record->idnumber = 'testuseridnumber';
$record->username = 'testuserusername';
$record->firstname = 'testuserfirstname';
$record->lastname = 'testuserlastname';
$record->email = 'testuser@email.com';
$record->address = 'testuseraddress';
$record->city = 'testusercity';
$record->country = 'CA';
$record->language = 'en';
$record->testfieldgender = 'Male/Female';
$importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
$importplugin->fslogger = new silent_fslogger(null);
$importplugin->process_record('user', $record, 'bogus');
// Validation.
$userid = $DB->get_field(user::TABLE, 'id', array('username' => 'testuserusername'));
$user = new user($userid);
$user->load();
$user = $user->to_object();
/*
$datars = field_data::get_for_context_and_field(\local_elisprogram\context\user::instance($user->id), 'testfieldgender');
foreach ($datars as $data) {
ob_start();
var_dump($data);
$tmp = ob_get_contents();
ob_end_clean();
error_log("test_user_multi_custom_field_on_user_create: data => {$tmp}");
}
*/
/*
ob_start();
var_dump($user);
$tmp = ob_get_contents();
ob_end_clean();
error_log("test_user_multi_custom_field_on_user_create: user => {$tmp}");
*/
$this->assertEquals(array($multilangoption1, $multilangoption2), $user->field_testfieldgender);
}
示例9: test_update_elis_user_instructor_enrolment_with_minimal_fields
/**
* Validate that an "instructor" assignment can be updated with a minimal set of fields specified
*
* @param string $fieldname The name of the one import field we are setting
* @param string $value The value to set for that import field
* @param string $dbvalue The equivalent back-end database value
* @dataProvider minimal_update_field_provider
*/
public function test_update_elis_user_instructor_enrolment_with_minimal_fields($fieldname, $value, $dbvalue)
{
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/pmclass.class.php');
require_once elispm::lib('data/instructor.class.php');
require_once elispm::lib('data/user.class.php');
$dbvalue = rlip_timestamp($dbvalue[0], $dbvalue[1], $dbvalue[2], $dbvalue[3], $dbvalue[4], $dbvalue[5]);
$user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'testuser@email.com', 'country' => 'CA'));
$user->reset_custom_field_list();
$user->save();
$course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
$course->save();
$class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
$class->save();
$instructor = new instructor(array('userid' => $user->id, 'classid' => $class->id));
$instructor->save();
// Validate setup.
$this->assertTrue($DB->record_exists(instructor::TABLE, array('userid' => $user->id, 'classid' => $class->id)));
// Run the instructor assignment update action.
$record = new stdClass();
$record->context = 'class_testclassidnumber';
$record->user_username = 'testuserusername';
$record->{$fieldname} = $value;
$record->role = 'instructor';
$importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
$importplugin->fslogger = new silent_fslogger(null);
$importplugin->class_enrolment_update($record, 'bogus', 'testclassidnumber');
// Validation.
$this->assertTrue($DB->record_exists(instructor::TABLE, array('userid' => $user->id, 'classid' => $class->id, $fieldname => $dbvalue)));
}
示例10: set_up_elis_custom_field
/**
* Set up an ELIS custom field from a Moodle custom field.
* @param object $mfield The moodle custom field object to use as reference.
* @param field_category $cat The ELIS custom field category to put the field in.
* @return field The created ELIS custom field.
*/
protected function set_up_elis_custom_field($mfield, field_category $cat)
{
if (empty($cat)) {
$cat = $this->set_up_elis_field_category();
}
$user = new user();
$user->reset_custom_field_list();
$field = new field();
$field->shortname = $mfield->shortname;
$field->name = $mfield->name;
$field->datatype = $mfield->datatype;
field::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USER, $cat);
$owner = new field_owner();
$owner->fieldid = $field->id;
$owner->plugin = 'manual';
$owner->params = serialize(array('required' => false, 'edit_capability' => '', 'view_capability' => '', 'control' => 'text', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'startyear' => '1970', 'stopyear' => '2038', 'inctime' => '0'));
$owner->save();
$owner = new field_owner();
$owner->fieldid = $field->id;
$owner->plugin = 'moodle_profile';
$owner->exclude = pm_moodle_profile::sync_to_moodle;
$owner->save();
return $field;
}
示例11: test_version1importsyncsusertoelisonupdate
/**
* Validate that the import performs user synchronization on user update
*/
public function test_version1importsyncsusertoelisonupdate()
{
global $CFG, $DB;
if (!file_exists($CFG->dirroot . '/local/elisprogram/lib/setup.php')) {
$this->markTestIncomplete('This test depends on the PM system');
}
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once $CFG->dirroot . '/user/profile/definelib.php';
require_once elis::lib('data/customfield.class.php');
require_once elispm::lib('data/user.class.php');
// Make sure we are not auto-assigning idnumbers.
set_config('auto_assign_user_idnumber', 0, 'local_elisprogram');
elis::$config = new elis_config();
// Create Moodle custom field category.
$category = new stdClass();
$category->sortorder = $DB->count_records('user_info_category') + 1;
$category->id = $DB->insert_record('user_info_category', $category);
// Create Moodle custom profile field.
$this->create_profile_field('rliptext', 'text', $category->id);
// Obtain the PM user context level.
$contextlevel = CONTEXT_ELIS_USER;
// Make sure the PM category and field exist.
$category = new field_category(array('name' => 'rlipcategory'));
$field = new field(array('shortname' => 'rliptext', 'name' => 'rliptext', 'datatype' => 'text', 'multivalued' => 0));
$field = field::ensure_field_exists_for_context_level($field, $contextlevel, $category);
// Make sure the field owner is setup.
field_owner::ensure_field_owner_exists($field, 'manual');
$ownerid = $DB->get_field(field_owner::TABLE, 'id', array('fieldid' => $field->id, 'plugin' => 'manual'));
$owner = new field_owner($ownerid);
$owner->param_control = 'text';
$owner->save();
// Make sure the field is set up for synchronization.
field_owner::ensure_field_owner_exists($field, 'moodle_profile');
$ownerid = $DB->get_field(field_owner::TABLE, 'id', array('fieldid' => $field->id, 'plugin' => 'moodle_profile'));
$owner = new field_owner($ownerid);
$owner->exclude = pm_moodle_profile::sync_from_moodle;
$owner->save();
// Update the user class's static cache of define user custom fields.
$tempuser = new user();
$tempuser->reset_custom_field_list();
// Create the user.
$this->run_core_user_import(array('idnumber' => 'rlipidnumber', 'profile_field_rliptext' => 'rliptext'));
// Make sure PM user was created correctly.
$this->assert_record_exists(user::TABLE, array('username' => 'rlipusername', 'idnumber' => 'rlipidnumber'));
// Run the import, updating the user.
$this->run_core_user_import(array('action' => 'update', 'username' => 'rlipusername', 'profile_field_rliptext' => 'rliptextupdated'));
// Make sure the PM custom field data was set.
$sql = "SELECT 'x'\n FROM {" . field::TABLE . "} f\n JOIN {" . field_data_text::TABLE . "} d ON f.id = d.fieldid\n WHERE f.shortname = ? AND d.data = ?";
$params = array('rliptext', 'rliptextupdated');
$exists = $DB->record_exists_sql($sql, $params);
$this->assertEquals($exists, true);
}
示例12: test_multivalue_field_data_supports_all_data_types_for_menu_of_choices
/**
* Validate that multivalue functionality is suppored for all data types when using the
* "menu of choices" UI / input type
*
* @dataProvider data_type_provider
* @param string $uitype The string value representing a data type
* @param string $data The multi-valued custom field value to use as input
* @param array $expected The values to expect in the databaes
*/
public function test_multivalue_field_data_supports_all_data_types_for_menu_of_choices($datatype, $data, $expected)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::lib('data/customfield.class.php');
require_once elispm::lib('data/user.class.php');
// Set up the custom field, category, context association, and owner.
// Use "expected" as list of available options.
$fieldid = $this->create_test_field('user', $datatype, 'menu', true, $expected, null, null);
// Reset the field list.
$temp = new user();
$temp->reset_custom_field_list();
// Run the entity create action.
$record = array('action' => 'create', 'idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'password' => 'testuserpassword', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'test@useremail.com', 'city' => 'testusercity', 'country' => 'CA', 'testfieldshortname' => $data);
$importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
$importplugin->fslogger = new silent_fslogger(null);
$importplugin->process_record('user', (object) $record, 'bogus');
// Validation.
$instance = new field(array('datatype' => $datatype));
$realtype = $instance->data_type();
$realdataclass = "field_data_{$realtype}";
$this->assert_field_values('user', user::TABLE, $realdataclass::TABLE, $fieldid, $expected);
}
示例13: test_user_update_triggers_group_setup
/**
* Validate that updating users triggers group functionality
*/
public function test_user_update_triggers_group_setup()
{
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
$this->set_up_required_data(false, true, true, true);
// Run the user update action.
$record = new stdClass();
$record->action = 'update';
$record->username = 'testuserusername';
$record->email = 'test@useremail.com';
$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);
$importplugin->process_record('user', $record, 'bogus');
$this->validate_end_result();
}