Merge branch 'wip-MDL-40356-master' of git://github.com/abgreeve/moodle

This commit is contained in:
Dan Poltawski
2014-09-22 15:02:51 +01:00
4 changed files with 39 additions and 2 deletions
+13 -2
View File
@@ -3602,11 +3602,22 @@ function fullname($user, $override=false) {
if (isset($CFG->fullnamedisplay)) {
$template = $CFG->fullnamedisplay;
}
// If the template is empty, or set to language, or $override is set, return the language string.
if (empty($template) || $template == 'language' || $override) {
// If the template is empty, or set to language, return the language string.
if ((empty($template) || $template == 'language') && !$override) {
return get_string('fullnamedisplay', null, $user);
}
// Check to see if we are displaying according to the alternative full name format.
if ($override) {
if (empty($CFG->alternativefullnameformat) || $CFG->alternativefullnameformat == 'language') {
// Default to show just the user names according to the fullnamedisplay string.
return get_string('fullnamedisplay', null, $user);
} else {
// If the override is true, then change the template to use the complete name.
$template = $CFG->alternativefullnameformat;
}
}
$requirednames = array();
// With each name, see if it is in the display name template, and add it to the required names array if it is.
foreach ($allnames as $allname) {
+21
View File
@@ -2321,6 +2321,7 @@ class core_moodlelib_testcase extends advanced_testcase {
// Back up config settings for restore later.
$originalcfg = new stdClass();
$originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
$originalcfg->alternativefullnameformat = $CFG->alternativefullnameformat;
// Testing existing fullnamedisplay settings.
$CFG->fullnamedisplay = 'firstname';
@@ -2348,6 +2349,25 @@ class core_moodlelib_testcase extends advanced_testcase {
$testname = fullname($user, true);
$this->assertSame($expectedname, $testname);
// Test alternativefullnameformat setting.
// Test alternativefullnameformat that has been set to nothing.
$CFG->alternativefullnameformat = '';
$expectedname = "$user->firstname $user->lastname";
$testname = fullname($user, true);
$this->assertSame($expectedname, $testname);
// Test alternativefullnameformat that has been set to 'language'.
$CFG->alternativefullnameformat = 'language';
$expectedname = "$user->firstname $user->lastname";
$testname = fullname($user, true);
$this->assertSame($expectedname, $testname);
// Test customising the alternativefullnameformat setting with all additional name fields.
$CFG->alternativefullnameformat = 'firstname lastname firstnamephonetic lastnamephonetic middlename alternatename';
$expectedname = "$user->firstname $user->lastname $user->firstnamephonetic $user->lastnamephonetic $user->middlename $user->alternatename";
$testname = fullname($user, true);
$this->assertSame($expectedname, $testname);
// Test additional name fields.
$CFG->fullnamedisplay = 'lastname lastnamephonetic firstname firstnamephonetic';
$expectedname = "$user->lastname $user->lastnamephonetic $user->firstname $user->firstnamephonetic";
@@ -2428,6 +2448,7 @@ class core_moodlelib_testcase extends advanced_testcase {
// Tidy up after we finish testing.
$CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
$CFG->alternativefullnameformat = $originalcfg->alternativefullnameformat;
}
public function test_get_all_user_name_fields() {