[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Manual authentication tests. 19 * 20 * @package auth_manual 21 * @category test 22 * @copyright 2014 Gilles-Philippe Leblanc <gilles-philippe.leblanc@umontreal.ca> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->dirroot.'/auth/manual/auth.php'); 30 31 /** 32 * Manual authentication tests class. 33 * 34 * @package auth_manual 35 * @category test 36 * @copyright 2014 Gilles-Philippe Leblanc <gilles-philippe.leblanc@umontreal.ca> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class auth_manual_testcase extends advanced_testcase { 40 41 /** @var auth_plugin_manual Keeps the authentication plugin. */ 42 protected $authplugin; 43 44 /** @var stdClass Keeps authentication plugin config */ 45 protected $config; 46 47 /** 48 * Setup test data. 49 */ 50 protected function setUp() { 51 $this->resetAfterTest(true); 52 $this->authplugin = new auth_plugin_manual(); 53 $this->config = new stdClass(); 54 $this->config->expiration = '1'; 55 $this->config->expiration_warning = '2'; 56 $this->config->expirationtime = '30'; 57 $this->authplugin->process_config($this->config); 58 $this->authplugin->config = get_config(auth_plugin_manual::COMPONENT_NAME); 59 } 60 61 /** 62 * Test user_update_password method. 63 */ 64 public function test_user_update_password() { 65 $user = $this->getDataGenerator()->create_user(); 66 $expectedtime = time(); 67 $passwordisupdated = $this->authplugin->user_update_password($user, 'MyNewPassword*'); 68 69 // Assert that the actual time should be equal or a little greater than the expected time. 70 $this->assertGreaterThanOrEqual($expectedtime, get_user_preferences('auth_manual_passwordupdatetime', 0, $user->id)); 71 72 // Assert that the password was successfully updated. 73 $this->assertTrue($passwordisupdated); 74 } 75 76 /** 77 * Test test_password_expire method. 78 */ 79 public function test_password_expire() { 80 $userrecord = array(); 81 $expirationtime = 31 * DAYSECS; 82 $userrecord['timecreated'] = time() - $expirationtime; 83 $user1 = $this->getDataGenerator()->create_user($userrecord); 84 $user2 = $this->getDataGenerator()->create_user(); 85 86 // The user 1 was created 31 days ago and has not changed his password yet, so the password has expirated. 87 $this->assertLessThanOrEqual(-1, $this->authplugin->password_expire($user1->username)); 88 89 // The user 2 just came to be created and has not changed his password yet, so the password has not expirated. 90 $this->assertEquals(30, $this->authplugin->password_expire($user2->username)); 91 92 $this->authplugin->user_update_password($user1, 'MyNewPassword*'); 93 94 // The user 1 just updated his password so the password has not expirated. 95 $this->assertEquals(30, $this->authplugin->password_expire($user1->username)); 96 } 97 98 /** 99 * Test test_process_config method. 100 */ 101 public function test_process_config() { 102 $this->assertTrue($this->authplugin->process_config($this->config)); 103 $config = get_config(auth_plugin_manual::COMPONENT_NAME); 104 $this->assertEquals($this->config->expiration, $config->expiration); 105 $this->assertEquals($this->config->expiration_warning, $config->expiration_warning); 106 $this->assertEquals($this->config->expirationtime, $config->expirationtime); 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |