-
Notifications
You must be signed in to change notification settings - Fork 275
/
UserTest.php
81 lines (71 loc) · 2.49 KB
/
UserTest.php
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
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Tests\Icinga;
use Mockery;
use DateTimeZone;
use Icinga\User;
use Icinga\Test\BaseTestCase;
class UserTest extends BaseTestCase
{
public function testGetDefaultTimezoneIfTimezoneNotSet()
{
$user = new User('unittest');
$prefs = Mockery::mock('Icinga\User\Preferences');
$prefs->shouldReceive('get')->with('timezone')->andReturnNull();
$user->setPreferences($prefs);
$this->assertEquals(
new DateTimeZone(date_default_timezone_get()),
$user->getTimeZone(),
'User\'s timezone does not match the default timezone'
);
}
public function testGetTimezoneIfTimezoneSet()
{
$explicitTz = 'Europe/Berlin';
$user = new User('unittest');
$prefs = Mockery::mock('Icinga\User\Preferences');
$prefs->shouldReceive('get')->with('timezone')->andReturn($explicitTz);
$user->setPreferences($prefs);
$this->assertEquals(
new DateTimeZone($explicitTz),
$user->getTimeZone(),
'User\'s timezone does not match the timezone set by himself'
);
}
public function testWhetherValidEmailsCanBeSet()
{
$user = new User('unittest');
$user->setEmail('mySampleEmail@someDomain.org');
$this->assertEquals(
$user->getEmail(),
'mySampleEmail@someDomain.org',
'Valid emails set with setEmail are not returned by getEmail'
);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testWhetherInvalidEmailsCannotBeSet()
{
$user = new User('unittest');
$user->setEmail('mySampleEmail at someDomain dot org');
}
public function testPermissions()
{
$user = new User('test');
$user->setPermissions(array(
'test',
'test/some/specific',
'test/more/*',
'test/wildcard-with-wildcard/*'
));
$this->assertTrue($user->can('test'));
$this->assertTrue($user->can('test/some/specific'));
$this->assertTrue($user->can('test/more/everything'));
$this->assertTrue($user->can('test/wildcard-with-wildcard/*'));
$this->assertTrue($user->can('test/wildcard/sub/sub'));
$this->assertFalse($user->can('not/test'));
$this->assertFalse($user->can('test/some/not/so/specific'));
$this->assertFalse($user->can('test/wildcard2/*'));
}
}