Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [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  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       */
  31      public function test_event() {
  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->assertEventLegacyLogData(null, $event);
  47          $this->assertFalse($event->other['forgottenreset']);
  48          $event->trigger();
  49  
  50          // Changing password of other user.
  51          $event = \core\event\user_password_updated::create_from_user($user2);
  52          $this->assertEventContextNotUsed($event);
  53          $this->assertEquals($user2->id, $event->relateduserid);
  54          $this->assertSame($context2, $event->get_context());
  55          $this->assertEventLegacyLogData(null, $event);
  56          $this->assertFalse($event->other['forgottenreset']);
  57          $event->trigger();
  58  
  59          // Password reset.
  60          $event = \core\event\user_password_updated::create_from_user($user1, true);
  61          $this->assertEventContextNotUsed($event);
  62          $this->assertEquals($user1->id, $event->relateduserid);
  63          $this->assertSame($context1, $event->get_context());
  64          $this->assertEventLegacyLogData(array(SITEID, 'user', 'set password', 'profile.php?id='.$user1->id, $user1->id), $event);
  65          $this->assertTrue($event->other['forgottenreset']);
  66          $event->trigger();
  67      }
  68  }