1 |
efrain |
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\event;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Tests for event \core\event\user_password_updated
|
|
|
21 |
*
|
|
|
22 |
* @package core
|
|
|
23 |
* @category test
|
|
|
24 |
* @copyright 2014 Petr Skoda
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
class user_password_updated_test extends \advanced_testcase {
|
|
|
28 |
/**
|
|
|
29 |
* Test the event.
|
|
|
30 |
*/
|
11 |
efrain |
31 |
public function test_event(): void {
|
1 |
efrain |
32 |
$this->resetAfterTest();
|
|
|
33 |
|
|
|
34 |
$user1 = $this->getDataGenerator()->create_user();
|
|
|
35 |
$context1 = \context_user::instance($user1->id);
|
|
|
36 |
$user2 = $this->getDataGenerator()->create_user();
|
|
|
37 |
$context2 = \context_user::instance($user2->id);
|
|
|
38 |
|
|
|
39 |
$this->setUser($user1);
|
|
|
40 |
|
|
|
41 |
// Changing own password.
|
|
|
42 |
$event = \core\event\user_password_updated::create_from_user($user1);
|
|
|
43 |
$this->assertEventContextNotUsed($event);
|
|
|
44 |
$this->assertEquals($user1->id, $event->relateduserid);
|
|
|
45 |
$this->assertSame($context1, $event->get_context());
|
|
|
46 |
$this->assertFalse($event->other['forgottenreset']);
|
|
|
47 |
$event->trigger();
|
|
|
48 |
|
|
|
49 |
// Changing password of other user.
|
|
|
50 |
$event = \core\event\user_password_updated::create_from_user($user2);
|
|
|
51 |
$this->assertEventContextNotUsed($event);
|
|
|
52 |
$this->assertEquals($user2->id, $event->relateduserid);
|
|
|
53 |
$this->assertSame($context2, $event->get_context());
|
|
|
54 |
$this->assertFalse($event->other['forgottenreset']);
|
|
|
55 |
$event->trigger();
|
|
|
56 |
|
|
|
57 |
// Password reset.
|
|
|
58 |
$event = \core\event\user_password_updated::create_from_user($user1, true);
|
|
|
59 |
$this->assertEventContextNotUsed($event);
|
|
|
60 |
$this->assertEquals($user1->id, $event->relateduserid);
|
|
|
61 |
$this->assertSame($context1, $event->get_context());
|
|
|
62 |
$this->assertTrue($event->other['forgottenreset']);
|
|
|
63 |
$event->trigger();
|
|
|
64 |
}
|
|
|
65 |
}
|