MDL-40356 lib: Unit tests for the alternativefullnameformat setting.
authorAdrian Greeve <adrian@moodle.com>
Tue, 16 Sep 2014 02:57:28 +0000 (10:57 +0800)
committerAdrian Greeve <adrian@moodle.com>
Tue, 16 Sep 2014 02:57:28 +0000 (10:57 +0800)
lib/tests/moodlelib_test.php

index 776d1fc..f875a02 100644 (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() {