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
/**
18
 * Provides testable_auth_plugin_base class.
19
 *
20
 * @package    core
21
 * @subpackage fixtures
22
 * @category   test
23
 * @copyright  2024 Catalyst IT
24
 * @author     Brendan Heywood <brendan@catalyst-au.net>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
class testable_auth_plugin_base extends \auth_plugin_base {
28
 
29
    /**
30
     * Override to add test auth plugin
31
     *
32
     * @return array of plugin classes
33
     */
34
    public static function get_enabled_auth_plugin_classes(): array {
35
        $plugins = parent::get_enabled_auth_plugin_classes();
36
        $plugins[] = new testable_auth_plugin_base();
37
        return $plugins;
38
    }
39
 
40
    /**
41
     * Identify a Moodle account on the CLI
42
     *
43
     * For example a plugin might use posix_geteuid and posix_getpwuid
44
     * to find the username of the OS level user and then match that
45
     * against Moodle user accounts.
46
     *
47
     * @return null|stdClass User user record if found
48
     */
49
    public function find_cli_user(): ?stdClass {
50
        global $DB;
51
        $user = $DB->get_record('user', ['username' => 'abcdef']);
52
        if ($user) {
53
            return $user;
54
        }
55
        return null;
56
    }
57
 
58
}