Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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 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
 */
1441 ariadna 34
final class manual_test extends \advanced_testcase {
1 efrain 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 {
1441 ariadna 43
        parent::setUp();
1 efrain 44
        $this->resetAfterTest(true);
45
        $this->authplugin = new auth_plugin_manual();
46
        set_config('expiration', '1', 'auth_manual');
47
        set_config('expiration_warning', '2', 'auth_manual');
48
        set_config('expirationtime', '30', 'auth_manual');
49
        $this->authplugin->config = get_config(auth_plugin_manual::COMPONENT_NAME);
50
    }
51
 
52
    /**
53
     * Test user_update_password method.
54
     */
11 efrain 55
    public function test_user_update_password(): void {
1 efrain 56
        $user = $this->getDataGenerator()->create_user();
57
        $expectedtime = time();
58
        $passwordisupdated = $this->authplugin->user_update_password($user, 'MyNewPassword*');
59
 
60
        // Assert that the actual time should be equal or a little greater than the expected time.
61
        $this->assertGreaterThanOrEqual($expectedtime, get_user_preferences('auth_manual_passwordupdatetime', 0, $user->id));
62
 
63
        // Assert that the password was successfully updated.
64
        $this->assertTrue($passwordisupdated);
65
    }
66
 
67
    /**
68
     * Test test_password_expire method.
69
     */
11 efrain 70
    public function test_password_expire(): void {
1 efrain 71
        $userrecord = array();
72
        $expirationtime = 31 * DAYSECS;
73
        $userrecord['timecreated'] = time() - $expirationtime;
74
        $user1 = $this->getDataGenerator()->create_user($userrecord);
75
        $user2 = $this->getDataGenerator()->create_user();
76
 
77
        // The user 1 was created 31 days ago and has not changed his password yet, so the password has expirated.
78
        $this->assertLessThanOrEqual(-1, $this->authplugin->password_expire($user1->username));
79
 
80
        // The user 2 just came to be created and has not changed his password yet, so the password has not expirated.
81
        $this->assertEquals(30, $this->authplugin->password_expire($user2->username));
82
 
83
        $this->authplugin->user_update_password($user1, 'MyNewPassword*');
84
 
85
        // The user 1 just updated his password so the password has not expirated.
86
        $this->assertEquals(30, $this->authplugin->password_expire($user1->username));
87
    }
88
 
89
}