UserTest.php 2.15 KB
Newer Older
1
2
3
4
5
<?php

namespace UnicaenAuthTest\Entity\Db;

use UnicaenAuth\Entity\Db\User;
6
use PHPUnit\Framework\TestCase;
7
8
9
10
11
12

/**
 * Description of UserTest
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
13
class UserTest extends TestCase
14
15
{
    protected $user;
16

17
18
19
20
    protected function setUp()
    {
        $this->user = new User();
    }
21

22
23
24
25
26
    public function testImplementsInterfaces()
    {
        $this->assertInstanceOf('ZfcUser\Entity\UserInterface', $this->user);
        $this->assertInstanceOf('BjyAuthorize\Provider\Role\ProviderInterface', $this->user);
    }
27

28
29
    public function testConstructorInitializeRoles()
    {
30
        $this->assertEquals([], $this->user->getRoles());
31
    }
32

33
34
35
36
37
    public function testCanSetId()
    {
        $this->user->setId(12);
        $this->assertEquals(12, $this->user->getId());
    }
38

39
40
41
42
43
    public function testCanSetUsername()
    {
        $this->user->setUsername('content');
        $this->assertEquals('content', $this->user->getUsername());
    }
44

45
46
47
48
49
    public function testCanSetEmail()
    {
        $this->user->setEmail('content');
        $this->assertEquals('content', $this->user->getEmail());
    }
50

51
52
53
54
55
    public function testCanSetDisplayName()
    {
        $this->user->setDisplayName('content');
        $this->assertEquals('content', $this->user->getDisplayName());
    }
56

57
58
59
60
61
    public function testCanSetPassword()
    {
        $this->user->setPassword('content');
        $this->assertEquals('content', $this->user->getPassword());
    }
62

63
64
65
66
67
    public function testCanSetState()
    {
        $this->user->setState(1);
        $this->assertEquals(1, $this->user->getState());
    }
68

69
70
    public function testCanAddRole()
    {
71
        $roles = new \Doctrine\Common\Collections\ArrayCollection([
72
73
                new \UnicaenAuth\Entity\Db\Role(),
                new \UnicaenAuth\Entity\Db\Role(),
74
        ]);
75
76
77
78
        $this->user->addRole($roles[0]);
        $this->user->addRole($roles[1]);
        $this->assertEquals($roles->getValues(), $this->user->getRoles());
    }
79

80
81
82
83
84
85
    public function testCanGetObjectToString()
    {
        $this->user->setDisplayName('content');
        $this->assertEquals('content', (string) $this->user);
    }
}