aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins/authplain/_test/userdata.test.php
blob: 9460c191970c71805845d747117f93c5e4d206e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

/**
 * Class userdata_test
 *
 * Test group retrieval
 *
 * @group plugins
 */
class userdata_test extends DokuWikiTest
{
    /** @var  auth_plugin_authplain */
    protected $auth;

    /**
     * Load auth with test conf
     * @throws Exception
     */
    public function setUp() : void
    {
        parent::setUp();
        global $config_cascade;
        $config_cascade['plainauth.users']['default'] = __DIR__ . '/conf/auth.users.php';
        $this->auth = new auth_plugin_authplain();
    }

    /**
     * Test that all groups are retrieved in the correct order, without duplicates
     */
    public function test_retrieve_groups()
    {
        $expected = ['user', 'first_group', 'second_group', 'third_group', 'fourth_group', 'fifth_group'];
        $actual = $this->auth->retrieveGroups();
        $this->assertEquals($expected, $actual);
    }

    /**
     * Test with small and large limits
     */
    public function test_retrieve_groups_limit()
    {
        $expected = ['user', 'first_group'];
        $actual = $this->auth->retrieveGroups(0, 2);
        $this->assertEquals($expected, $actual);

        $expected = ['user', 'first_group', 'second_group', 'third_group', 'fourth_group', 'fifth_group'];
        $actual = $this->auth->retrieveGroups(0, 20);
        $this->assertEquals($expected, $actual);
    }

    /**
     * Test with small and large offsets
     */
    public function test_retrieve_groups_offset()
    {
        $expected = ['third_group', 'fourth_group', 'fifth_group'];
        $actual = $this->auth->retrieveGroups(3,10);
        $this->assertEquals($expected, $actual);

        $expected = [];
        $actual = $this->auth->retrieveGroups(10,3);
        $this->assertEquals($expected, $actual);
    }
}