2013-06-07 12:40:21 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-06-07 12:40:21 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
namespace Tests\Icinga;
|
2013-08-06 18:02:40 +02:00
|
|
|
|
2014-04-22 09:43:53 +02:00
|
|
|
use Mockery;
|
|
|
|
use DateTimeZone;
|
2014-04-10 10:32:50 +02:00
|
|
|
use Icinga\User;
|
|
|
|
use Icinga\Test\BaseTestCase;
|
2013-08-06 18:02:40 +02:00
|
|
|
|
2014-04-10 10:32:50 +02:00
|
|
|
class UserTest extends BaseTestCase
|
2013-06-07 12:40:21 +02:00
|
|
|
{
|
2013-08-06 18:02:40 +02:00
|
|
|
public function testGetDefaultTimezoneIfTimezoneNotSet()
|
|
|
|
{
|
2014-04-10 10:32:50 +02:00
|
|
|
$user = new User('unittest');
|
2014-04-22 09:43:53 +02:00
|
|
|
$prefs = Mockery::mock('Icinga\User\Preferences');
|
|
|
|
$prefs->shouldReceive('get')->with('timezone')->andReturnNull();
|
2013-08-06 18:02:40 +02:00
|
|
|
$user->setPreferences($prefs);
|
2014-04-22 09:43:53 +02:00
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
new DateTimeZone(date_default_timezone_get()),
|
|
|
|
$user->getTimeZone(),
|
2013-08-06 18:02:40 +02:00
|
|
|
'User\'s timezone does not match the default timezone'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetTimezoneIfTimezoneSet()
|
|
|
|
{
|
|
|
|
$explicitTz = 'Europe/Berlin';
|
2014-04-10 10:32:50 +02:00
|
|
|
$user = new User('unittest');
|
2014-04-22 09:43:53 +02:00
|
|
|
$prefs = Mockery::mock('Icinga\User\Preferences');
|
|
|
|
$prefs->shouldReceive('get')->with('timezone')->andReturn($explicitTz);
|
2013-08-06 18:02:40 +02:00
|
|
|
$user->setPreferences($prefs);
|
2013-08-20 11:27:25 +02:00
|
|
|
|
2014-04-22 09:43:53 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
new DateTimeZone($explicitTz),
|
|
|
|
$user->getTimeZone(),
|
2013-08-06 18:02:40 +02:00
|
|
|
'User\'s timezone does not match the timezone set by himself'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-04-22 09:43:53 +02:00
|
|
|
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');
|
|
|
|
}
|
2014-09-18 14:37:18 +02:00
|
|
|
|
|
|
|
public function testPermissions()
|
|
|
|
{
|
|
|
|
$user = new User('test');
|
|
|
|
$user->setPermissions(array(
|
|
|
|
'test',
|
|
|
|
'test/some/specific',
|
2015-05-05 12:36:26 +02:00
|
|
|
'test/more/*',
|
2015-06-02 12:01:02 +02:00
|
|
|
'test/wildcard-with-wildcard/*',
|
|
|
|
'test/even-more/specific-with-wildcard/*'
|
2014-09-18 14:37:18 +02:00
|
|
|
));
|
|
|
|
$this->assertTrue($user->can('test'));
|
|
|
|
$this->assertTrue($user->can('test/some/specific'));
|
|
|
|
$this->assertTrue($user->can('test/more/everything'));
|
2015-05-05 12:36:26 +02:00
|
|
|
$this->assertTrue($user->can('test/wildcard-with-wildcard/*'));
|
2015-05-07 17:19:00 +02:00
|
|
|
$this->assertTrue($user->can('test/wildcard-with-wildcard/sub/sub'));
|
2015-06-02 12:01:02 +02:00
|
|
|
$this->assertTrue($user->can('test/even-more/*'));
|
2014-09-18 14:37:18 +02:00
|
|
|
$this->assertFalse($user->can('not/test'));
|
|
|
|
$this->assertFalse($user->can('test/some/not/so/specific'));
|
2015-05-05 12:36:26 +02:00
|
|
|
$this->assertFalse($user->can('test/wildcard2/*'));
|
2014-09-18 14:37:18 +02:00
|
|
|
}
|
2013-06-07 12:40:21 +02:00
|
|
|
}
|