[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 * Tests core_user class. 19 * 20 * @package core 21 * @copyright 2013 Rajesh Taneja <[email protected]> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 /** 26 * Test core_user class. 27 * 28 * @package core 29 * @copyright 2013 Rajesh Taneja <[email protected]> 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class core_user_testcase extends advanced_testcase { 33 34 /** 35 * Setup test data. 36 */ 37 protected function setUp() { 38 $this->resetAfterTest(true); 39 } 40 41 public function test_get_user() { 42 global $CFG; 43 44 45 // Create user and try fetach it with api. 46 $user = $this->getDataGenerator()->create_user(); 47 $this->assertEquals($user, core_user::get_user($user->id, '*', MUST_EXIST)); 48 49 // Test noreply user. 50 $CFG->noreplyuserid = null; 51 $noreplyuser = core_user::get_noreply_user(); 52 $this->assertEquals(1, $noreplyuser->emailstop); 53 $this->assertFalse(core_user::is_real_user($noreplyuser->id)); 54 $this->assertEquals($CFG->noreplyaddress, $noreplyuser->email); 55 $this->assertEquals(get_string('noreplyname'), $noreplyuser->firstname); 56 57 // Set user as noreply user and make sure noreply propery is set. 58 core_user::reset_internal_users(); 59 $CFG->noreplyuserid = $user->id; 60 $noreplyuser = core_user::get_noreply_user(); 61 $this->assertEquals(1, $noreplyuser->emailstop); 62 $this->assertTrue(core_user::is_real_user($noreplyuser->id)); 63 64 // Test support user. 65 core_user::reset_internal_users(); 66 $CFG->supportemail = null; 67 $CFG->noreplyuserid = null; 68 $supportuser = core_user::get_support_user(); 69 $adminuser = get_admin(); 70 $this->assertEquals($adminuser, $supportuser); 71 $this->assertTrue(core_user::is_real_user($supportuser->id)); 72 73 // When supportemail is set. 74 core_user::reset_internal_users(); 75 $CFG->supportemail = '[email protected]'; 76 $supportuser = core_user::get_support_user(); 77 $this->assertEquals(core_user::SUPPORT_USER, $supportuser->id); 78 $this->assertFalse(core_user::is_real_user($supportuser->id)); 79 80 // Set user as support user and make sure noreply propery is set. 81 core_user::reset_internal_users(); 82 $CFG->supportuserid = $user->id; 83 $supportuser = core_user::get_support_user(); 84 $this->assertEquals($user, $supportuser); 85 $this->assertTrue(core_user::is_real_user($supportuser->id)); 86 } 87 88 /** 89 * Test get_user_by_username method. 90 */ 91 public function test_get_user_by_username() { 92 $record = array(); 93 $record['username'] = 'johndoe'; 94 $record['email'] = '[email protected]'; 95 $record['timecreated'] = time(); 96 97 // Create a default user for the test. 98 $userexpected = $this->getDataGenerator()->create_user($record); 99 100 // Assert that the returned user is the espected one. 101 $this->assertEquals($userexpected, core_user::get_user_by_username('johndoe')); 102 103 // Assert that a subset of fields is correctly returned. 104 $this->assertEquals((object) $record, core_user::get_user_by_username('johndoe', 'username,email,timecreated')); 105 106 // Assert that a user with a different mnethostid will no be returned. 107 $this->assertFalse(core_user::get_user_by_username('johndoe', 'username,email,timecreated', 2)); 108 109 // Create a new user from a different host. 110 $record['mnethostid'] = 2; 111 $userexpected2 = $this->getDataGenerator()->create_user($record); 112 113 // Assert that the new user is returned when specified the correct mnethostid. 114 $this->assertEquals($userexpected2, core_user::get_user_by_username('johndoe', '*', 2)); 115 116 // Assert that a user not in the db return false. 117 $this->assertFalse(core_user::get_user_by_username('janedoe')); 118 } 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |