DbTest.php 2.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
namespace UnicaenAuthTest\Provider\Identity;

/**
 * Description of LdapTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class DbTest extends BaseTest
{
    protected $providerClass = 'UnicaenAuth\Provider\Identity\Db';
    
    public function provideAuthServiceIdentity()
    {
        $role = new \UnicaenAuth\Entity\Db\Role();
        $role->setRoleId('role id');
        
18
        $identity1 = $this->getMock('UnicaenAuth\Entity\Db\User', array('getRoles', 'getUsername'));
19
20
21
        $identity1->expects($this->once())
                  ->method('getRoles')
                  ->will($this->returnValue(array($role)));
22
23
24
25
26
        $identity1->expects($this->once())
                  ->method('getUsername')
                  ->will($this->returnValue($username = 'username1'));
        
        $expectedRoles1 = array($role, $username);
27
28
29
30
        
        $role2 = new \UnicaenAuth\Entity\Db\Role();
        $role2->setRoleId('role id 2');
        
31
        $identity2 = $this->getMock('UnicaenAuth\Entity\Db\User', array('getRoles', 'getUsername'));
32
33
34
        $identity2->expects($this->once())
                  ->method('getRoles')
                  ->will($this->returnValue(array($role)));
35
36
37
        $identity2->expects($this->once())
                  ->method('getUsername')
                  ->will($this->returnValue($username = 'username2'));
38
        
39
        $expectedRoles2 = array($role, $username);
40
41
        
        return array(
42
43
            'object-identity' => array($identity1, $expectedRoles1),
            'array-identity'  => array(array('db' => $identity2), $expectedRoles2),
44
45
46
47
48
49
50
51
52
53
54
        );
    }
    
    /**
     * @dataProvider provideAuthServiceIdentity
     */
    public function testGettingIdentityRolesReturnsPeopleRoles($identity, $expectedRoles)
    {
        $this->authService->expects($this->once())
                          ->method('getIdentity')
                          ->will($this->returnValue($identity));
55
                  
56
57
58
59
60
        $roles = $this->provider->getIdentityRoles();
        
        $this->assertEquals($expectedRoles, $roles);
    }
}