Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 declare(strict_types=1); 18 19 namespace core_reportbuilder\local\entities; 20 21 use advanced_testcase; 22 23 /** 24 * Unit tests for user entity 25 * 26 * @package core_reportbuilder 27 * @covers \core_reportbuilder\local\entities\user 28 * @copyright 2021 Paul Holden <paulh@moodle.com> 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 */ 31 class user_test extends advanced_testcase { 32 33 /** 34 * Data provider for {@see test_get_name_fields_select} 35 * 36 * @return array 37 */ 38 public function get_name_fields_select_provider(): array { 39 return [ 40 ['firstname lastname', ['firstname', 'lastname']], 41 ['firstname middlename lastname', ['firstname', 'middlename', 'lastname']], 42 ['alternatename lastname firstname', ['alternatename', 'lastname', 'firstname']], 43 ]; 44 } 45 46 /** 47 * Tests the helper method for selecting all of a users' name fields 48 * 49 * @param string $fullnamedisplay 50 * @param string[] $expecteduserfields 51 * 52 * @dataProvider get_name_fields_select_provider 53 */ 54 public function test_get_name_fields_select(string $fullnamedisplay, array $expecteduserfields): void { 55 global $DB; 56 57 $this->resetAfterTest(true); 58 59 set_config('alternativefullnameformat', $fullnamedisplay); 60 61 $fields = user::get_name_fields_select('u'); 62 $user = $DB->get_record_sql("SELECT {$fields} FROM {user} u WHERE username = :username", ['username' => 'admin']); 63 64 // Ensure we received back all name fields. 65 $this->assertEquals($expecteduserfields, array_keys((array) $user)); 66 } 67 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body