]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/TimeZoneTest.php
fix a11y label
[github/shaarli/Shaarli.git] / tests / TimeZoneTest.php
CommitLineData
d1e2f8e5
V
1<?php
2/**
3 * TimeZone's tests
4 */
5
6require_once 'application/TimeZone.php';
7
8/**
9 * Unitary tests for timezone utilities
10 */
dea72c71 11class TimeZoneTest extends PHPUnit\Framework\TestCase
d1e2f8e5 12{
ae3aa968
A
13 /**
14 * @var array of timezones
15 */
16 protected $installedTimezones;
17
18 public function setUp()
19 {
20 $this->installedTimezones = [
21 'Antarctica/Syowa',
22 'Europe/London',
23 'Europe/Paris',
24 'UTC'
25 ];
26 }
27
d1e2f8e5
V
28 /**
29 * Generate a timezone selection form
30 */
31 public function testGenerateTimeZoneForm()
32 {
ae3aa968
A
33 $expected = [
34 'continents' => [
35 'Antarctica',
36 'Europe',
37 'UTC',
38 'selected' => '',
39 ],
40 'cities' => [
41 ['continent' => 'Antarctica', 'city' => 'Syowa'],
42 ['continent' => 'Europe', 'city' => 'London'],
43 ['continent' => 'Europe', 'city' => 'Paris'],
44 ['continent' => 'UTC', 'city' => 'UTC'],
45 'selected' => '',
46 ]
47 ];
d1e2f8e5 48
ae3aa968 49 list($continents, $cities) = generateTimeZoneData($this->installedTimezones);
d1e2f8e5 50
ae3aa968
A
51 $this->assertEquals($expected['continents'], $continents);
52 $this->assertEquals($expected['cities'], $cities);
d1e2f8e5
V
53 }
54
55 /**
56 * Generate a timezone selection form, with a preselected timezone
57 */
58 public function testGenerateTimeZoneFormPreselected()
59 {
ae3aa968
A
60 $expected = [
61 'continents' => [
62 'Antarctica',
63 'Europe',
64 'UTC',
65 'selected' => 'Antarctica',
66 ],
67 'cities' => [
68 ['continent' => 'Antarctica', 'city' => 'Syowa'],
69 ['continent' => 'Europe', 'city' => 'London'],
70 ['continent' => 'Europe', 'city' => 'Paris'],
71 ['continent' => 'UTC', 'city' => 'UTC'],
72 'selected' => 'Syowa',
73 ]
74 ];
d1e2f8e5 75
ae3aa968 76 list($continents, $cities) = generateTimeZoneData($this->installedTimezones, 'Antarctica/Syowa');
d1e2f8e5 77
ae3aa968
A
78 $this->assertEquals($expected['continents'], $continents);
79 $this->assertEquals($expected['cities'], $cities);
d1e2f8e5
V
80 }
81
82 /**
83 * Check valid timezones
84 */
85 public function testValidTimeZone()
86 {
87 $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia'));
88 $this->assertTrue(isTimeZoneValid('Europe', 'Oslo'));
d1e2f8e5
V
89 }
90
91 /**
92 * Check invalid timezones
93 */
94 public function testInvalidTimeZone()
95 {
96 $this->assertFalse(isTimeZoneValid('CEST', 'CEST'));
97 $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis'));
98 $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria'));
12ff86c9 99 $this->assertFalse(isTimeZoneValid('UTC', 'UTC'));
d1e2f8e5
V
100 }
101}