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 for password changes event. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2014 Petr Skoda 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Tests for event \core\event\user_password_updated 30 * 31 * @package core 32 * @category phpunit 33 * @copyright 2014 Petr Skoda 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class core_event_user_password_updated_testcase extends advanced_testcase { 37 /** 38 * Test the event. 39 */ 40 public function test_event() { 41 $this->resetAfterTest(); 42 43 $user1 = $this->getDataGenerator()->create_user(); 44 $context1 = context_user::instance($user1->id); 45 $user2 = $this->getDataGenerator()->create_user(); 46 $context2 = context_user::instance($user2->id); 47 48 $this->setUser($user1); 49 50 // Changing own password. 51 $event = \core\event\user_password_updated::create_from_user($user1); 52 $this->assertEventContextNotUsed($event); 53 $this->assertEquals($user1->id, $event->relateduserid); 54 $this->assertSame($context1, $event->get_context()); 55 $this->assertEventLegacyLogData(null, $event); 56 $this->assertFalse($event->other['forgottenreset']); 57 $event->trigger(); 58 59 // Changing password of other user. 60 $event = \core\event\user_password_updated::create_from_user($user2); 61 $this->assertEventContextNotUsed($event); 62 $this->assertEquals($user2->id, $event->relateduserid); 63 $this->assertSame($context2, $event->get_context()); 64 $this->assertEventLegacyLogData(null, $event); 65 $this->assertFalse($event->other['forgottenreset']); 66 $event->trigger(); 67 68 // Password reset. 69 $event = \core\event\user_password_updated::create_from_user($user1, true); 70 $this->assertEventContextNotUsed($event); 71 $this->assertEquals($user1->id, $event->relateduserid); 72 $this->assertSame($context1, $event->get_context()); 73 $this->assertEventLegacyLogData(array(SITEID, 'user', 'set password', 'profile.php?id='.$user1->id, $user1->id), $event); 74 $this->assertTrue($event->other['forgottenreset']); 75 $event->trigger(); 76 } 77 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body