aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TimeZoneTest.php
blob: 127fdc192ccab36ec57427ba270f444f9108b29f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 * TimeZone's tests
 */

require_once 'application/TimeZone.php';

/**
 * Unitary tests for timezone utilities
 */
class TimeZoneTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var array of timezones
     */
    protected $installedTimezones;

    public function setUp()
    {
        $this->installedTimezones = [
            'Antarctica/Syowa',
            'Europe/London',
            'Europe/Paris',
            'UTC'
        ];
    }

    /**
     * Generate a timezone selection form
     */
    public function testGenerateTimeZoneForm()
    {
        $expected = [
            'continents' => [
                'Antarctica',
                'Europe',
                'UTC',
                'selected' => '',
            ],
            'cities' => [
                ['continent' => 'Antarctica', 'city' => 'Syowa'],
                ['continent' => 'Europe',     'city' => 'London'],
                ['continent' => 'Europe',     'city' => 'Paris'],
                ['continent' => 'UTC',        'city' => 'UTC'],
                'selected'    => '',
            ]
        ];

        list($continents, $cities) = generateTimeZoneData($this->installedTimezones);

        $this->assertEquals($expected['continents'], $continents);
        $this->assertEquals($expected['cities'], $cities);
    }

    /**
     * Generate a timezone selection form, with a preselected timezone
     */
    public function testGenerateTimeZoneFormPreselected()
    {
        $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',
            ]
        ];

        list($continents, $cities) = generateTimeZoneData($this->installedTimezones, 'Antarctica/Syowa');

        $this->assertEquals($expected['continents'], $continents);
        $this->assertEquals($expected['cities'], $cities);
    }

    /**
     * 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'));
        $this->assertFalse(isTimeZoneValid('UTC', 'UTC'));
    }
}