Framework/User: Implement getTimezone to retrieve the user's Timezone
refs #4440
This commit is contained in:
parent
9170523afa
commit
8af901e9ed
|
@ -316,4 +316,20 @@ class User
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the user's timezone
|
||||
*
|
||||
* If the user did not set a timezone, the default timezone set via config.ini will be returned
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTimezone()
|
||||
{
|
||||
$tz = $this->preferences->get('timezone');
|
||||
if ($tz === null) {
|
||||
$tz = date_default_timezone_get();
|
||||
}
|
||||
return $tz;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,67 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga;
|
||||
/**
|
||||
*
|
||||
* Test class for User
|
||||
* Created Fri, 07 Jun 2013 10:38:16 +0000
|
||||
*
|
||||
**/
|
||||
|
||||
require_once __DIR__ . '/../../../../library/Icinga/User.php';
|
||||
require_once __DIR__ . '/../../../../library/Icinga/User/Preferences.php';
|
||||
require_once __DIR__ . '/../../../../library/Icinga/User/Preferences/ChangeSet.php';
|
||||
|
||||
use Icinga\User as IcingaUser;
|
||||
use Icinga\User\Preferences as UserPreferences;
|
||||
|
||||
class UserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for User::ListGroups()
|
||||
*
|
||||
**/
|
||||
public function testListGroups()
|
||||
{
|
||||
$this->markTestIncomplete('testListGroups is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for User::IsMemberOf()
|
||||
*
|
||||
**/
|
||||
public function testIsMemberOf()
|
||||
{
|
||||
$this->markTestIncomplete('testIsMemberOf is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for User::GetPermissionList()
|
||||
*
|
||||
**/
|
||||
public function testGetPermissionList()
|
||||
{
|
||||
$this->markTestIncomplete('testGetPermissionList is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for User::HasPermission()
|
||||
*
|
||||
**/
|
||||
public function testHasPermission()
|
||||
{
|
||||
$this->markTestIncomplete('testHasPermission is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for User::GrantPermission()
|
||||
*
|
||||
**/
|
||||
public function testGrantPermission()
|
||||
{
|
||||
$this->markTestIncomplete('testGrantPermission is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for User::RevokePermission()
|
||||
*
|
||||
**/
|
||||
public function testRevokePermission()
|
||||
{
|
||||
$this->markTestIncomplete('testRevokePermission is not implemented yet');
|
||||
}
|
||||
|
||||
public function testGetDefaultTimezoneIfTimezoneNotSet()
|
||||
{
|
||||
$defaultTz = 'UTC';
|
||||
date_default_timezone_set($defaultTz);
|
||||
$user = new IcingaUser('unittest');
|
||||
$prefs = new UserPreferences(array());
|
||||
$user->setPreferences($prefs);
|
||||
$this->assertEquals($user->getTimezone(), $defaultTz,
|
||||
'User\'s timezone does not match the default timezone'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetTimezoneIfTimezoneSet()
|
||||
{
|
||||
$defaultTz = 'UTC';
|
||||
$explicitTz = 'Europe/Berlin';
|
||||
date_default_timezone_set($defaultTz);
|
||||
$user = new IcingaUser('unittest');
|
||||
$prefs = new UserPreferences(array(
|
||||
'timezone' => $explicitTz
|
||||
));
|
||||
$user->setPreferences($prefs);
|
||||
$this->assertEquals($user->getTimezone(), $explicitTz,
|
||||
'User\'s timezone does not match the timezone set by himself'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue