forked from kerphi/phpfreechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_file.php
188 lines (151 loc) · 5.94 KB
/
container_file.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
require_once "container_generic.php";
class pfcContainerTestcase_File extends pfcContainerTestcase
{
// constructor of the test suite
function pfcContainerTestcase_File($name)
{
$this->type = "File";
$this->pfcContainerTestcase($name);
}
// called before the test functions will be executed
// this function is defined in PHPUnit_TestCase and overwritten
// here
function setUp()
{
pfcContainerTestcase::setUp();
}
// called after the test functions are executed
// this function is defined in PHPUnit_TestCase and overwritten
// here
function tearDown()
{
pfcContainerTestcase::tearDown();
}
function test_setMeta_File_1()
{
$c =& $this->c;
$ct =& $this->ct;
$prefix = __FUNCTION__;
$group = $prefix."_nickid-to-channelid";
$subgroup = $prefix."_nickid1";
$leaf = $prefix."_channelid1";
$ret = $ct->setMeta($group, $subgroup, $leaf);
$this->assertEquals($ret, 0, "the leaf should be first time created");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf;
$ret = file_exists($f);
$this->assertEquals($ret, true, "the leaf file should exists");
$ret = file_get_contents($f);
$this->assertEquals($ret, '', "the leaf file should contain nothing");
}
function test_setMeta_File_2()
{
$c =& $this->c;
$ct =& $this->ct;
$prefix = __FUNCTION__;
$group = $prefix."_nickid-to-channelid";
$subgroup = $prefix."_nickid1";
$leaf = $prefix."_channelid1";
$leafvalue = $prefix."_leafvalue1";
$ret = $ct->setMeta($group, $subgroup, $leaf, $leafvalue);
$this->assertEquals($ret, 0, "the leaf should be first time created");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf;
$ret = file_exists($f);
$this->assertEquals($ret, true, "the leaf file should exists");
$ret = file_get_contents($f);
$this->assertEquals($ret, $leafvalue, "the leaf file should contain the value");
}
function test_setMeta_File_3()
{
$c =& $this->c;
$ct =& $this->ct;
$prefix = __FUNCTION__;
$group = $prefix."_nickid-to-channelid";
$subgroup = $prefix."_nickid1";
$leaf = $prefix."_channelid1";
$leafvalue = $prefix."_leafvalue1";
$ret = $ct->setMeta($group, $subgroup, $leaf, $leafvalue);
$this->assertEquals($ret, 0, "the leaf should be first time created");
$leafvalue = null;
$ret = $ct->setMeta($group, $subgroup, $leaf, $leafvalue);
$this->assertEquals($ret, 1, "the leaf should be overwritten");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf;
$ret = file_exists($f);
$this->assertEquals($ret, true, "the leaf file should exists");
$ret = file_get_contents($f);
$this->assertEquals($ret, '', "the leaf file should contain nothing");
}
function test_rmMeta_File_1()
{
$c =& $this->c;
$ct =& $this->ct;
$prefix = __FUNCTION__;
$group = $prefix."_nickid-to-channelid";
$subgroup = $prefix."_nickid1";
$leaf = $prefix."_channelid1";
$ret = $ct->setMeta($group, $subgroup, $leaf);
$ret = $ct->rmMeta($group, $subgroup, $leaf);
$this->assertEquals($ret, true, "the returned value should be true (rm success)");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf;
$ret = file_exists($f);
$this->assertEquals($ret, false, "the leaf file should not exists anymore");
}
function test_rmMeta_File_2()
{
$c =& $this->c;
$ct =& $this->ct;
$prefix = __FUNCTION__;
$group = $prefix."_nickid-to-channelid";
$subgroup = $prefix."_nickid1";
$leaf1 = $prefix."_channelid1";
$leaf2 = $prefix."_channelid2";
$ret = $ct->setMeta($group, $subgroup, $leaf1);
$ret = $ct->setMeta($group, $subgroup, $leaf2);
$ret = $ct->rmMeta($group, $subgroup);
$this->assertEquals($ret, true, "the returned value should be true (rm success)");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf1;
$ret = file_exists($f);
$this->assertEquals($ret, false, "the leaf file should not exists anymore");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf2;
$ret = file_exists($f);
$this->assertEquals($ret, false, "the leaf file should not exists anymore");
$d = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup;
$ret = file_exists($f);
$this->assertEquals($ret, false, "the subgroup directory should not exists anymore");
}
function test_rmMeta_File_3()
{
$c =& $this->c;
$ct =& $this->ct;
$prefix = __FUNCTION__;
$group = $prefix."_nickid-to-channelid";
$subgroup = $prefix."_nickid1";
$leaf1 = $prefix."_channelid1";
$leaf2 = $prefix."_channelid2";
$ret = $ct->setMeta($group, $subgroup, $leaf1);
$ret = $ct->setMeta($group, $subgroup, $leaf2);
$ret = $ct->rmMeta($group);
$this->assertEquals($ret, true, "the returned value should be true (rm success)");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf1;
$ret = file_exists($f);
$this->assertEquals($ret, false, "the leaf file should not exists anymore");
$f = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup.'/'.$leaf2;
$ret = file_exists($f);
$this->assertEquals($ret, false, "the leaf file should not exists anymore");
$d = $c->container_cfg_server_dir.'/'.$group.'/'.$subgroup;
$ret = file_exists($d);
$this->assertEquals($ret, false, "the subgroup directory should not exists anymore");
$d = $c->container_cfg_server_dir.'/'.$group;
$ret = file_exists($d);
$this->assertEquals($ret, false, "the group directory should not exists anymore");
}
}
// on desactive le timeout car se script peut mettre bcp de temps a s'executer
ini_set('max_execution_time', 0);
$suite = new PHPUnit_TestSuite();
$suite->addTestSuite("pfcContainerTestcase_File");
$result =& PHPUnit::run($suite);
echo "<pre>";
print_r($result->toString());
echo "</pre>";
?>