util.php 1.23 KB
Newer Older
1
2
3
4
5
6
7
8
<?php
/**
 * Copyright (c) 2012 Lukas Reschke <lukas@statuscode.ch>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

Thomas Mueller's avatar
Thomas Mueller committed
9
class Test_Util extends PHPUnit_Framework_TestCase {
10
11
12

	// Constructor
	function Test_Util() {
13
		date_default_timezone_set("UTC");
14
15
16
17
	}

	function testFormatDate() {
		$result = OC_Util::formatDate(1350129205);
18
		$expected = 'October 13, 2012 11:53';
Thomas Müller's avatar
Thomas Müller committed
19
		$this->assertEquals($expected, $result);
20
21
22

		$result = OC_Util::formatDate(1102831200, true);
		$expected = 'December 12, 2004';
23
		$this->assertEquals($expected, $result);
24
25
26
27
	}

	function testCallRegister() {
		$result = strlen(OC_Util::callRegister());
28
		$this->assertEquals(20, $result);
29
30
31
32
33
	}

	function testSanitizeHTML() {
		$badString = "<script>alert('Hacked!');</script>";
		$result = OC_Util::sanitizeHTML($badString);
34
		$this->assertEquals("&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;", $result);
35
36
37

		$goodString = "This is an harmless string.";
		$result = OC_Util::sanitizeHTML($goodString);
38
		$this->assertEquals("This is an harmless string.", $result);
39
	}
40
41
42

	function testGenerate_random_bytes() {
		$result = strlen(OC_Util::generate_random_bytes(59));
43
		$this->assertEquals(59, $result);
44
	}
45
}