1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2015 Michael Giesler |
4
|
|
|
* |
5
|
|
|
* This file is part of Dembelo. |
6
|
|
|
* |
7
|
|
|
* Dembelo is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Dembelo is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License 3 for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License 3 |
18
|
|
|
* along with Dembelo. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @package DembeloMain |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace DembeloMain\Tests\Document; |
27
|
|
|
|
28
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
29
|
|
|
use DembeloMain\Document\User; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class DocumentUserTest |
33
|
|
|
*/ |
34
|
|
|
class UserTest extends WebTestCase |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var User |
38
|
|
|
*/ |
39
|
|
|
private $user; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* setUp method |
43
|
|
|
*/ |
44
|
|
|
public function setUp() |
45
|
|
|
{ |
46
|
|
|
$this->user = new User(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* a generic test for all class properties |
51
|
|
|
*/ |
52
|
|
|
public function testGenericMethods() |
53
|
|
|
{ |
54
|
|
|
$properties = array('id', 'email', 'licenseeId', 'currentTextnode', 'gender', 'source', 'reason', 'password', 'status', 'activationHash'); |
55
|
|
|
|
56
|
|
|
foreach ($properties as $property) { |
57
|
|
|
$getter = 'get'.ucfirst($property); |
58
|
|
|
$setter = 'set'.ucfirst($property); |
59
|
|
|
$string = @tempnam($property, 'hrz'); |
60
|
|
|
$this->assertNull($this->user->$getter()); |
61
|
|
|
$this->user->$setter($string); |
62
|
|
|
$this->assertEquals($string, $this->user->$getter()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* tests getUsername() |
68
|
|
|
*/ |
69
|
|
|
public function testGetUsernameShouldEqualEmail() |
70
|
|
|
{ |
71
|
|
|
$this->user->setEmail('test'); |
72
|
|
|
$this->assertEquals('test', $this->user->getUsername()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* tests getSalt() |
77
|
|
|
*/ |
78
|
|
|
public function testGetSaltShouldBeNull() |
79
|
|
|
{ |
80
|
|
|
$this->assertNull($this->user->getSalt()); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* tests setRoles() |
85
|
|
|
*/ |
86
|
|
|
public function testGetRolesShouldEqualSetRoles() |
87
|
|
|
{ |
88
|
|
|
$this->user->setRoles(array('test')); |
89
|
|
|
$this->assertEquals(array('test'), $this->user->getRoles()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* tests setRoles() with a non array as argument |
94
|
|
|
*/ |
95
|
|
|
public function testGetRolesShouldBeArray() |
96
|
|
|
{ |
97
|
|
|
$this->user->setRoles('test'); |
98
|
|
|
$this->assertEquals(array('test'), $this->user->getRoles()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* tests serialize() |
103
|
|
|
*/ |
104
|
|
|
public function testSerialize() |
105
|
|
|
{ |
106
|
|
|
$this->user->setId('id'); |
107
|
|
|
$this->user->setEmail('email'); |
108
|
|
|
$this->user->setPassword('pw'); |
109
|
|
|
$this->user->setCurrentTextnode('55cd2a9808985ca80c3c9877'); |
110
|
|
|
$this->assertEquals(serialize(array('id', 'email', 'pw', '55cd2a9808985ca80c3c9877')), $this->user->serialize()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* tests unserialize() |
115
|
|
|
*/ |
116
|
|
|
public function testUnserialize() |
117
|
|
|
{ |
118
|
|
|
$serialized = serialize(array('id', 'email', 'pw', '55cd2a9808985ca80c3c9877')); |
119
|
|
|
$this->user->unserialize($serialized); |
120
|
|
|
$this->assertEquals('id', $this->user->getId()); |
121
|
|
|
$this->assertEquals('email', $this->user->getEmail()); |
122
|
|
|
$this->assertEquals('pw', $this->user->getPassword()); |
123
|
|
|
$this->assertEquals('55cd2a9808985ca80c3c9877', $this->user->getCurrentTextnode()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* tests eraseCredentials() |
128
|
|
|
*/ |
129
|
|
|
public function testEraseCredentials() |
130
|
|
|
{ |
131
|
|
|
$this->assertNull($this->user->eraseCredentials()); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* tests isAccountNonExpired |
136
|
|
|
*/ |
137
|
|
|
public function testIsAccountNonExpired() |
138
|
|
|
{ |
139
|
|
|
$this->assertTrue($this->user->isAccountNonExpired()); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* tests isAccountNonLocked |
144
|
|
|
*/ |
145
|
|
|
public function testIsAccountNonLocked() |
146
|
|
|
{ |
147
|
|
|
$this->assertTrue($this->user->isAccountNonLocked()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* tests isCredentialsNonExpired |
152
|
|
|
*/ |
153
|
|
|
public function testIsCredentialsNonExpired() |
154
|
|
|
{ |
155
|
|
|
$this->assertTrue($this->user->isCredentialsNonExpired()); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* tests isEnabled for not set status |
160
|
|
|
*/ |
161
|
|
|
public function testIsEnabledDefault() |
162
|
|
|
{ |
163
|
|
|
$this->assertFalse($this->user->isEnabled()); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* tests isEnabled for status = 0 |
168
|
|
|
*/ |
169
|
|
|
public function testIsEnabledForStatusZero() |
170
|
|
|
{ |
171
|
|
|
$this->user->setStatus(0); |
172
|
|
|
$this->assertFalse($this->user->isEnabled()); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* tests isEnabled for status = 1 |
177
|
|
|
*/ |
178
|
|
|
public function testIsEnabledForStatusOne() |
179
|
|
|
{ |
180
|
|
|
$this->user->setStatus(1); |
181
|
|
|
$this->assertTrue($this->user->isEnabled()); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.