Differences Between: [Versions 310 and 311] [Versions 39 and 311]
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 namespace core_user; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 global $CFG; 22 require_once($CFG->dirroot.'/user/editlib.php'); 23 24 /** 25 * Unit tests for user editlib api. 26 * 27 * @package core_user 28 * @category test 29 * @copyright 2013 Adrian Greeve <adrian@moodle.com> 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class editlib_test extends \advanced_testcase { 33 34 /** 35 * Test that the required fields are returned in the correct order. 36 */ 37 function test_useredit_get_required_name_fields() { 38 global $CFG; 39 // Back up config settings for restore later. 40 $originalcfg = new \stdClass(); 41 $originalcfg->fullnamedisplay = $CFG->fullnamedisplay; 42 43 $CFG->fullnamedisplay = 'language'; 44 $expectedresult = array(5 => 'firstname', 21 => 'lastname'); 45 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 46 $CFG->fullnamedisplay = 'firstname'; 47 $expectedresult = array(5 => 'firstname', 21 => 'lastname'); 48 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 49 $CFG->fullnamedisplay = 'lastname firstname'; 50 $expectedresult = array('lastname', 9 => 'firstname'); 51 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 52 $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic'; 53 $expectedresult = array(5 => 'firstname', 21 => 'lastname'); 54 $this->assertEquals(useredit_get_required_name_fields(), $expectedresult); 55 56 // Tidy up after we finish testing. 57 $CFG->fullnamedisplay = $originalcfg->fullnamedisplay; 58 } 59 60 /** 61 * Test that the enabled fields are returned in the correct order. 62 */ 63 function test_useredit_get_enabled_name_fields() { 64 global $CFG; 65 // Back up config settings for restore later. 66 $originalcfg = new \stdClass(); 67 $originalcfg->fullnamedisplay = $CFG->fullnamedisplay; 68 69 $CFG->fullnamedisplay = 'language'; 70 $expectedresult = array(); 71 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 72 $CFG->fullnamedisplay = 'firstname lastname firstnamephonetic'; 73 $expectedresult = array(19 => 'firstnamephonetic'); 74 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 75 $CFG->fullnamedisplay = 'firstnamephonetic, lastname lastnamephonetic (alternatename)'; 76 $expectedresult = array('firstnamephonetic', 28 => 'lastnamephonetic', 46 => 'alternatename'); 77 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 78 $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic alternatename middlename'; 79 $expectedresult = array('firstnamephonetic', 18 => 'lastnamephonetic', 35 => 'alternatename', 49 => 'middlename'); 80 $this->assertEquals(useredit_get_enabled_name_fields(), $expectedresult); 81 82 // Tidy up after we finish testing. 83 $CFG->fullnamedisplay = $originalcfg->fullnamedisplay; 84 } 85 86 /** 87 * Test that the disabled fields are returned. 88 */ 89 function test_useredit_get_disabled_name_fields() { 90 global $CFG; 91 // Back up config settings for restore later. 92 $originalcfg = new \stdClass(); 93 $originalcfg->fullnamedisplay = $CFG->fullnamedisplay; 94 95 $CFG->fullnamedisplay = 'language'; 96 $expectedresult = array('firstnamephonetic' => 'firstnamephonetic', 'lastnamephonetic' => 'lastnamephonetic', 97 'middlename' => 'middlename', 'alternatename' => 'alternatename'); 98 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 99 $CFG->fullnamedisplay = 'firstname lastname firstnamephonetic'; 100 $expectedresult = array('lastnamephonetic' => 'lastnamephonetic', 'middlename' => 'middlename', 'alternatename' => 'alternatename'); 101 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 102 $CFG->fullnamedisplay = 'firstnamephonetic, lastname lastnamephonetic (alternatename)'; 103 $expectedresult = array('middlename' => 'middlename'); 104 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 105 $CFG->fullnamedisplay = 'firstnamephonetic lastnamephonetic alternatename middlename'; 106 $expectedresult = array(); 107 $this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult); 108 109 // Tidy up after we finish testing. 110 $CFG->fullnamedisplay = $originalcfg->fullnamedisplay; 111 } 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body