Skip to content

Commit

Permalink
MDL-40356 lib: Unit tests for the alternativefullnameformat setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Sep 16, 2014
1 parent 482abd0 commit 795c588
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/tests/moodlelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,7 @@ public function test_fullname() {
// 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';
Expand Down Expand Up @@ -2348,6 +2349,25 @@ public function test_fullname() {
$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";
Expand Down Expand Up @@ -2428,6 +2448,7 @@ public function test_fullname() {

// Tidy up after we finish testing.
$CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
$CFG->alternativefullnameformat = $originalcfg->alternativefullnameformat;
}

public function test_get_all_user_name_fields() {
Expand Down

0 comments on commit 795c588

Please sign in to comment.