See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Unit tests for user/editlib.php. 19 * 20 * @package core_user 21 * @category phpunit 22 * @copyright 2013 Adrian Greeve <adrian@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->dirroot.'/user/editlib.php'); 30 31 /** 32 * Unit tests for user editlib api. 33 * 34 * @package core_user 35 * @category phpunit 36 * @copyright 2013 Adrian Greeve <adrian@moodle.com> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class core_user_editlib_testcase extends advanced_testcase { 40 41 /** 42 * Test that the required fields are returned in the correct order. 43 */ 44 function test_useredit_get_required_name_fields() { 45 global $CFG; 46 // Back up config settings for restore later. 47 $originalcfg = new stdClass(); 48 $originalcfg->fullnamedisplay = $CFG->fullnamedisplay; 49 50 $CFG->fullnamedisplay = 'language'; 51 $expectedresult = array(5 => 'firstname', 21 => 'lastname'); 52 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 53 $CFG->fullnamedisplay = 'firstname'; 54 $expectedresult = array(5 => 'firstname', 21 => 'lastname'); 55 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 56 $CFG->fullnamedisplay = 'lastname firstname'; 57 $expectedresult = array('lastname', 9 => 'firstname'); 58 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 59 $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic'; 60 $expectedresult = array(5 => 'firstname', 21 => 'lastname'); 61 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 62 63 // Tidy up after we finish testing. 64 $CFG->fullnamedisplay = $originalcfg->fullnamedisplay; 65 } 66 67 /** 68 * Test that the enabled fields are returned in the correct order. 69 */ 70 function test_useredit_get_enabled_name_fields() { 71 global $CFG; 72 // Back up config settings for restore later. 73 $originalcfg = new stdClass(); 74 $originalcfg->fullnamedisplay = $CFG->fullnamedisplay; 75 76 $CFG->fullnamedisplay = 'language'; 77 $expectedresult = array(); 78 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 79 $CFG->fullnamedisplay = 'firstname lastname firstnamephonetic'; 80 $expectedresult = array(19 => 'firstnamephonetic'); 81 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 82 $CFG->fullnamedisplay = 'firstnamephonetic, lastname lastnamephonetic (alternatename)'; 83 $expectedresult = array('firstnamephonetic', 28 => 'lastnamephonetic', 46 => 'alternatename'); 84 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 85 $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic alternatename middlename'; 86 $expectedresult = array('firstnamephonetic', 18 => 'lastnamephonetic', 35 => 'alternatename', 49 => 'middlename'); 87 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 88 89 // Tidy up after we finish testing. 90 $CFG->fullnamedisplay = $originalcfg->fullnamedisplay; 91 } 92 93 /** 94 * Test that the disabled fields are returned. 95 */ 96 function test_useredit_get_disabled_name_fields() { 97 global $CFG; 98 // Back up config settings for restore later. 99 $originalcfg = new stdClass(); 100 $originalcfg->fullnamedisplay = $CFG->fullnamedisplay; 101 102 $CFG->fullnamedisplay = 'language'; 103 $expectedresult = array('firstnamephonetic' => 'firstnamephonetic', 'lastnamephonetic' => 'lastnamephonetic', 104 'middlename' => 'middlename', 'alternatename' => 'alternatename'); 105 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 106 $CFG->fullnamedisplay = 'firstname lastname firstnamephonetic'; 107 $expectedresult = array('lastnamephonetic' => 'lastnamephonetic', 'middlename' => 'middlename', 'alternatename' => 'alternatename'); 108 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 109 $CFG->fullnamedisplay = 'firstnamephonetic, lastname lastnamephonetic (alternatename)'; 110 $expectedresult = array('middlename' => 'middlename'); 111 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 112 $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic alternatename middlename'; 113 $expectedresult = array(); 114 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 115 116 // Tidy up after we finish testing. 117 $CFG->fullnamedisplay = $originalcfg->fullnamedisplay; 118 } 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body