PeopleTest.php 3.53 KB
Newer Older
1
2
3
<?php
namespace UnicaenAuthTest\Entity\Ldap;

4
5
use UnicaenApp\Entity\Ldap\People as BasePeople;
use UnicaenAuth\Entity\Ldap\People;
6
7
8
use UnicaenAppTest\Entity\Ldap\TestAsset\People as PeopleTestAsset;

/**
9
 * Description of PeopleTest
10
11
12
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
13
class PeopleTest extends \PHPUnit_Framework_TestCase
14
15
16
17
18
19
20
21
22
{
    protected $entity;
    
    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
23
        $this->entity = new People(PeopleTestAsset::$data1);
24
25
    }
    
26
    public function testCanConstructFromBasePeopleEntity()
27
    {
28
        new People(new BasePeople(PeopleTestAsset::$data1));
29
30
    }
    
31
    public function testSuperClassAndInterface()
32
    {
33
34
        $this->assertInstanceOf('UnicaenApp\Entity\Ldap\People', $this->entity);
        $this->assertInstanceOf('ZfcUser\Entity\UserInterface', $this->entity);
35
36
    }
    
Bertrand Gauthier's avatar
Bertrand Gauthier committed
37
    public function testGettingIdReturnsLdapUidAsDefaultValue()
38
    {
39
        $entity = new People(PeopleTestAsset::$data1);
40
41
42
43
44
45
46
        $this->assertEquals(PeopleTestAsset::$data1['uid'], $entity->getId());
    }
    
    public function testStateDependsOnDeactivatedLdapBranch()
    {
        $this->assertEquals(1, $this->entity->getState());
        
47
        $entity = new People(PeopleTestAsset::$dataDeactivated, 12);
48
49
50
        $this->assertEquals(0, $entity->getState());
    }
    
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
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingStateThrowsException()
    {
        $this->entity->setState('whatever');
    }
    
    public function testGetDisplayNameReturnsString()
    {
        $this->assertInternalType('string', $this->entity->getDisplayName());
        $this->assertNotEmpty($this->entity->getDisplayName());
    }
    
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingDisplayNameThrowsException()
    {
        $this->entity->setDisplayName('whatever');
    }
    
    public function testGetEmailReturnsString()
    {
        $this->assertInternalType('string', $this->entity->getEmail());
        $this->assertNotEmpty($this->entity->getEmail());
    }
    
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingEmailThrowsException()
    {
        $this->entity->setEmail('whatever');
    }
    
87
88
89
90
91
92
93
94
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingIdThrowsException()
    {
        $this->entity->setId('whatever');
    }
    
95
96
97
98
99
    public function testGetUsernameReturnsSupannAliasLogin()
    {
        $this->assertEquals(PeopleTestAsset::$data1['supannaliaslogin'], $this->entity->getUsername());
    }
    
100
101
102
103
104
105
106
107
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingUsernameThrowsException()
    {
        $this->entity->setUsername('whatever');
    }
    
108
109
    public function testGetPasswordReturnsNull()
    {
110
        $entity = new People(PeopleTestAsset::$data1);
111
112
        $this->assertNull($entity->getPassword());
    }
113
114
115
116
117
118
119
120
    
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingPasswordThrowsException()
    {
        $this->entity->setPassword('whatever');
    }
121
    
122
    public function testGettingRolesContainsMembershipAndSupannRole()
123
    {
124
125
126
        $this->assertEquals(
                array_merge($this->entity->getMemberOf(), $this->entity->getSupannRolesEntite()), 
                $this->entity->getRoles());
127
    }
128
}