Differences Between: [Versions 310 and 311] [Versions 39 and 311]
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 auth_manual; 18 19 use auth_plugin_manual; 20 21 defined('MOODLE_INTERNAL') || die(); 22 23 global $CFG; 24 require_once($CFG->dirroot.'/auth/manual/auth.php'); 25 26 /** 27 * Manual authentication tests class. 28 * 29 * @package auth_manual 30 * @category test 31 * @copyright 2014 Gilles-Philippe Leblanc <gilles-philippe.leblanc@umontreal.ca> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class manual_test extends \advanced_testcase { 35 36 /** @var auth_plugin_manual Keeps the authentication plugin. */ 37 protected $authplugin; 38 39 /** 40 * Setup test data. 41 */ 42 protected function setUp(): void { 43 $this->resetAfterTest(true); 44 $this->authplugin = new auth_plugin_manual(); 45 set_config('expiration', '1', 'auth_manual'); 46 set_config('expiration_warning', '2', 'auth_manual'); 47 set_config('expirationtime', '30', 'auth_manual'); 48 $this->authplugin->config = get_config(auth_plugin_manual::COMPONENT_NAME); 49 } 50 51 /** 52 * Test user_update_password method. 53 */ 54 public function test_user_update_password() { 55 $user = $this->getDataGenerator()->create_user(); 56 $expectedtime = time(); 57 $passwordisupdated = $this->authplugin->user_update_password($user, 'MyNewPassword*'); 58 59 // Assert that the actual time should be equal or a little greater than the expected time. 60 $this->assertGreaterThanOrEqual($expectedtime, get_user_preferences('auth_manual_passwordupdatetime', 0, $user->id)); 61 62 // Assert that the password was successfully updated. 63 $this->assertTrue($passwordisupdated); 64 } 65 66 /** 67 * Test test_password_expire method. 68 */ 69 public function test_password_expire() { 70 $userrecord = array(); 71 $expirationtime = 31 * DAYSECS; 72 $userrecord['timecreated'] = time() - $expirationtime; 73 $user1 = $this->getDataGenerator()->create_user($userrecord); 74 $user2 = $this->getDataGenerator()->create_user(); 75 76 // The user 1 was created 31 days ago and has not changed his password yet, so the password has expirated. 77 $this->assertLessThanOrEqual(-1, $this->authplugin->password_expire($user1->username)); 78 79 // The user 2 just came to be created and has not changed his password yet, so the password has not expirated. 80 $this->assertEquals(30, $this->authplugin->password_expire($user2->username)); 81 82 $this->authplugin->user_update_password($user1, 'MyNewPassword*'); 83 84 // The user 1 just updated his password so the password has not expirated. 85 $this->assertEquals(30, $this->authplugin->password_expire($user1->username)); 86 } 87 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body