UserTest.php 2.22 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
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
<?php

namespace UnicaenAuthTest\Entity\Db;

use UnicaenAuth\Entity\Db\User;
use PHPUnit_Framework_TestCase;

/**
 * Description of UserTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class UserTest extends PHPUnit_Framework_TestCase
{
    protected $user;
    
    protected function setUp()
    {
        $this->user = new User();
    }
    
    public function testImplementsInterfaces()
    {
        $this->assertInstanceOf('ZfcUser\Entity\UserInterface', $this->user);
        $this->assertInstanceOf('BjyAuthorize\Provider\Role\ProviderInterface', $this->user);
    }
    
    public function testConstructorInitializeRoles()
    {
        $this->assertEquals(array(), $this->user->getRoles());
    }
    
    public function testCanSetId()
    {
        $this->user->setId(12);
        $this->assertEquals(12, $this->user->getId());
    }
    
    public function testCanSetUsername()
    {
        $this->user->setUsername('content');
        $this->assertEquals('content', $this->user->getUsername());
    }
    
    public function testCanSetEmail()
    {
        $this->user->setEmail('content');
        $this->assertEquals('content', $this->user->getEmail());
    }
    
    public function testCanSetDisplayName()
    {
        $this->user->setDisplayName('content');
        $this->assertEquals('content', $this->user->getDisplayName());
    }
    
    public function testCanSetPassword()
    {
        $this->user->setPassword('content');
        $this->assertEquals('content', $this->user->getPassword());
    }
    
    public function testCanSetState()
    {
        $this->user->setState(1);
        $this->assertEquals(1, $this->user->getState());
    }
    
    public function testCanAddRole()
    {
        $roles = new \Doctrine\Common\Collections\ArrayCollection(array(
                new \UnicaenAuth\Entity\Db\Role(),
                new \UnicaenAuth\Entity\Db\Role(),
        ));
        $this->user->addRole($roles[0]);
        $this->user->addRole($roles[1]);
        $this->assertEquals($roles->getValues(), $this->user->getRoles());
    }
    
    public function testCanGetObjectToString()
    {
        $this->user->setDisplayName('content');
        $this->assertEquals('content', (string) $this->user);
    }
}