PeopleAdapterTest.php 3.16 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
27
28
29
30
31
32
<?php
namespace UnicaenAuthTest\Entity\Ldap;

use UnicaenAuth\Entity\Ldap\PeopleAdapter;
use UnicaenAppTest\Entity\Ldap\TestAsset\People as PeopleTestAsset;

/**
 * Description of PeopleAdapterTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class PeopleAdapterTest extends \PHPUnit_Framework_TestCase
{
    protected $entity;
    
    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
        $this->entity = new PeopleAdapter(PeopleTestAsset::$data1, 12);
    }
    
    public function testSuperClassAndInterface()
    {
        $this->assertInstanceOf('UnicaenApp\Entity\Ldap\People', $this->entity);
        $this->assertInstanceOf('ZfcUser\Entity\UserInterface', $this->entity);
    }
    
    public function testConstrutorSetsSpecifiedUserId()
    {
33
34
        $entity = new PeopleAdapter(PeopleTestAsset::$data1, $id = 12);
        $this->assertEquals($id, $entity->getId());
35
36
    }
    
Bertrand Gauthier's avatar
Bertrand Gauthier committed
37
    public function testGettingIdReturnsLdapUidAsDefaultValue()
38
39
40
41
42
43
44
45
46
47
48
49
50
    {
        $entity = new PeopleAdapter(PeopleTestAsset::$data1);
        $this->assertEquals(PeopleTestAsset::$data1['uid'], $entity->getId());
    }
    
    public function testStateDependsOnDeactivatedLdapBranch()
    {
        $this->assertEquals(1, $this->entity->getState());
        
        $entity = new PeopleAdapter(PeopleTestAsset::$dataDeactivated, 12);
        $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
    public function testGetUsernameReturnsSupannAliasLogin()
    {
        $this->assertEquals(PeopleTestAsset::$data1['supannaliaslogin'], $this->entity->getUsername());
    }
    
92
93
94
95
96
97
98
99
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingUsernameThrowsException()
    {
        $this->entity->setUsername('whatever');
    }
    
100
101
102
103
104
    public function testGetPasswordReturnsNull()
    {
        $entity = new PeopleAdapter(PeopleTestAsset::$data1);
        $this->assertNull($entity->getPassword());
    }
105
106
107
108
109
110
111
112
    
    /**
     * @expectedException \BadMethodCallException
     */
    public function testSettingPasswordThrowsException()
    {
        $this->entity->setPassword('whatever');
    }
113
}