Exemplo n.º 1
0
 /**
  * Test get_property_definition() method.
  */
 public function test_get_property_definition()
 {
     // Try to get a existing property.
     $properties = core_user::get_property_definition('id');
     $this->assertEquals($properties['type'], PARAM_INT);
     $properties = core_user::get_property_definition('username');
     $this->assertEquals($properties['type'], PARAM_USERNAME);
     // Invalid property.
     try {
         core_user::get_property_definition('fullname');
     } catch (coding_exception $e) {
         $this->assertRegExp('/Invalid property requested./', $e->getMessage());
     }
     // Empty parameter.
     try {
         core_user::get_property_definition('');
     } catch (coding_exception $e) {
         $this->assertRegExp('/Invalid property requested./', $e->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * Clean the user data that comes from an external database.
  *
  * @param array $user the user data to be validated against properties definition.
  * @return stdClass $user the cleaned user data.
  */
 public function clean_data($user)
 {
     if (empty($user)) {
         return $user;
     }
     foreach ($user as $field => $value) {
         // Get the property parameter type and do the cleaning.
         try {
             $property = core_user::get_property_definition($field);
             $user->{$field} = clean_param($value, $property['type']);
         } catch (coding_exception $e) {
             debugging("The property '{$field}' could not be cleaned.", DEBUG_DEVELOPER);
         }
     }
     return $user;
 }