1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test - filesystem function |
4
|
|
|
* |
5
|
|
|
* @package fwolflib |
6
|
|
|
* @subpackage func.test |
7
|
|
|
* @copyright Copyright 2010, Fwolf |
8
|
|
|
* @author Fwolf <[email protected]> |
9
|
|
|
* @since 2010-10-10 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Define like this, so test can run both under eclipse and web alone. |
13
|
|
|
// {{{ |
14
|
|
|
if (! defined('SIMPLE_TEST')) { |
15
|
|
|
define('SIMPLE_TEST', 'simpletest/'); |
16
|
|
|
require_once(SIMPLE_TEST . 'autorun.php'); |
17
|
|
|
} |
18
|
|
|
// Then set output encoding |
19
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
20
|
|
|
// }}} |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
// Require library define file which need test |
24
|
|
|
require_once(dirname(__FILE__) . '/../fwolflib.php'); |
25
|
|
|
require_once(FWOLFLIB . 'func/filesystem.php'); |
26
|
|
|
require_once(FWOLFLIB . 'func/request.php'); |
27
|
|
|
require_once(FWOLFLIB . 'func/uuid.php'); |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class TestFuncFilesystem extends UnitTestCase { |
31
|
|
|
|
32
|
|
|
function TestGetFilenameToWrite () { |
|
|
|
|
33
|
|
|
// Prepare a filename |
34
|
|
|
$s_name = sys_get_temp_dir(); |
35
|
|
|
if ('/' != substr($s_name, -1)) |
36
|
|
|
$s_name .= '/'; |
37
|
|
|
$s_name .= Uuid(); |
|
|
|
|
38
|
|
|
$s_ext = 'ext'; |
39
|
|
|
$s_file = $s_name . '.' . $s_ext; |
40
|
|
|
|
41
|
|
|
// Call 0 |
42
|
|
|
$s = GetFilenameToWrite($s_file); |
|
|
|
|
43
|
|
|
$this->assertEqual($s, $s_name . '.' . $s_ext); |
44
|
|
|
touch($s); |
45
|
|
|
|
46
|
|
|
// Call 1 |
47
|
|
|
$s = GetFilenameToWrite($s_file); |
|
|
|
|
48
|
|
|
$this->assertEqual($s, $s_name . '-1.' . $s_ext); |
49
|
|
|
mkdir($s); |
50
|
|
|
|
51
|
|
|
// Call 2 |
52
|
|
|
$s = GetFilenameToWrite($s_file); |
|
|
|
|
53
|
|
|
$this->assertEqual($s, $s_name . '-2.' . $s_ext); |
54
|
|
|
//touch($s); |
55
|
|
|
|
56
|
|
|
} // end of func GetFilenameToWrite |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
} // end of class TestFuncFilesystem |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
// Change output charset in this way. |
63
|
|
|
// {{{ |
64
|
|
|
$s_url = GetSelfUrl(false); |
|
|
|
|
65
|
|
|
$s_url = substr($s_url, strrpos($s_url, '/') + 1); |
66
|
|
|
if (__FILE__ == $s_url) { |
67
|
|
|
$test = new TestFuncFilesystem(); |
68
|
|
|
$test->run(new HtmlReporter('utf-8')); |
69
|
|
|
} |
70
|
|
|
// }}} |
71
|
|
|
?> |
|
|
|
|
72
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.