Proyectos de Subversion Moodle

Rev

| 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 core;
18
 
19
use core\check\result;
20
use core\check\security\passwordpolicy;
21
 
22
/**
23
 * Example unit tests for check API
24
 *
25
 * @package    core
26
 * @category   check
27
 * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @covers     \core\check
30
 */
31
class check_test extends \advanced_testcase {
32
 
33
    /**
34
     * A simple example showing how a check and result object works
35
     *
36
     * Conceptually a check is analgous to a unit test except at runtime
37
     * instead of build time so many checks in real life such as testing
38
     * an API is connecting aren't viable to unit test.
39
     */
40
    public function test_passwordpolicy(): void {
41
        global $CFG;
42
        $prior = $CFG->passwordpolicy;
43
 
44
        $check = new passwordpolicy();
45
 
46
        $CFG->passwordpolicy = false;
47
        $result = $check->get_result();
48
        $this->assertEquals($result->get_status(), result::WARNING);
49
 
50
        $CFG->passwordpolicy = true;
51
        $result = $check->get_result();
52
        $this->assertEquals($result->get_status(), result::OK);
53
 
54
        $CFG->passwordpolicy = $prior;
55
    }
56
 
57
    /**
58
     * Tests that the component is correctly set.
59
     */
60
    public function test_get_component(): void {
61
        $check = new \tool_task\check\maxfaildelay();
62
 
63
        // If no component is set, it should return the one based off the namespace.
64
        $this->assertEquals('tool_task', $check->get_component());
65
 
66
        // However if one is set, it should return that.
67
        $check->set_component('test component');
68
        $this->assertEquals('test component', $check->get_component());
69
    }
70
}
71