1<?php
2
3namespace dokuwiki\plugin\usermanager\test;
4
5/**
6 * Simple Auth Plugin for testing
7 *
8 * All users are stored in a simple array
9 * @todo This might be useful for other tests and could replace the remaining mock auth plugins
10 */
11class AuthPlugin extends \dokuwiki\Extension\AuthPlugin {
12
13    public $loggedOff = false;
14
15    /** @var array user storage */
16    public $users = [];
17
18    /** @inheritdoc */
19    public function __construct($cando = []) {
20        parent::__construct(); // for compatibility
21
22        // our own default capabilities
23        $this->cando['addUser'] = true;
24        $this->cando['delUser'] = true;
25
26        // merge in given capabilities for testing
27        $this->cando = array_merge($this->cando, $cando);
28    }
29
30    /** @inheritdoc */
31    public function createUser($user, $pwd, $name, $mail, $grps = null) {
32        if (isset($this->users[$user])) {
33            return false;
34        }
35        $pass = md5($pwd);
36        $grps = (array) $grps;
37        $this->users[$user] = compact('pass', 'name', 'mail', 'grps');
38        return true;
39    }
40
41    /** @inheritdoc */
42    public function deleteUsers($users)
43    {
44        $deleted = 0;
45        foreach ($users as $user) {
46            if (isset($this->users[$user])) {
47                unset($this->users[$user]);
48                $deleted++;
49            }
50
51        }
52        return $deleted;
53    }
54}
55