Proyectos de Subversion Moodle

Rev

Rev 1 | | 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
/**
18
 * Data provider tests.
19
 *
20
 * @package    core_auth
21
 * @category   test
22
 * @copyright  2018 Frédéric Massart
23
 * @author     Frédéric Massart <fred@branchup.tech>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
namespace core_auth\privacy;
27
 
28
defined('MOODLE_INTERNAL') || die();
29
global $CFG;
30
 
31
use core_privacy\tests\provider_testcase;
32
use core_privacy\local\request\transform;
33
use core_privacy\local\request\writer;
34
use core_auth\privacy\provider;
35
 
36
/**
37
 * Data provider testcase class.
38
 *
39
 * @package    core_auth
40
 * @category   test
41
 * @copyright  2018 Frédéric Massart
42
 * @author     Frédéric Massart <fred@branchup.tech>
43
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44
 */
45
class provider_test extends provider_testcase {
46
 
47
    public function setUp(): void {
48
        $this->resetAfterTest();
49
    }
50
 
11 efrain 51
    public function test_export_user_preferences(): void {
1 efrain 52
        $dg = $this->getDataGenerator();
53
        $u1 = $dg->create_user();
54
        $u2 = $dg->create_user();
55
        $sysctx = \context_system::instance();
56
        $now = time();
57
 
58
        // Check nothing is there.
59
        writer::reset();
60
        provider::export_user_preferences($u1->id);
61
        $prefs = writer::with_context($sysctx)->get_user_preferences('core_auth');
62
        $this->assertEmpty((array) $prefs);
63
 
64
        // Set some preferences.
65
        set_user_preference('auth_forcepasswordchange', 1, $u1);
66
        set_user_preference('create_password', 1, $u1);
67
        set_user_preference('login_failed_count', 18, $u1);
68
        set_user_preference('login_failed_count_since_success', 7, $u1);
69
        set_user_preference('login_failed_last', $now - DAYSECS, $u1);
70
        set_user_preference('login_lockout', $now - HOURSECS, $u1);
71
        set_user_preference('login_lockout_ignored', 0, $u1);
72
        set_user_preference('login_lockout_secret', 'Hello world!', $u1);
73
 
74
        set_user_preference('auth_forcepasswordchange', 0, $u2);
75
        set_user_preference('create_password', 0, $u2);
76
        set_user_preference('login_lockout_ignored', 1, $u2);
77
 
78
        // Check user 1.
79
        writer::reset();
80
        provider::export_user_preferences($u1->id);
81
        $prefs = writer::with_context($sysctx)->get_user_preferences('core_auth');
82
        $this->assertEquals(transform::yesno(true), $prefs->auth_forcepasswordchange->value);
83
        $this->assertEquals(transform::yesno(true), $prefs->create_password->value);
84
        $this->assertEquals(18, $prefs->login_failed_count->value);
85
        $this->assertEquals(7, $prefs->login_failed_count_since_success->value);
86
        $this->assertEquals(transform::datetime($now - DAYSECS), $prefs->login_failed_last->value);
87
        $this->assertEquals(transform::datetime($now - HOURSECS), $prefs->login_lockout->value);
88
        $this->assertEquals(transform::yesno(false), $prefs->login_lockout_ignored->value);
89
        $this->assertEquals('Hello world!', $prefs->login_lockout_secret->value);
90
 
91
        // Check user 2.
92
        writer::reset();
93
        provider::export_user_preferences($u2->id);
94
        $prefs = writer::with_context($sysctx)->get_user_preferences('core_auth');
95
        $this->assertEquals(transform::yesno(false), $prefs->auth_forcepasswordchange->value);
96
        $this->assertEquals(transform::yesno(false), $prefs->create_password->value);
97
        $this->assertObjectNotHasProperty('login_failed_count', $prefs);
98
        $this->assertObjectNotHasProperty('login_failed_count_since_success', $prefs);
99
        $this->assertObjectNotHasProperty('login_failed_last', $prefs);
100
        $this->assertObjectNotHasProperty('login_lockout', $prefs);
101
        $this->assertEquals(transform::yesno(true), $prefs->login_lockout_ignored->value);
102
        $this->assertObjectNotHasProperty('login_lockout_secret', $prefs);
103
    }
104
}