aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TimeZoneTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-07-11 01:29:12 +0200
committerVirtualTam <virtualtam@flibidi.net>2015-07-13 13:06:06 +0200
commitd1e2f8e52c931f84c11d4f54f32959710d528182 (patch)
treebe5ad2fcfeb31136e7afca0603a3cd3da3d76b57 /tests/TimeZoneTest.php
parent5b0ebbc5de06b8a0e9679b78b45d0dc755db7986 (diff)
downloadShaarli-d1e2f8e52c931f84c11d4f54f32959710d528182.tar.gz
Shaarli-d1e2f8e52c931f84c11d4f54f32959710d528182.tar.zst
Shaarli-d1e2f8e52c931f84c11d4f54f32959710d528182.zip
PHP: ensure 5.3 compatibility, refactor timezone utilities
Relates to #250 Modifications - supported version - bump required version from 5.1.0 to 5.3.x - update README - add PHP 5.3 to Travis environments - rewrite array declarations: explicitely use array() instead of [] - move checkPHPVersion to application/Utils.php - move timezone functions to application/TimeZone.php - cleanup code - improve test coverage Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/TimeZoneTest.php')
-rw-r--r--tests/TimeZoneTest.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php
new file mode 100644
index 00000000..f3de3913
--- /dev/null
+++ b/tests/TimeZoneTest.php
@@ -0,0 +1,83 @@
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 * 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}
83?>