MDL-45469 profile: make sure profile fields can be initialised without arguments

This commit is contained in:
Marina Glancy 2014-05-21 11:40:12 +08:00
parent 627a4619f5
commit 65ae0a1bde
2 changed files with 24 additions and 4 deletions

View File

@ -49,9 +49,13 @@ class profile_field_menu extends profile_field_base {
$this->profile_field_base($fieldid, $userid);
// Param 1 for menu type is the options.
$options = explode("\n", $this->field->param1);
if (isset($this->field->param1)) {
$options = explode("\n", $this->field->param1);
} else {
$options = array();
}
$this->options = array();
if ($this->field->required) {
if (!empty($this->field->required)) {
$this->options[''] = get_string('choose').'...';
}
foreach ($options as $key => $option) {

View File

@ -25,7 +25,6 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/user/profile/lib.php');
/**
* Unit tests for user/profile/lib.php.
@ -40,7 +39,8 @@ class core_user_profilelib_testcase extends advanced_testcase {
* with profile_user_record.
*/
public function test_get_custom_fields() {
global $DB;
global $DB, $CFG;
require_once($CFG->dirroot . '/user/profile/lib.php');
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
@ -85,4 +85,20 @@ class core_user_profilelib_testcase extends advanced_testcase {
// Check profile_user_record returns same field.
$this->assertEquals(array('frogname'), array_keys((array)profile_user_record($user->id)));
}
/**
* Make sure that all profile fields can be initialised without arguments.
*/
public function test_default_constructor() {
global $DB, $CFG;
require_once($CFG->dirroot . '/user/profile/definelib.php');
$datatypes = profile_list_datatypes();
foreach ($datatypes as $datatype => $datatypename) {
require_once($CFG->dirroot . '/user/profile/field/' .
$datatype . '/field.class.php');
$newfield = 'profile_field_' . $datatype;
$formfield = new $newfield();
$this->assertNotNull($formfield);
}
}
}