mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-40356 lib: Unit tests for the alternativefullnameformat setting.
This commit is contained in:
parent
ea6f548081
commit
4112ef994a
@ -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';
|
||||
@ -2344,10 +2345,35 @@ class core_moodlelib_testcase extends advanced_testcase {
|
||||
|
||||
// Test override parameter.
|
||||
$CFG->fullnamedisplay = 'firstname';
|
||||
$expectedname = "$user->firstname $user->lastname $user->firstnamephonetic $user->lastnamephonetic $user->middlename $user->alternatename";
|
||||
$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 $user->firstnamephonetic $user->lastnamephonetic $user->middlename $user->alternatename";
|
||||
$testname = fullname($user, true);
|
||||
$this->assertSame($expectedname, $testname);
|
||||
|
||||
// Test alternativefullnameformat that has been set to 'language'.
|
||||
$CFG->alternativefullnameformat = 'language';
|
||||
$expectedname = "$user->firstname $user->lastname $user->firstnamephonetic $user->lastnamephonetic $user->middlename $user->alternatename";
|
||||
$testname = fullname($user, true);
|
||||
$this->assertSame($expectedname, $testname);
|
||||
|
||||
// Test customising the alternativefullnameformat setting with a basic configuration.
|
||||
$CFG->alternativefullnameformat = 'firstname lastname';
|
||||
$expectedname = "$user->firstname $user->lastname";
|
||||
$testname = fullname($user, true);
|
||||
$this->assertSame($expectedname, $testname);
|
||||
|
||||
// Test customising the alternativefullnameformat setting with a more advanced configuration.
|
||||
$CFG->alternativefullnameformat = 'firstname firstnamephonetic lastname lastnamephonetic, middlename';
|
||||
$expectedname = "$user->firstname $user->firstnamephonetic $user->lastname $user->lastnamephonetic, $user->middlename";
|
||||
$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 +2454,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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user