MDL-31560 Messages: Added support for noreply and support users
[moodle.git] / lib / tests / user_test.php
CommitLineData
3bcf6b3c
RT
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 <rajesh@moodle.com>
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 <rajesh@moodle.com>
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 */
32class core_user_testcase extends advanced_testcase {
33
34 public function test_get_user() {
35 global $CFG;
36
37 $this->resetAfterTest(true);
38
39 // Create user and try fetach it with api.
40 $user = $this->getDataGenerator()->create_user();
41 $this->assertEquals($user, core_user::get_user($user->id, '*', MUST_EXIST));
42
43 // Test noreply user.
44 $CFG->noreplyuserid = null;
45 $noreplyuser = core_user::get_noreply_user();
46 $this->assertEquals(1, $noreplyuser->emailstop);
47 $this->assertFalse(core_user::is_real_user($noreplyuser->id));
48 $this->assertEquals($CFG->noreplyaddress, $noreplyuser->email);
49 $this->assertEquals(get_string('noreplyname'), $noreplyuser->firstname);
50
51 // Set user as noreply user and make sure noreply propery is set.
52 core_user::reset_internal_users();
53 $CFG->noreplyuserid = $user->id;
54 $noreplyuser = core_user::get_noreply_user();
55 $this->assertEquals(1, $noreplyuser->emailstop);
56 $this->assertTrue(core_user::is_real_user($noreplyuser->id));
57
58 // Test support user.
59 core_user::reset_internal_users();
60 $CFG->supportemail = null;
61 $CFG->noreplyuserid = null;
62 $supportuser = core_user::get_support_user();
63 $adminuser = get_admin();
64 $this->assertEquals($adminuser, $supportuser);
65 $this->assertTrue(core_user::is_real_user($supportuser->id));
66
67 // When supportemail is set.
68 core_user::reset_internal_users();
69 $CFG->supportemail = 'test@support.moodle.test';
70 $supportuser = core_user::get_support_user();
71 $this->assertEquals(core_user::SUPPORT_USER, $supportuser->id);
72 $this->assertFalse(core_user::is_real_user($supportuser->id));
73
74 // Set user as support user and make sure noreply propery is set.
75 core_user::reset_internal_users();
76 $CFG->supportuserid = $user->id;
77 $supportuser = core_user::get_support_user();
78 $this->assertEquals($user, $supportuser);
79 $this->assertTrue(core_user::is_real_user($supportuser->id));
80 }
81}