/** * Returns description of method parameters * * @return external_function_parameters * @since Moodle 2.2 */ public static function create_users_parameters() { global $CFG; return new external_function_parameters(array('users' => new external_multiple_structure(new external_single_structure(array('username' => new external_value(core_user::get_property_type('username'), 'Username policy is defined in Moodle security config.'), 'password' => new external_value(core_user::get_property_type('password'), 'Plain text password consisting of any characters', VALUE_OPTIONAL), 'createpassword' => new external_value(PARAM_BOOL, 'True if password should be created and mailed to user.', VALUE_OPTIONAL), 'firstname' => new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user'), 'lastname' => new external_value(core_user::get_property_type('lastname'), 'The family name of the user'), 'email' => new external_value(core_user::get_property_type('email'), 'A valid and unique email address'), 'auth' => new external_value(core_user::get_property_type('auth'), 'Auth plugins include manual, ldap, imap, etc', VALUE_DEFAULT, 'manual', core_user::get_property_null('auth')), 'idnumber' => new external_value(core_user::get_property_type('idnumber'), 'An arbitrary ID code number perhaps from the institution', VALUE_DEFAULT, ''), 'lang' => new external_value(core_user::get_property_type('lang'), 'Language code such as "en", must exist on server', VALUE_DEFAULT, core_user::get_property_default('lang'), core_user::get_property_null('lang')), 'calendartype' => new external_value(core_user::get_property_type('calendartype'), 'Calendar type such as "gregorian", must exist on server', VALUE_DEFAULT, $CFG->calendartype, VALUE_OPTIONAL), 'theme' => new external_value(core_user::get_property_type('theme'), 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL), 'timezone' => new external_value(core_user::get_property_type('timezone'), 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL), 'mailformat' => new external_value(core_user::get_property_type('mailformat'), 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL), 'description' => new external_value(core_user::get_property_type('description'), 'User profile description, no HTML', VALUE_OPTIONAL), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_OPTIONAL), 'country' => new external_value(core_user::get_property_type('country'), 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL), 'firstnamephonetic' => new external_value(core_user::get_property_type('firstnamephonetic'), 'The first name(s) phonetically of the user', VALUE_OPTIONAL), 'lastnamephonetic' => new external_value(core_user::get_property_type('lastnamephonetic'), 'The family name phonetically of the user', VALUE_OPTIONAL), 'middlename' => new external_value(core_user::get_property_type('middlename'), 'The middle name of the user', VALUE_OPTIONAL), 'alternatename' => new external_value(core_user::get_property_type('alternatename'), 'The alternate name of the user', VALUE_OPTIONAL), 'preferences' => new external_multiple_structure(new external_single_structure(array('type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preference'), 'value' => new external_value(PARAM_RAW, 'The value of the preference'))), 'User preferences', VALUE_OPTIONAL), 'customfields' => new external_multiple_structure(new external_single_structure(array('type' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'), 'value' => new external_value(PARAM_RAW, 'The value of the custom field'))), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL)))))); }
/** * Test get_property_choices() method. */ public function test_get_property_choices() { // Test against country property choices. $choices = core_user::get_property_choices('country'); $this->assertArrayHasKey('AU', $choices); $this->assertArrayHasKey('BR', $choices); $this->assertArrayNotHasKey('WW', $choices); $this->assertArrayNotHasKey('TX', $choices); // Test against lang property choices. $choices = core_user::get_property_choices('lang'); $this->assertArrayHasKey('en', $choices); $this->assertArrayNotHasKey('ww', $choices); $this->assertArrayNotHasKey('yy', $choices); // Test against theme property choices. $choices = core_user::get_property_choices('theme'); $this->assertArrayHasKey('base', $choices); $this->assertArrayHasKey('clean', $choices); $this->assertArrayNotHasKey('unknowntheme', $choices); $this->assertArrayNotHasKey('wrongtheme', $choices); // Try to fetch type of a non-existent properties. $nonexistingproperty = 'language'; $this->expectException('coding_exception'); $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty); core_user::get_property_null($nonexistingproperty); $nonexistingproperty = 'coutries'; $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty); core_user::get_property_null($nonexistingproperty); }
/** * Test get_property_choices() method. */ public function test_get_property_choices() { // Test against country property choices. $choices = core_user::get_property_choices('country'); $this->assertArrayHasKey('AU', $choices); $this->assertArrayHasKey('BR', $choices); $this->assertArrayNotHasKey('WW', $choices); $this->assertArrayNotHasKey('TX', $choices); // Test against lang property choices. $choices = core_user::get_property_choices('lang'); $this->assertArrayHasKey('en', $choices); $this->assertArrayNotHasKey('ww', $choices); $this->assertArrayNotHasKey('yy', $choices); // Test against theme property choices. $choices = core_user::get_property_choices('theme'); $this->assertArrayHasKey('base', $choices); $this->assertArrayHasKey('clean', $choices); $this->assertArrayNotHasKey('unknowntheme', $choices); $this->assertArrayNotHasKey('wrongtheme', $choices); // Test against timezone property choices. $choices = core_user::get_property_choices('timezone'); $this->assertArrayHasKey('America/Sao_Paulo', $choices); $this->assertArrayHasKey('Australia/Perth', $choices); $this->assertArrayHasKey('99', $choices); $this->assertArrayHasKey('UTC', $choices); $this->assertArrayNotHasKey('North Korea', $choices); $this->assertArrayNotHasKey('New york', $choices); // Try to fetch type of a non-existent properties. $nonexistingproperty = 'language'; $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty); core_user::get_property_null($nonexistingproperty); $nonexistingproperty = 'coutries'; $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty); core_user::get_property_null($nonexistingproperty); }