本文整理汇总了PHP中field::save方法的典型用法代码示例。如果您正苦于以下问题:PHP field::save方法的具体用法?PHP field::save怎么用?PHP field::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field
的用法示例。
在下文中一共展示了field::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_success
/**
* Test successful program delete
*/
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_PROGRAM;
$fieldctx->save();
// Create test program to delete.
$cur = new curriculum(array('idnumber' => 'testprogram', 'name' => 'testprogram'));
$cur->save();
$program = array('idnumber' => 'testprogram');
$this->give_permissions(array('local/elisprogram:program_delete'));
$response = local_datahub_elis_program_delete::program_delete($program);
$this->assertNotEmpty($response);
$this->assertInternalType('array', $response);
$this->assertArrayHasKey('messagecode', $response);
$this->assertArrayHasKey('message', $response);
$this->assertEquals(get_string('ws_program_delete_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_program_delete_success_msg', 'local_datahub'), $response['message']);
$this->assertFalse($DB->record_exists(curriculum::TABLE, array('idnumber' => 'testprogram')));
}
示例2: build_elis_field_data
/**
* Method to create ELIS field & owner objects given test data array.
*
* @param array $inputarray The test data array with params to build elis field object & owner
* input array format:
* array('field' => array(fieldparam => fieldparam_value [,...]),
* 'context' => contextlevel,
* 'manual' => array(fieldowners_manual_param => fomp_value [,...]),
* 'moodle_profile' => array(fieldowners_moodleprofile_param => fompp_value [,...]),
* )
* @return object The ELIS field object created
*/
public function build_elis_field_data($inputarray)
{
$field = new field((object) $inputarray['field']);
$field->save();
$fieldcontext = new field_contextlevel();
$fieldcontext->fieldid = $field->id;
$fieldcontext->contextlevel = $inputarray['context'];
$fieldcontext->save();
if (isset($inputarray['manual'])) {
$manual = new field_owner();
$manual->fieldid = $field->id;
$manual->plugin = 'manual';
foreach ($inputarray['manual'] as $key => $val) {
$manual->{'param_' . $key} = $val;
}
$manual->save();
}
if (isset($inputarray['moodle_profile'])) {
$moodleprofile = new field_owner();
$moodleprofile->fieldid = $field->id;
$moodleprofile->plugin = 'moodle_profile';
foreach ($inputarray['moodle_profile'] as $key => $val) {
$moodleprofile->{$key} = $val;
}
$moodleprofile->save();
}
$field->load();
// TDB.
return $field;
}
示例3: test_success
/**
* Test successful userset delete
*/
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_USERSET;
$fieldctx->save();
$this->give_permissions(array('local/elisprogram:userset_delete'));
$userset = array('name' => 'testuserset', 'recursive' => true);
// Setup userset to delete.
$us = new userset(array('name' => 'testuserset'));
$us->save();
$response = local_datahub_elis_userset_delete::userset_delete($userset);
$this->assertNotEmpty($response);
$this->assertInternalType('array', $response);
$this->assertArrayHasKey('messagecode', $response);
$this->assertArrayHasKey('message', $response);
$this->assertEquals(get_string('ws_userset_delete_success_code', 'local_datahub', get_string('ws_userset_delete_recursive', 'local_datahub')), $response['messagecode']);
$this->assertEquals(get_string('ws_userset_delete_success_msg', 'local_datahub', get_string('ws_userset_delete_subsets', 'local_datahub')), $response['message']);
}
示例4: test_success
/**
* Test successful course update.
*/
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_COURSE;
$fieldctx->save();
// Grant permissions.
$this->give_permissions(array('local/elisprogram:course_edit'));
// Create test program.
$datagen = new elis_program_datagenerator($DB);
$program = $datagen->create_program(array('idnumber' => 'TestProgram'));
// Create test course to update.
$crs = new course(array('idnumber' => 'TestCourse', 'name' => 'Test Course', 'syllabus' => ''));
$crs->save();
$course = array('idnumber' => 'TestCourse', 'name' => 'Test Course', 'code' => 'CRS1', 'syllabus' => 'Test syllabus', 'lengthdescription' => 'Weeks', 'length' => 2, 'credits' => 1.1, 'completion_grade' => 50, 'cost' => '$100', 'version' => '1.0.0', 'assignment' => $program->idnumber);
// Update test course.
$response = local_datahub_elis_course_update::course_update($course);
$this->assertNotEmpty($response);
$this->assertInternalType('array', $response);
$this->assertArrayHasKey('messagecode', $response);
$this->assertArrayHasKey('message', $response);
$this->assertArrayHasKey('record', $response);
$this->assertEquals(get_string('ws_course_update_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_course_update_success_msg', 'local_datahub'), $response['message']);
$this->assertInternalType('array', $response['record']);
$this->assertArrayHasKey('id', $response['record']);
// Get course.
$updatedcourse = new course($response['record']['id']);
$updatedcourse->load();
$updatedcourse = $updatedcourse->to_array();
foreach ($course as $param => $val) {
if ($param != 'assignment') {
$this->assertArrayHasKey($param, $updatedcourse);
$this->assertEquals($val, $updatedcourse[$param]);
}
}
// Check that course was assigned to program.
$curriculumcourseid = $DB->get_field(curriculumcourse::TABLE, 'id', array('curriculumid' => $program->id, 'courseid' => $response['record']['id']));
$this->assertNotEmpty($curriculumcourseid);
}
示例5: create_profile_field
/**
* Helper function for creating a Moodle user profile field
*
* @param string $name Profile field shortname
* @param string $datatype Profile field data type
* @param int $categoryid Profile field category id
* @return int The id of the created profile field
*/
private function create_profile_field($name, $datatype, $categoryid, $contextlevelname = 'user')
{
global $CFG;
require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php';
$file = get_plugin_directory('dhimport', 'version1elis') . '/lib.php';
require_once $file;
$field = new field(array('categoryid' => $categoryid, 'shortname' => $name, 'name' => $name));
$field->save();
// Field contextlevel.
$contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevelname);
$fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => $contextlevel));
$fieldcontextlevel->save();
return $field->id;
}
示例6: create_custom_field
/**
* Create the necessary custom field
*
* @return int The id of the created field
*/
private function create_custom_field()
{
global $CFG;
require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php';
require_once $CFG->dirroot . '/local/elisprogram/accesslib.php';
// Field category.
$fieldcategory = new field_category(array('name' => 'testcategoryname'));
$fieldcategory->save();
// Custom field.
$field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldshortname', 'name' => 'testfieldname', 'datatype' => 'bool'));
$field->save();
// Field context level assocation.
$fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER));
$fieldcontextlevel->save();
return $field->id;
}
示例7: test_success
/**
* Test successful user creation.
*/
public function test_success()
{
global $DB;
$this->give_permissions(array('local/elisprogram:class_edit'));
// 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_CLASS;
$fieldctx->save();
$course = new course();
$course->idnumber = 'testcourse1';
$course->name = 'Test Course 1';
$course->syllabus = 'Test';
$course->save();
$class = new pmclass(array('idnumber' => 'testclass', 'startdate' => 1357016400, 'enddate' => 1359694800, 'courseid' => $course->id, 'assignment' => $course->idnumber, 'field_testfield' => 'Test Field'));
$class->save();
$classupdates = array('idnumber' => 'testclass', 'startdate' => 'Feb/04/2013', 'enddate' => 'Mar/01/2013', 'field_testfield' => 'Test Field 2');
$response = local_datahub_elis_class_update::class_update($classupdates);
$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_update_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_class_update_success_msg', 'local_datahub'), $response['message']);
$this->assertInternalType('array', $response['record']);
$this->assertArrayHasKey('id', $response['record']);
// Get class.
$expectedclass = array('idnumber' => $class->idnumber, 'startdate' => rlip_timestamp(0, 0, 0, 2, 4, 2013), 'enddate' => rlip_timestamp(0, 0, 0, 3, 1, 2013), 'courseid' => $course->id, 'field_testfield' => 'Test Field 2');
$createdclass = new pmclass($response['record']['id']);
$createdclass->load();
$createdclass = $createdclass->to_array();
foreach ($expectedclass as $param => $val) {
$this->assertArrayHasKey($param, $createdclass);
$this->assertEquals($val, $createdclass[$param]);
}
}
示例8: init_required_data
/**
* Set up necessary data
*
* @param int $numfields The number of custom fields used in auto-association
*/
private function init_required_data($numfields = 1)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
require_once elis::lib('data/customfield.class.php');
require_once elispm::file('accesslib.php');
require_once elispm::lib('data/userset.class.php');
require_once $CFG->dirroot . '/user/profile/definelib.php';
require_once $CFG->dirroot . '/user/profile/field/checkbox/define.class.php';
// Set up the category only once.
$fieldcategory = new field_category(array('name' => 'testcategoryname'));
$fieldcategory->save();
// Ste up the target userset only once.
$userset = new userset(array('name' => 'testusersetname'));
$userset->save();
for ($i = 1; $i <= $numfields; $i++) {
// Custom field.
$field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldshortname' . $i, 'name' => 'testfieldname' . $i, 'datatype' => 'bool'));
$field->save();
// Ensure manual field owner exists for syncing.
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 = 'checkbox';
$owner->save();
// Ensure moodle profile field owner exists.
field_owner::ensure_field_owner_exists($field, 'moodle_profile');
$DB->execute("UPDATE {" . field_owner::TABLE . "} SET exclude = ?", array(pm_moodle_profile::sync_to_moodle));
// Field context level assocation.
$fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER));
$fieldcontextlevel->save();
// The associated Moodle user profile field.
$profiledefinecheckbox = new profile_define_checkbox();
$data = new stdClass();
$data->datatype = 'checkbox';
$data->categoryid = 99999;
$data->shortname = 'testfieldshortname' . $i;
$data->name = 'testfieldname' . $i;
$profiledefinecheckbox->define_save($data);
$mfield = $DB->get_record('user_info_field', array('shortname' => 'testfieldshortname' . $i));
// The "cluster-profile" association.
$usersetprofile = new userset_profile(array('clusterid' => $userset->id, 'fieldid' => $mfield->id, 'value' => 1));
$usersetprofile->save();
}
}
示例9: 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);
}
}
示例10: test_success
/**
* Test successful user edit.
* @dataProvider dataprovider_success
* @param array $update Incoming update data.
*/
public function test_success($update)
{
global $DB;
$this->give_permissions(array('local/elisprogram:user_edit'));
// 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');
$user = new user($user);
$user->save();
$expecteduser = (array) $DB->get_record(user::TABLE, array('id' => $user->id));
$expecteduser = array_merge($expecteduser, $update);
$response = local_datahub_elis_user_update::user_update($update);
// Verify general response structure.
$this->assertNotEmpty($response);
$this->assertInternalType('array', $response);
$this->assertArrayHasKey('messagecode', $response);
$this->assertArrayHasKey('message', $response);
$this->assertArrayHasKey('record', $response);
// Verify response message/code.
$this->assertEquals(get_string('ws_user_update_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_user_update_success_msg', 'local_datahub'), $response['message']);
// Verify returned user information.
$this->assertInternalType('array', $response['record']);
$this->assertArrayHasKey('id', $response['record']);
$actualuser = $DB->get_record(user::TABLE, array('id' => $response['record']['id']));
$this->assertNotEmpty($actualuser);
$actualuser = (array) $actualuser;
// Unset timemodified as it's unreliable to test.
unset($actualuser['timemodified']);
foreach ($actualuser as $param => $val) {
$this->assertEquals($expecteduser[$param], $val);
}
}
示例11: test_success
/**
* Test successful track update
*/
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_TRACK;
$fieldctx->save();
$this->give_permissions(array('local/elisprogram:track_edit'));
// Setup program and track.
$datagen = new elis_program_datagenerator($DB);
$program = $datagen->create_program(array('idnumber' => 'test_program_idnumber', 'name' => 'ProgramName'));
$track = $datagen->create_track(array('idnumber' => 'testtrack', 'name' => 'testtrackname', 'curid' => $program->id));
// Perform update.
$trackupdatedata = array('idnumber' => $track->idnumber, 'name' => 'testtrackname_changed', 'description' => 'testtrack description', 'field_testfield' => 'Test field');
$response = local_datahub_elis_track_update::track_update($trackupdatedata);
$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_update_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_track_update_success_msg', 'local_datahub'), $response['message']);
$this->assertInternalType('array', $response['record']);
$this->assertArrayHasKey('id', $response['record']);
// Get Track.
$updatedtrk = new track($response['record']['id']);
$updatedtrk->load();
$updatedtrk = $updatedtrk->to_array();
$expecttrk = array('id' => $response['record']['id'], 'idnumber' => 'testtrack', 'name' => 'testtrackname_changed', 'curid' => $program->id, 'description' => 'testtrack description', 'field_testfield' => 'Test field');
foreach ($expecttrk as $param => $val) {
$this->assertArrayHasKey($param, $updatedtrk);
$this->assertEquals($val, $updatedtrk[$param]);
}
}
示例12: test_success
/**
* Test successful userset update
*/
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_USERSET;
$fieldctx->save();
$this->give_permissions(array('local/elisprogram:userset_edit'));
$userset = array('name' => 'testuserset', 'display' => 'test userset description', 'parent' => 'top', 'field_testfield' => 'Test field');
// Setup userset to update.
$us = new userset(array('name' => 'testuserset'));
$us->save();
$response = local_datahub_elis_userset_update::userset_update($userset);
$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_update_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_userset_update_success_msg', 'local_datahub'), $response['message']);
$this->assertInternalType('array', $response['record']);
$this->assertArrayHasKey('id', $response['record']);
// Get Userset.
$updatedus = new userset($response['record']['id']);
$updatedus->load();
$updatedus = $updatedus->to_array();
$expectus = array('id' => $response['record']['id'], 'name' => 'testuserset', 'display' => 'test userset description', 'parent' => 0, 'field_testfield' => 'Test field');
foreach ($expectus as $param => $val) {
$this->assertArrayHasKey($param, $updatedus);
$this->assertEquals($val, $updatedus[$param]);
}
}
示例13: test_success
/**
* Test successful program update
*/
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_PROGRAM;
$fieldctx->save();
// Create test program to update.
$datagen = new elis_program_datagenerator($DB);
$program = $datagen->create_program(array('idnumber' => 'testprogram', 'name' => 'testprogram'));
$program = array('idnumber' => 'testprogram', 'name' => 'newtestprogramname', 'reqcredits' => 4.5, 'timetocomplete' => '6m', 'frequency' => '1y', 'field_testfield' => 'Test Field');
$this->give_permissions(array('local/elisprogram:program_edit'));
$response = local_datahub_elis_program_update::program_update($program);
$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_update_success_code', 'local_datahub'), $response['messagecode']);
$this->assertEquals(get_string('ws_program_update_success_msg', 'local_datahub'), $response['message']);
$this->assertInternalType('array', $response['record']);
$this->assertArrayHasKey('id', $response['record']);
// Get Program.
$createdprg = new curriculum($response['record']['id']);
$createdprg->load();
$createdprg = $createdprg->to_array();
foreach ($program as $param => $val) {
$this->assertArrayHasKey($param, $createdprg);
$this->assertEquals($val, $createdprg[$param]);
}
}
示例14: 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]);
}
}
示例15: create_test_field
/**
* Create the test custom profile field, category and owner
*
* @param string $contextlevelname The name of the custom context level to create the field at
* @param string $datatype The string identifier of the data type to use
* @param string $uitype The string identifier of the UI / control type to use
* @param boolean $multivalued Set to true to make field multivalued, otherwise false
* @param mixed $options Array of menu options, or null for none
* @param int $maxlength The maximum data length, or null for none
* @return int The id of the created field
*/
private function create_test_field($contextlevelname, $datatype, $uitype, $multivalued, $options, $maxlength, $inctime)
{
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::lib('data/customfield.class.php');
// Category.
$fieldcategory = new field_category(array('name' => 'testcategoryname'));
$fieldcategory->save();
// Category contextlevel.
$contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevelname);
$fieldcategorycontextlevel = new field_category_contextlevel(array('categoryid' => $fieldcategory->id, 'contextlevel' => $contextlevel));
$fieldcategorycontextlevel->save();
// Field.
$field = new field(array('shortname' => 'testfieldshortname', 'name' => 'testfieldname', 'categoryid' => $fieldcategory->id, 'datatype' => $datatype));
if ($multivalued) {
// Enable multivalued ability.
$field->multivalued = true;
}
$field->save();
// Field contextlevel.
$fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => $contextlevel));
$fieldcontextlevel->save();
// Field owner.
$ownerdata = array('control' => $uitype);
if ($options !== null) {
// Set options.
$ownerdata['options'] = implode("\n", $options);
}
if ($maxlength !== null) {
// Set max length.
$ownerdata['maxlength'] = $maxlength;
}
if ($inctime !== null) {
$ownerdata['inctime'] = $inctime;
}
field_owner::ensure_field_owner_exists($field, 'manual', $ownerdata);
return $field->id;
}