]>
Commit | Line | Data |
---|---|---|
d1e2f8e5 V |
1 | <?php |
2 | /** | |
3 | * TimeZone's tests | |
4 | */ | |
5 | ||
6 | require_once 'application/TimeZone.php'; | |
7 | ||
8 | /** | |
9 | * Unitary tests for timezone utilities | |
10 | */ | |
11 | class TimeZoneTest extends PHPUnit_Framework_TestCase | |
12 | { | |
13 | /** | |
14 | * Generate a timezone selection form | |
15 | */ | |
16 | public function testGenerateTimeZoneForm() | |
17 | { | |
18 | $generated = generateTimeZoneForm(); | |
19 | ||
20 | // HTML form | |
21 | $this->assertStringStartsWith('Continent:<select', $generated[0]); | |
22 | $this->assertContains('selected="selected"', $generated[0]); | |
23 | $this->assertStringEndsWith('</select><br />', $generated[0]); | |
24 | ||
25 | // Javascript handler | |
26 | $this->assertStringStartsWith('<script>', $generated[1]); | |
27 | $this->assertContains( | |
28 | '<option value=\"Bermuda\">Bermuda<\/option>', | |
29 | $generated[1] | |
30 | ); | |
31 | $this->assertStringEndsWith('</script>', $generated[1]); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Generate a timezone selection form, with a preselected timezone | |
36 | */ | |
37 | public function testGenerateTimeZoneFormPreselected() | |
38 | { | |
39 | $generated = generateTimeZoneForm('Antarctica/Syowa'); | |
40 | ||
41 | // HTML form | |
42 | $this->assertStringStartsWith('Continent:<select', $generated[0]); | |
43 | $this->assertContains( | |
44 | 'value="Antarctica" selected="selected"', | |
45 | $generated[0] | |
46 | ); | |
47 | $this->assertContains( | |
48 | 'value="Syowa" selected="selected"', | |
49 | $generated[0] | |
50 | ); | |
51 | $this->assertStringEndsWith('</select><br />', $generated[0]); | |
52 | ||
53 | ||
54 | // Javascript handler | |
55 | $this->assertStringStartsWith('<script>', $generated[1]); | |
56 | $this->assertContains( | |
57 | '<option value=\"Bermuda\">Bermuda<\/option>', | |
58 | $generated[1] | |
59 | ); | |
60 | $this->assertStringEndsWith('</script>', $generated[1]); | |
61 | } | |
62 | ||
63 | /** | |
64 | * Check valid timezones | |
65 | */ | |
66 | public function testValidTimeZone() | |
67 | { | |
68 | $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia')); | |
69 | $this->assertTrue(isTimeZoneValid('Europe', 'Oslo')); | |
70 | $this->assertTrue(isTimeZoneValid('UTC', 'UTC')); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Check invalid timezones | |
75 | */ | |
76 | public function testInvalidTimeZone() | |
77 | { | |
78 | $this->assertFalse(isTimeZoneValid('CEST', 'CEST')); | |
79 | $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis')); | |
80 | $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria')); | |
81 | } | |
82 | } |