2015-07-11 01:29:12 +02:00
|
|
|
<?php
|
2021-04-05 09:39:34 +02:00
|
|
|
|
2015-07-11 01:29:12 +02:00
|
|
|
/**
|
|
|
|
* TimeZone's tests
|
|
|
|
*/
|
|
|
|
|
2021-04-05 11:00:28 +02:00
|
|
|
namespace Shaarli\Tests;
|
|
|
|
|
|
|
|
use Shaarli\TestCase;
|
2015-07-11 01:29:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unitary tests for timezone utilities
|
|
|
|
*/
|
2021-04-05 11:00:28 +02:00
|
|
|
class TimeZoneTest extends TestCase
|
2015-07-11 01:29:12 +02:00
|
|
|
{
|
2017-03-22 19:16:35 +01:00
|
|
|
/**
|
|
|
|
* @var array of timezones
|
|
|
|
*/
|
|
|
|
protected $installedTimezones;
|
|
|
|
|
2020-09-26 15:08:39 +02:00
|
|
|
protected function setUp(): void
|
2017-03-22 19:16:35 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|