Skip to content
Snippets Groups Projects
Commit b31d663c authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Complete unit testing for SimpleSAML\Utils\Time by adding test for initTimezone().

parent 0b4413ac
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,49 @@ class TimeTest extends \PHPUnit_Framework_TestCase
}
/**
* Test the SimpleSAML\Utils\Time::initTimezone() method.
*
* @covers SimpleSAML\Utils\Time::initTimezone
*/
public function testInitTimezon()
{
$tz = 'UTC';
if (@date_default_timezone_get() === 'UTC') { // avoid collisions
$tz = 'Europe/Oslo';
}
// test guessing timezone from the OS
\SimpleSAML_Configuration::loadFromArray(array('timezone' => 'Europe/Madrid'), '[ARRAY]', 'simplesaml');
@Time::initTimezone();
$this->assertEquals('Europe/Madrid', @date_default_timezone_get());
// clear initialization
$c = new \ReflectionProperty('\SimpleSAML\Utils\Time', 'tz_initialized');
$c->setAccessible(true);
$c->setValue(false);
// test unknown timezone
\SimpleSAML_Configuration::loadFromArray(array('timezone' => 'INVALID'), '[ARRAY]', 'simplesaml');
try {
@Time::initTimezone();
$this->fail('Failed to recognize an invalid timezone.');
} catch (\SimpleSAML_Error_Exception $e) {
$this->assertEquals('Invalid timezone set in the "timezone" option in config.php.', $e->getMessage());
}
// test a valid timezone
\SimpleSAML_Configuration::loadFromArray(array('timezone' => $tz), '[ARRAY]', 'simplesaml');
@Time::initTimezone();
$this->assertEquals($tz, @date_default_timezone_get());
// make sure initialization happens only once
\SimpleSAML_Configuration::loadFromArray(array('timezone' => 'Europe/Madrid'), '[ARRAY]', 'simplesaml');
@Time::initTimezone();
$this->assertEquals($tz, @date_default_timezone_get());
}
/**
* Test the SimpleSAML\Utils\Time::parseDuration() method.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment