summaryrefslogtreecommitdiff
path: root/pear/tests/pear_config.phpt
blob: 395986b9bd432c691b82e62f5b6de6da45c58772 (plain)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
--TEST--
PEAR_Config
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
    echo 'skip';
    exit();
}
include 'PEAR/Config.php';
$pv = phpversion() . '';
$av = $pv{0} == '4' ? 'apiversion' : 'apiVersion';
if (in_array($av, get_class_methods('PEAR_Config'))) {
    echo 'skip';
}
?>
--FILE--
<?php

error_reporting(E_ALL);
chdir(dirname(__FILE__));
include "PEAR/Config.php";
copy("system.input", "system.conf");
copy("user.input", "user.conf");
copy("user2.input", "user2.conf");
copy("merge.input", "merge.conf");
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s\n");

print "\n#0 starting up\n";
dump_files();

print "\n#1 testing: constructor\n";
$config = new PEAR_Config("user.conf", "system.conf");
dump_array("files", $config->files);

print "\n#2 testing: singleton\n";
$o1 = &PEAR_Config::singleton();
$o1->blah = 'blah';
$o2 = &PEAR_Config::singleton();
var_dump($o1->blah);
@var_dump($o2->blah);

print "\n#3 testing: readConfigFile\n";
$config->readConfigFile("user2.conf", "user");
dump_config($config);
$config->readConfigFile("user.conf");
dump_config($config);

print "\n#4 testing: mergeConfigFile\n";
$config->readConfigFile("user2.conf");
dump_config($config, "user");
$config->mergeConfigFile("merge.conf", true);
dump_config($config, "user");
$config->readConfigFile("user2.conf");
$config->mergeConfigFile("merge.conf", false);
dump_config($config, "user");
$config->readConfigFile("user.conf");
dump_config($config, "user");
$config->mergeConfigFile("merge.conf", true, "xyzzy");

print "\n#5 testing: config file version detection\n";
$config->readConfigFile("user.conf", "user");
$config->readConfigFile("toonew.conf", "user");

print "\n#6 testing: get/set/remove\n";
var_dump($config->get("verbose"));
$config->set("verbose", 100, "system");
var_dump($config->get("verbose"));
$config->set("verbose", 2, "user");
var_dump($config->get("verbose"));
$config->set("verbose", 2, "system");
$config->set("verbose", 50, "user");
var_dump($config->get("verbose"));
$config->remove("verbose", "user");
var_dump($config->get("verbose"));
$config->remove("verbose", "system");
var_dump($config->get("verbose"));

print "\n#7 testing: getType\n";
var_dump($config->getType("__unknown__"));
var_dump($config->getType("verbose"));
var_dump($config->getType("master_server"));
var_dump($config->getType("ext_dir"));

print "\n#8 testing: getDocs\n";
print "master_server: " . $config->getDocs("master_server") . "\n";

print "\n#9 testing: getKeys\n";
$keys = $config->getKeys();
sort($keys);
print implode(" ", $keys) . "\n";

print "\n#10 testing: definedBy\n";
var_dump($config->definedBy("verbose"));
$config->set("verbose", 6, "system");
$config->set("verbose", 3, "user");
var_dump($config->definedBy("verbose"));
$config->remove("verbose", "system");
var_dump($config->definedBy("verbose"));
$config->set("verbose", 6, "system");
$config->remove("verbose", "user");
var_dump($config->definedBy("verbose"));
$config->remove("verbose", "system");
var_dump($config->definedBy("verbose"));

print "\n#11 testing: isDefined\n";
var_dump($config->isDefined("php_dir"));
var_dump($config->isDefined("verbose"));
var_dump($config->isDefined("HTTP_GET_VARS"));
var_dump($config->isDefined("query"));

print "\n#12 testing: getGroup\n";
foreach ($keys as $key) {
    print "$key: ".$config->getGroup($key)."\n";
}

print "\n#13 testing: getGroups\n";
$groups = $config->getGroups();
sort($groups);
print implode(", ", $groups) . "\n";

print "\n#14 testing: getGroupKeys\n";
foreach ($groups as $group) {
    $gk = $config->getGroupKeys($group);
    sort($gk);
    print "$group: " . implode(", ", $gk) . "\n";
}

print "\n#15 testing: getPrompt\n";
foreach ($keys as $key) {
    print "$key: ".$config->getPrompt($key)."\n";
}


//

print "done\n";

unlink("user.conf");
unlink("user2.conf");
unlink("system.conf");
unlink("merge.conf");

// ------------------------------------------------------------------------- //

function dump_file($file)
{
	print "..$file:";
        $data = PEAR_Config::_readConfigDataFrom($file);
	if (empty($data)) {
		print " <empty>\n";
		return;
	}
	foreach ($data as $k => $v) {
		print " $k=\"$v\"";
	}
	print "\n";
}

function dump_files() {
	dump_file("system.conf");
	dump_file("user.conf");
}

function dump_array($name, $arr) {
	print "$name:";
	if (empty($arr)) {
		print " <empty>";
	} else {
		foreach ($arr as $k => $v) {
			print " $k=\"$v\"";
		}
	}
	print "\n";
}

function dump_config(&$obj, $layer = null) {
	if ($layer !== null) {
		dump_array($layer, $obj->configuration[$layer]);
		return;
	}
	foreach ($obj->configuration as $layer => $data) {
		if ($layer == "default") {
			continue;
		}
		dump_array($layer, $data);
	}
}

?>
--EXPECT--
#0 starting up
..system.conf: master_server="pear.php.net"
..user.conf: <empty>

#1 testing: constructor
files: system="system.conf" user="user.conf"

#2 testing: singleton
string(4) "blah"
string(4) "blah"

#3 testing: readConfigFile
user: verbose="2"
system: master_server="pear.php.net"
user: <empty>
system: master_server="pear.php.net"

#4 testing: mergeConfigFile
user: verbose="2"
user: verbose="100"
user: verbose="2"
user: <empty>
unknown config file type `xyzzy'

#5 testing: config file version detection
toonew.conf: unknown version `2.0'

#6 testing: get/set/remove
int(1)
int(100)
int(2)
int(50)
int(2)
int(1)

#7 testing: getType
bool(false)
string(7) "integer"
string(6) "string"
string(9) "directory"

#8 testing: getDocs
master_server: name of the main PEAR server

#9 testing: getKeys
bin_dir cache_dir cache_ttl data_dir doc_dir ext_dir http_proxy master_server password php_bin php_dir preferred_state sig_bin sig_keydir sig_keyid sig_type test_dir umask username verbose

#10 testing: definedBy
string(7) "default"
string(4) "user"
string(4) "user"
string(6) "system"
string(7) "default"

#11 testing: isDefined
bool(true)
bool(true)
bool(false)
bool(false)

#12 testing: getGroup
bin_dir: File Locations
cache_dir: File Locations (Advanced)
cache_ttl: Advanced
data_dir: File Locations (Advanced)
doc_dir: File Locations
ext_dir: File Locations
http_proxy: Internet Access
master_server: Internet Access
password: Maintainers
php_bin: File Locations (Advanced)
php_dir: File Locations
preferred_state: Advanced
sig_bin: Maintainers
sig_keydir: Maintainers
sig_keyid: Maintainers
sig_type: Maintainers
test_dir: File Locations (Advanced)
umask: Advanced
username: Maintainers
verbose: Advanced

#13 testing: getGroups
Advanced, File Locations, File Locations (Advanced), Internet Access, Maintainers

#14 testing: getGroupKeys
Advanced: cache_ttl, preferred_state, umask, verbose
File Locations: bin_dir, doc_dir, ext_dir, php_dir
File Locations (Advanced): cache_dir, data_dir, php_bin, test_dir
Internet Access: http_proxy, master_server
Maintainers: password, sig_bin, sig_keydir, sig_keyid, sig_type, username

#15 testing: getPrompt
bin_dir: PEAR executables directory
cache_dir: PEAR Installer cache directory
cache_ttl: Cache TimeToLive
data_dir: PEAR data directory
doc_dir: PEAR documentation directory
ext_dir: PHP extension directory
http_proxy: HTTP Proxy Server Address
master_server: PEAR server
password: PEAR password (for maintainers)
php_bin: PHP CLI/CGI binary
php_dir: PEAR directory
preferred_state: Preferred Package State
sig_bin: Signature Handling Program
sig_keydir: Signature Key Directory
sig_keyid: Signature Key Id
sig_type: Package Signature Type
test_dir: PEAR test directory
umask: Unix file mask
username: PEAR username (for maintainers)
verbose: Debug Log Level
done