]> git.immae.eu Git - github/shaarli/Shaarli.git/blame_incremental - tests/TimeZoneTest.php
documentation: add links to example REST API clients
[github/shaarli/Shaarli.git] / tests / TimeZoneTest.php
... / ...
CommitLineData
1<?php
2/**
3 * TimeZone's tests
4 */
5
6require_once 'application/TimeZone.php';
7
8/**
9 * Unitary tests for timezone utilities
10 */
11class TimeZoneTest extends PHPUnit_Framework_TestCase
12{
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
28 /**
29 * Generate a timezone selection form
30 */
31 public function testGenerateTimeZoneForm()
32 {
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 ];
48
49 list($continents, $cities) = generateTimeZoneData($this->installedTimezones);
50
51 $this->assertEquals($expected['continents'], $continents);
52 $this->assertEquals($expected['cities'], $cities);
53 }
54
55 /**
56 * Generate a timezone selection form, with a preselected timezone
57 */
58 public function testGenerateTimeZoneFormPreselected()
59 {
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 ];
75
76 list($continents, $cities) = generateTimeZoneData($this->installedTimezones, 'Antarctica/Syowa');
77
78 $this->assertEquals($expected['continents'], $continents);
79 $this->assertEquals($expected['cities'], $cities);
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'));
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'));
99 $this->assertFalse(isTimeZoneValid('UTC', 'UTC'));
100 }
101}