xref: /plugin/pureldap/_test/GroupHierarchyCacheTest.php (revision 5dcabeda2fad4e4ee9d5e2783f1e5e830b0344f4)
1<?php
2
3namespace dokuwiki\plugin\pureldap\test;
4
5use dokuwiki\plugin\pureldap\classes\ADClient;
6use dokuwiki\plugin\pureldap\classes\GroupHierarchyCache;
7use DokuWikiTest;
8
9/**
10 * tests for the pureldap plugin
11 *
12 * @group plugin_pureldap
13 * @group plugins
14 */
15class GroupHierarchyCacheTest extends DokuWikiTest
16{
17
18    /**
19     * Return an initialized GroupHierarchyCache
20     *
21     * Creates a client with default settings. Optionally allows to override configs.
22     *
23     * All tests assume to be running against https://github.com/splitbrain/vagrant-active-directory
24     *
25     * @param array $conf
26     * @return GroupHierarchyCache|null
27     */
28    protected function getClient($conf = [])
29    {
30        $client = new ADClient(
31            array_merge(
32                [
33                    'base_dn' => 'DC=example,DC=local',
34                    'suffix' => 'example.local',
35                    'servers' => ['localhost'],
36                    'port' => 7636,
37                    'admin_username' => 'vagrant',
38                    'admin_password' => 'vagrant',
39                    'encryption' => 'ssl',
40                    'validate' => 'self',
41                    'attributes' => ['mobile'],
42                ],
43                $conf
44            )
45        );
46
47        return $client->getGroupHierarchyCache();
48    }
49
50    public function testGetGroupList()
51    {
52        $ghc = $this->getClient();
53        $list = $this->callInaccessibleMethod($ghc, 'getGroupList', []);
54
55        $this->assertGreaterThan(20, $list);
56        $this->assertArrayHasKey('CN=Gamma Nested,CN=Users,DC=example,DC=local', $list);
57        $this->assertArrayHasKey('parents', $list['CN=Gamma Nested,CN=Users,DC=example,DC=local']);
58        $this->assertArrayHasKey('children', $list['CN=Gamma Nested,CN=Users,DC=example,DC=local']);
59    }
60
61    public function testGetParents()
62    {
63        $ghc = $this->getClient();
64        $this->assertEquals(
65            [
66                'CN=Gamma Nested,CN=Users,DC=example,DC=local',
67                'CN=beta,CN=Users,DC=example,DC=local',
68            ],
69            $ghc->getParents('CN=omega nested,CN=Users,DC=example,DC=local')
70        );
71    }
72
73    public function testGetChildren()
74    {
75        $ghc = $this->getClient();
76        $this->assertEquals(
77            [
78                'CN=Gamma Nested,CN=Users,DC=example,DC=local',
79                'CN=omega nested,CN=Users,DC=example,DC=local',
80            ],
81            $ghc->getChildren('CN=beta,CN=Users,DC=example,DC=local')
82        );
83    }
84
85}
86