LdapTest.php 2.33 KB
Newer Older
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
<?php
namespace UnicaenAuthTest\Provider\Identity;

/**
 * Description of LdapTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class LdapTest extends BaseTest
{
    protected $providerClass = 'UnicaenAuth\Provider\Identity\Ldap';
    protected $mapper;
    
    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
        parent::setUp();

        $this->mapper = $this->getMock('UnicaenApp\Mapper\Ldap\Db', array('findOneByDn'));
    }
    
    public function provideAuthServiceIdentity()
    {
27
        $identity1 = $this->getMock('UnicaenAuth\Entity\Ldap\People', array('getRoles', 'getUsername'));
28
29
30
        $identity1->expects($this->once())
                  ->method('getRoles')
                  ->will($this->returnValue(array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr')));
31
32
33
        $identity1->expects($this->once())
                  ->method('getUsername')
                  ->will($this->returnValue('username1'));
34
        
35
36
37
        $expectedRoles1 = array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr', 'username1');
                
        $identity2 = $this->getMock('UnicaenAuth\Entity\Ldap\People', array('getRoles', 'getUsername'));
38
39
40
        $identity2->expects($this->once())
                  ->method('getRoles')
                  ->will($this->returnValue(array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr')));
41
42
43
44
45
        $identity2->expects($this->once())
                  ->method('getUsername')
                  ->will($this->returnValue('username2'));
        
        $expectedRoles2 = array('cn=admin_reseau,ou=groups,dc=unicaen,dc=fr', 'username2');
46
47
        
        return array(
48
49
            'object-identity' => array($identity1, $expectedRoles1),
            'array-identity'  => array(array('ldap' => $identity2), $expectedRoles2),
50
51
52
53
54
55
        );
    }
    
    /**
     * @dataProvider provideAuthServiceIdentity
     */
56
    public function testGettingIdentityRolesReturnsPeopleRoles($identity, $expectedRoles)
57
58
59
60
61
62
63
    {
        $this->authService->expects($this->once())
                          ->method('getIdentity')
                          ->will($this->returnValue($identity));
        
        $roles = $this->provider->getIdentityRoles();
        
64
        $this->assertEquals($expectedRoles, $roles);
65
66
    }
}