|
1
|
|
|
<?php |
|
2
|
|
|
require_once 'Intraface/User.php'; |
|
3
|
|
|
require_once 'Intraface/modules/intranetmaintenance/ModuleMaintenance.php'; |
|
4
|
|
|
require_once 'Intraface/modules/intranetmaintenance/UserMaintenance.php'; |
|
5
|
|
|
require_once 'Intraface/modules/intranetmaintenance/IntranetMaintenance.php'; |
|
6
|
|
|
require_once 'Intraface/Validator.php'; |
|
7
|
|
|
|
|
8
|
|
|
class UserTest extends PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
private $user; |
|
11
|
|
|
|
|
12
|
|
|
function setUp() |
|
13
|
|
|
{ |
|
14
|
|
|
$db = MDB2::singleton(DB_DSN); |
|
15
|
|
|
$db->exec('TRUNCATE user'); |
|
16
|
|
|
$db->exec('TRUNCATE intranet'); |
|
17
|
|
|
$db->exec('TRUNCATE modules'); |
|
18
|
|
|
$db->exec('TRUNCATE permission'); |
|
19
|
|
|
|
|
20
|
|
|
// @todo this has the notion with the standard database setup |
|
21
|
|
|
$u = new UserMaintenance(); |
|
22
|
|
|
$u->update(array('email' => '[email protected]', 'password' => '123456', 'confirm_password' => '123456', 'disabled' => 0)); |
|
23
|
|
|
|
|
24
|
|
|
$i = new IntranetMaintenance(); |
|
25
|
|
|
$i->save(array('name' => 'intraface', 'identifier' => 'intraface')); |
|
26
|
|
|
|
|
27
|
|
|
$m = new ModuleMaintenance(); |
|
28
|
|
|
$result = $m->register(); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
$this->user = new Intraface_User(1); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function tearDown() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->user = null; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
//////////////////////////////////////////////////////////////////////////// |
|
39
|
|
|
|
|
40
|
|
|
function testConstructionOfUser() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertTrue(is_object($this->user)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function testIntranetAccessReturnsTrueWhenTheUserHasIntranetAccessAndFalseIfNot() |
|
46
|
|
|
{ |
|
47
|
|
|
$u = new UserMaintenance(1); |
|
48
|
|
|
$u->setIntranetAccess(1); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertTrue($this->user->hasIntranetAccess(1)); |
|
51
|
|
|
$this->assertFalse($this->user->hasIntranetAccess(2)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function testUserModuleAccessOnlyWorksWhenTheUserHasAnActiveIntranetId() |
|
55
|
|
|
{ |
|
56
|
|
|
$u = new UserMaintenance(1); |
|
57
|
|
|
$u->setModuleAccess('intranetmaintenance', 1); |
|
58
|
|
|
|
|
59
|
|
|
// TODO how should we handle unknown modules |
|
60
|
|
|
// TODO and setup modules we can count on for the test |
|
61
|
|
|
$this->assertFalse($this->user->hasModuleAccess('intranetmaintenance')); |
|
62
|
|
|
$this->assertFalse($this->user->hasModuleAccess('todo')); |
|
63
|
|
|
$this->user->setIntranetId(1); // sp�rgsm�let er om man bare skal have en init i stedet? |
|
64
|
|
|
$this->assertTrue($this->user->hasModuleAccess('intranetmaintenance')); |
|
65
|
|
|
$this->assertFalse($this->user->hasModuleAccess('todo')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function testSubAccessReturnsFalseOnANotInitializedSubAccess() |
|
69
|
|
|
{ |
|
70
|
|
|
$u = new UserMaintenance(1); |
|
71
|
|
|
$u->setIntranetAccess(1); |
|
72
|
|
|
$this->assertFalse($this->user->hasSubAccess(1, 1)); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function testSetActiveIntranetReturnsAValueLargerThanZero() |
|
76
|
|
|
{ |
|
77
|
|
|
$u = new UserMaintenance(1); |
|
78
|
|
|
$u->setModuleAccess('intranetmaintenance', 1); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertTrue($this->user->setActiveIntranetId(1) > 0); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function testGetPermissionsReturnsAnArray() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->assertTrue(is_array($this->user->getPermissions())); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
function testHasModuleAccessReturnsTrueOnAccess() |
|
89
|
|
|
{ |
|
90
|
|
|
$u = new UserMaintenance(1); |
|
91
|
|
|
$u->setModuleAccess('intranetmaintenance', 1); |
|
92
|
|
|
|
|
93
|
|
|
$this->user->setIntranetId(1); |
|
94
|
|
|
$this->assertTrue($this->user->hasModuleAccess('intranetmaintenance')); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
function testHasModuleAccessReturnsFalseIfAccessIsNotGranted() |
|
98
|
|
|
{ |
|
99
|
|
|
$u = new UserMaintenance(1); |
|
100
|
|
|
$u->setIntranetAccess(1); |
|
101
|
|
|
$this->user->setIntranetId(1); |
|
102
|
|
|
$this->assertFalse($this->user->hasModuleAccess('todo')); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
function testClearCachedPermissionsEmptiesPermissionArrayAndSetsPermissionLoadedToFalse() |
|
106
|
|
|
{ |
|
107
|
|
|
$u = new UserMaintenance(1); |
|
108
|
|
|
$u->setIntranetAccess(1); |
|
109
|
|
|
|
|
110
|
|
|
$this->user->setIntranetId(1); |
|
111
|
|
|
$this->user->clearCachedPermission(); |
|
112
|
|
|
$this->assertEquals(0, count($this->user->getPermissions())); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
function testGetAddressReturnsObject() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->assertTrue(is_object($this->user->getAddress())); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @todo Is this correct? |
|
122
|
|
|
*/ |
|
123
|
|
|
function testGetActiveIntranetIdReturnsCorrectIntranetIdEvenBeforeItIsSpecificallySetBySetActiveIntranetId() |
|
124
|
|
|
{ |
|
125
|
|
|
$u = new UserMaintenance(1); |
|
126
|
|
|
$u->setIntranetAccess(1); |
|
127
|
|
|
$this->assertEquals(1, $this->user->getActiveIntranetId()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
function testGetActiveIntranetIdReturnsActiveIdWhenFirstSetBySetActiveIntranetId() |
|
131
|
|
|
{ |
|
132
|
|
|
$u = new UserMaintenance(1); |
|
133
|
|
|
$u->setIntranetAccess(1); |
|
134
|
|
|
|
|
135
|
|
|
$this->user->setActiveIntranetId(1); |
|
136
|
|
|
$this->assertEquals(1, $this->user->getActiveIntranetId()); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
function testIsFilledInReturnsFalseWhenNothingHasBeenDoneToSetupTheUser() |
|
140
|
|
|
{ |
|
141
|
|
|
$u = new UserMaintenance(1); |
|
142
|
|
|
$u->setIntranetAccess(1); |
|
143
|
|
|
$this->assertFalse($this->user->isFilledIn()); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
View Code Duplication |
function testUpdatePasswordReturnsTrue() |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
|
|
$u = new UserMaintenance(1); |
|
149
|
|
|
$u->setIntranetAccess(1); |
|
150
|
|
|
|
|
151
|
|
|
$old = '123456'; |
|
152
|
|
|
$new = 'newpass'; |
|
153
|
|
|
|
|
154
|
|
|
$this->assertTrue($this->user->updatePassword($old, $new, $new)); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
View Code Duplication |
function testUpdatePasswordReturnsFalseIfNewPasswordsDoNotMatch() |
|
|
|
|
|
|
158
|
|
|
{ |
|
159
|
|
|
$u = new UserMaintenance(1); |
|
160
|
|
|
$u->setIntranetAccess(1); |
|
161
|
|
|
|
|
162
|
|
|
$old = '123456'; |
|
163
|
|
|
$new = 'newpass'; |
|
164
|
|
|
$new1 = 'nomatch'; |
|
165
|
|
|
|
|
166
|
|
|
$this->assertFalse($this->user->updatePassword($old, $new, $new1)); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
function testGetIdReturnsTheIdOfTheUSer() |
|
170
|
|
|
{ |
|
171
|
|
|
$this->assertEquals(1, $this->user->getId()); |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.