summaryrefslogtreecommitdiff
path: root/tests/units/Core/Ldap/UserTest.php
blob: 56cc588c14ebb89bae8ef7ea9ede76bc00939b3c (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php

namespace Kanboard\Core\Ldap;

require_once __DIR__.'/../../Base.php';

class UserTest extends \Base
{
    public function testGetProfile()
    {
        $entries = array(
            'count' => 1,
            0 => array(
                'count' => 2,
                'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local',
                'displayname' => array(
                    'count' => 1,
                    0 => 'My LDAP user',
                ),
                'mail' => array(
                    'count' => 2,
                    0 => 'user1@localhost',
                    1 => 'user2@localhost',
                ),
                'samaccountname' => array(
                    'count' => 1,
                    0 => 'my_ldap_user',
                ),
                0 => 'displayname',
                1 => 'mail',
                2 => 'samaccountname',
            )
        );

        $expected = array(
            'ldap_id' => 'uid=my_user,ou=People,dc=kanboard,dc=local',
            'username' => 'my_ldap_user',
            'name' => 'My LDAP user',
            'email' => 'user1@localhost',
            'is_admin' => 0,
            'is_project_admin' => 0,
            'is_ldap_user' => 1,
        );

        $query = $this
            ->getMockBuilder('\Kanboard\Core\Ldap\Query')
            ->setConstructorArgs(array($entries))
            ->setMethods(array(
                'execute',
                'hasResult',
            ))
            ->getMock();

        $query
            ->expects($this->once())
            ->method('execute')
            ->with(
                $this->equalTo('my_ldap_resource'),
                $this->equalTo('ou=People,dc=kanboard,dc=local'),
                $this->equalTo('(uid=my_user)')
            );

        $query
            ->expects($this->once())
            ->method('hasResult')
            ->will($this->returnValue(true));

        $user = $this
            ->getMockBuilder('\Kanboard\Core\Ldap\User')
            ->setConstructorArgs(array($query))
            ->setMethods(array(
                'getAttributeUsername',
                'getAttributeEmail',
                'getAttributeName',
            ))
            ->getMock();

        $user
            ->expects($this->any())
            ->method('getAttributeUsername')
            ->will($this->returnValue('samaccountname'));

        $user
            ->expects($this->any())
            ->method('getAttributeName')
            ->will($this->returnValue('displayname'));

        $user
            ->expects($this->any())
            ->method('getAttributeEmail')
            ->will($this->returnValue('mail'));

        $this->assertEquals($expected, $user->getProfile('my_ldap_resource', 'ou=People,dc=kanboard,dc=local', '(uid=my_user)'));
    }
}