aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/ConfigTest.php10
-rw-r--r--tests/LinkDBTest.php12
-rw-r--r--tests/TimeZoneTest.php83
-rw-r--r--tests/UtilsTest.php34
4 files changed, 127 insertions, 12 deletions
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php
index 4279c57e..a239d8b7 100755
--- a/tests/ConfigTest.php
+++ b/tests/ConfigTest.php
@@ -18,7 +18,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
18 */ 18 */
19 public function setUp() 19 public function setUp()
20 { 20 {
21 self::$_configFields = [ 21 self::$_configFields = array(
22 'login' => 'login', 22 'login' => 'login',
23 'hash' => 'hash', 23 'hash' => 'hash',
24 'salt' => 'salt', 24 'salt' => 'salt',
@@ -28,13 +28,13 @@ class ConfigTest extends PHPUnit_Framework_TestCase
28 'redirector' => '', 28 'redirector' => '',
29 'disablesessionprotection' => false, 29 'disablesessionprotection' => false,
30 'privateLinkByDefault' => false, 30 'privateLinkByDefault' => false,
31 'config' => [ 31 'config' => array(
32 'CONFIG_FILE' => 'tests/config.php', 32 'CONFIG_FILE' => 'tests/config.php',
33 'DATADIR' => 'tests', 33 'DATADIR' => 'tests',
34 'config1' => 'config1data', 34 'config1' => 'config1data',
35 'config2' => 'config2data', 35 'config2' => 'config2data',
36 ] 36 )
37 ]; 37 );
38 } 38 }
39 39
40 /** 40 /**
@@ -174,4 +174,4 @@ class ConfigTest extends PHPUnit_Framework_TestCase
174 include self::$_configFields['config']['CONFIG_FILE']; 174 include self::$_configFields['config']['CONFIG_FILE'];
175 $this->assertEquals(self::$_configFields['login'], $GLOBALS['login']); 175 $this->assertEquals(self::$_configFields['login'], $GLOBALS['login']);
176 } 176 }
177} \ No newline at end of file 177}
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index d34ea4f5..504c8190 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -228,12 +228,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
228 public function testDays() 228 public function testDays()
229 { 229 {
230 $this->assertEquals( 230 $this->assertEquals(
231 ['20121206', '20130614', '20150310'], 231 array('20121206', '20130614', '20150310'),
232 self::$publicLinkDB->days() 232 self::$publicLinkDB->days()
233 ); 233 );
234 234
235 $this->assertEquals( 235 $this->assertEquals(
236 ['20121206', '20130614', '20141125', '20150310'], 236 array('20121206', '20130614', '20141125', '20150310'),
237 self::$privateLinkDB->days() 237 self::$privateLinkDB->days()
238 ); 238 );
239 } 239 }
@@ -269,7 +269,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
269 public function testAllTags() 269 public function testAllTags()
270 { 270 {
271 $this->assertEquals( 271 $this->assertEquals(
272 [ 272 array(
273 'web' => 3, 273 'web' => 3,
274 'cartoon' => 2, 274 'cartoon' => 2,
275 'gnu' => 2, 275 'gnu' => 2,
@@ -279,12 +279,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
279 'software' => 1, 279 'software' => 1,
280 'stallman' => 1, 280 'stallman' => 1,
281 'free' => 1 281 'free' => 1
282 ], 282 ),
283 self::$publicLinkDB->allTags() 283 self::$publicLinkDB->allTags()
284 ); 284 );
285 285
286 $this->assertEquals( 286 $this->assertEquals(
287 [ 287 array(
288 'web' => 4, 288 'web' => 4,
289 'cartoon' => 3, 289 'cartoon' => 3,
290 'gnu' => 2, 290 'gnu' => 2,
@@ -298,7 +298,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
298 'w3c' => 1, 298 'w3c' => 1,
299 'css' => 1, 299 'css' => 1,
300 'Mercurial' => 1 300 'Mercurial' => 1
301 ], 301 ),
302 self::$privateLinkDB->allTags() 302 self::$privateLinkDB->allTags()
303 ); 303 );
304 } 304 }
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?>
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 8355c7f8..28e15f5a 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -109,7 +109,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase
109 */ 109 */
110 public function testGenerateLocationLoop() { 110 public function testGenerateLocationLoop() {
111 $ref = 'http://localhost/?test'; 111 $ref = 'http://localhost/?test';
112 $this->assertEquals('?', generateLocation($ref, 'localhost', ['test'])); 112 $this->assertEquals('?', generateLocation($ref, 'localhost', array('test')));
113 } 113 }
114 114
115 /** 115 /**
@@ -119,4 +119,36 @@ class UtilsTest extends PHPUnit_Framework_TestCase
119 $ref = 'http://somewebsite.com/?test'; 119 $ref = 'http://somewebsite.com/?test';
120 $this->assertEquals('?', generateLocation($ref, 'localhost')); 120 $this->assertEquals('?', generateLocation($ref, 'localhost'));
121 } 121 }
122
123 /**
124 * Check supported PHP versions
125 */
126 public function testCheckSupportedPHPVersion()
127 {
128 $minVersion = '5.3';
129 checkPHPVersion($minVersion, '5.4.32');
130 checkPHPVersion($minVersion, '5.5');
131 checkPHPVersion($minVersion, '5.6.10');
132 }
133
134 /**
135 * Check a unsupported PHP version
136 * @expectedException Exception
137 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
138 */
139 public function testCheckSupportedPHPVersion51()
140 {
141 checkPHPVersion('5.3', '5.1.0');
142 }
143
144 /**
145 * Check another unsupported PHP version
146 * @expectedException Exception
147 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
148 */
149 public function testCheckSupportedPHPVersion52()
150 {
151 checkPHPVersion('5.3', '5.2');
152 }
122} 153}
154?>