2015-07-11 01:29:12 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TimeZone's tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once 'application/TimeZone.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unitary tests for timezone utilities
|
|
|
|
*/
|
2019-01-12 23:55:38 +01:00
|
|
|
class TimeZoneTest extends PHPUnit\Framework\TestCase
|
2015-07-11 01:29:12 +02:00
|
|
|
{
|
2017-03-22 19:16:35 +01:00
|
|
|
/**
|
|
|
|
* @var array of timezones
|
|
|
|
*/
|
|
|
|
protected $installedTimezones;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->installedTimezones = [
|
|
|
|
'Antarctica/Syowa',
|
|
|
|
'Europe/London',
|
|
|
|
'Europe/Paris',
|
|
|
|
'UTC'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-07-11 01:29:12 +02:00
|
|
|
/**
|
|
|
|
* Generate a timezone selection form
|
|
|
|
*/
|
|
|
|
public function testGenerateTimeZoneForm()
|
|
|
|
{
|
2017-03-22 19:16:35 +01:00
|
|
|
$expected = [
|
|
|
|
'continents' => [
|
|
|
|
'Antarctica',
|
|
|
|
'Europe',
|
|
|
|
'UTC',
|
|
|
|
'selected' => '',
|
|
|
|
],
|
|
|
|
'cities' => [
|
|
|
|
['continent' => 'Antarctica', 'city' => 'Syowa'],
|
|
|
|
['continent' => 'Europe', 'city' => 'London'],
|
|
|
|
['continent' => 'Europe', 'city' => 'Paris'],
|
|
|
|
['continent' => 'UTC', 'city' => 'UTC'],
|
|
|
|
'selected' => '',
|
|
|
|
]
|
|
|
|
];
|
2015-07-11 01:29:12 +02:00
|
|
|
|
2017-03-22 19:16:35 +01:00
|
|
|
list($continents, $cities) = generateTimeZoneData($this->installedTimezones);
|
2015-07-11 01:29:12 +02:00
|
|
|
|
2017-03-22 19:16:35 +01:00
|
|
|
$this->assertEquals($expected['continents'], $continents);
|
|
|
|
$this->assertEquals($expected['cities'], $cities);
|
2015-07-11 01:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a timezone selection form, with a preselected timezone
|
|
|
|
*/
|
|
|
|
public function testGenerateTimeZoneFormPreselected()
|
|
|
|
{
|
2017-03-22 19:16:35 +01:00
|
|
|
$expected = [
|
|
|
|
'continents' => [
|
|
|
|
'Antarctica',
|
|
|
|
'Europe',
|
|
|
|
'UTC',
|
|
|
|
'selected' => 'Antarctica',
|
|
|
|
],
|
|
|
|
'cities' => [
|
|
|
|
['continent' => 'Antarctica', 'city' => 'Syowa'],
|
|
|
|
['continent' => 'Europe', 'city' => 'London'],
|
|
|
|
['continent' => 'Europe', 'city' => 'Paris'],
|
|
|
|
['continent' => 'UTC', 'city' => 'UTC'],
|
|
|
|
'selected' => 'Syowa',
|
|
|
|
]
|
|
|
|
];
|
2015-07-11 01:29:12 +02:00
|
|
|
|
2017-03-22 19:16:35 +01:00
|
|
|
list($continents, $cities) = generateTimeZoneData($this->installedTimezones, 'Antarctica/Syowa');
|
2015-07-11 01:29:12 +02:00
|
|
|
|
2017-03-22 19:16:35 +01:00
|
|
|
$this->assertEquals($expected['continents'], $continents);
|
|
|
|
$this->assertEquals($expected['cities'], $cities);
|
2015-07-11 01:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check valid timezones
|
|
|
|
*/
|
|
|
|
public function testValidTimeZone()
|
|
|
|
{
|
|
|
|
$this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia'));
|
|
|
|
$this->assertTrue(isTimeZoneValid('Europe', 'Oslo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check invalid timezones
|
|
|
|
*/
|
|
|
|
public function testInvalidTimeZone()
|
|
|
|
{
|
|
|
|
$this->assertFalse(isTimeZoneValid('CEST', 'CEST'));
|
|
|
|
$this->assertFalse(isTimeZoneValid('Europe', 'Atlantis'));
|
|
|
|
$this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria'));
|
2016-05-03 20:09:24 +02:00
|
|
|
$this->assertFalse(isTimeZoneValid('UTC', 'UTC'));
|
2015-07-11 01:29:12 +02:00
|
|
|
}
|
|
|
|
}
|