mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-57840 libraries: Fixed missing fields in get_users_by_field().
This commit is contained in:
parent
9ec952f237
commit
b80caca188
@ -554,6 +554,15 @@ function user_get_user_details($user, $course = null, array $userfields = array(
|
||||
$userdetails['preferences'] = $preferences;
|
||||
}
|
||||
|
||||
if ($currentuser or has_capability('moodle/user:viewalldetails', $context)) {
|
||||
$extrafields = ['auth', 'confirmed', 'lang', 'theme', 'timezone', 'mailformat'];
|
||||
foreach ($extrafields as $extrafield) {
|
||||
if (in_array($extrafield, $userfields) && isset($user->$extrafield)) {
|
||||
$userdetails[$extrafield] = $user->$extrafield;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $userdetails;
|
||||
}
|
||||
|
||||
|
@ -624,4 +624,34 @@ class core_userliblib_testcase extends advanced_testcase {
|
||||
$this->expectException('moodle_exception');
|
||||
$result = user_get_user_details($student, $course1, array('wrongrequiredfield'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for MDL-57840.
|
||||
*
|
||||
* Ensure the fields "auth, confirmed, idnumber, lang, theme, timezone and mailformat" are present when
|
||||
* calling user_get_user_details() function.
|
||||
*/
|
||||
public function test_user_get_user_details_missing_fields() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser(); // We need capabilities to view the data.
|
||||
$user = self::getDataGenerator()->create_user([
|
||||
'auth' => 'auth_something',
|
||||
'confirmed' => '0',
|
||||
'idnumber' => 'someidnumber',
|
||||
'lang' => 'en_ar',
|
||||
'theme' => 'mytheme',
|
||||
'timezone' => '50',
|
||||
'mailformat' => '0',
|
||||
]);
|
||||
|
||||
// Fields that should get by default.
|
||||
$got = user_get_user_details($user);
|
||||
self::assertSame('auth_something', $got['auth']);
|
||||
self::assertSame('0', $got['confirmed']);
|
||||
self::assertSame('someidnumber', $got['idnumber']);
|
||||
self::assertSame('en_ar', $got['lang']);
|
||||
self::assertSame('mytheme', $got['theme']);
|
||||
self::assertSame('50', $got['timezone']);
|
||||
self::assertSame('0', $got['mailformat']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user