Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
--TEST--
2
PEAR_Info using custom configuration
3
--FILE--
4
<?php
5
$ds         = DIRECTORY_SEPARATOR;
6
$dir        = dirname(__FILE__);
7
$sysconfdir = $dir . $ds . 'sysconf_dir';
8
$peardir    = $dir . $ds . 'pear_dir';
9
$userdir    = $dir . $ds . 'user_dir';
10
 
11
putenv("PHP_PEAR_SYSCONF_DIR=" . $sysconfdir);
12
chdir($dir);
13
 
14
// we get PEAR_Info class only here due to setting of PEAR_CONFIG_SYSCONFDIR
15
include_once 'PEAR/Info.php';
16
 
17
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
18
    $conf_file    = $peardir . $ds . 'pearsys.ini';
19
    $custom_file1 = $peardir . $ds . 'name1.pearsys.ini';
20
    $custom_file2 = $userdir . $ds . 'name2.pearsys.ini';
21
} else {
22
    $conf_file    = $peardir . $ds . 'pear.conf';
23
    $custom_file1 = $peardir . $ds . 'name1.pear.conf';
24
    $custom_file2 = $userdir . $ds . 'name2.pear.conf';
25
}
26
 
27
if (!file_exists($conf_file)) {
28
    // write once PEAR system-wide config file for simulation
29
    $config =& PEAR_Config::singleton();
30
    $config->set('php_dir', $peardir);
31
    $config->writeConfigFile($conf_file);
32
 
33
    // also writes custom pear system config files
34
    $config->writeConfigFile($custom_file1);
35
    $config->writeConfigFile($custom_file2);
36
}
37
 
38
/**
39
 * TestCase 1:
40
 * class constructor with only $pear_dir parameter
41
 *
42
 * Will try to detect if default user config files (pear.ini | .pearrc),
43
 * and/or default system config files (pearsys.ini | pear.conf) are available
44
 * into $peardir directory.
45
 */
46
$testCase = 'testConfigFilesExistWithDefaultNameInPearDir';
47
 
48
$GLOBALS['_PEAR_Config_instance'] = null;
49
 
50
$pear_dir = $peardir;
51
 
52
// try to load PEAR system config ($conf_file) from system dir
53
$pearInfo = new PEAR_Info($pear_dir);
54
 
55
$result = (!is_null($pearInfo->reg))
56
    ? 'OK' : 'System PEAR configuration files does not exist';
57
 
58
echo $testCase . ' : ' . $result;
59
echo "\n";
60
 
61
/**
62
 * TestCase 2:
63
 * class constructor with 3 parameters ($pear_dir, $user_file, and $system_file)
64
 *
65
 * Will try to detect if user config files and/or system config files
66
 * are available into $peardir directory.
67
 */
68
$testCase = 'testConfigFilesExistWithCustomNameInPearDir';
69
 
70
$GLOBALS['_PEAR_Config_instance'] = null;
71
 
72
$pear_dir    = $peardir;
73
$user_file   = '';
74
$system_file = $custom_file1;
75
 
76
// try to load PEAR system config ($custom_file1) from pear dir
77
$pearInfo = new PEAR_Info($pear_dir, $user_file, $system_file);
78
 
79
$result = (!is_null($pearInfo->reg))
80
    ? 'OK' : 'User PEAR configuration files does not exist';
81
 
82
echo $testCase . ' : ' . $result;
83
echo "\n";
84
 
85
/**
86
 * TestCase 3:
87
 * class constructor with parameters ($user_file, and $system_file)
88
 *
89
 * Will try to detect if user config files and/or system config files
90
 * are available into user directory.
91
 */
92
$testCase = 'testConfigFilesExistInUserDir';
93
 
94
$GLOBALS['_PEAR_Config_instance'] = null;
95
 
96
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
97
    $user_file   = $userdir . $ds . 'name2.pear.ini';
98
    $system_file = $userdir . $ds . 'name2.pearsys.ini';
99
} else {
100
    $user_file   = $userdir . $ds . 'name2.pearrc';
101
    $system_file = $userdir . $ds . 'name2.pear.conf';
102
}
103
$pear_dir = '';
104
 
105
// try to load PEAR system config ($system_file) from user dir,
106
// because user config ($user_file) does not exists (volontary)
107
$pearInfo = new PEAR_Info($pear_dir, $user_file, $system_file);
108
 
109
$result = (!is_null($pearInfo->reg))
110
    ? 'OK' : 'User PEAR configuration files does not exist';
111
 
112
echo $testCase . ' : ' . $result;
113
echo "\n";
114
 
115
/**
116
 * TestCase 4:
117
 * class constructor with only $pear_dir parameter
118
 *
119
 * No user or system file exists into pear directory.
120
 * Will display error to prevent unexpected behavior.
121
 */
122
$testCase = 'testNoConfigFilesFoundIntoPearDir';
123
 
124
$GLOBALS['_PEAR_Config_instance'] = null;
125
 
126
$pear_dir = $dir . $ds . 'pear2_dir';
127
 
128
$pearInfo = new PEAR_Info($pear_dir);
129
 
130
$result = (is_null($pearInfo->reg))
131
    ? 'OK' : 'User PEAR configuration files does not exist';
132
 
133
echo $testCase . ' : ' . $result;
134
echo "\n";
135
 
136
/**
137
 * TestCase 5:
138
 * class constructor with only $user_file and $system_file parameters
139
 *
140
 * No such (name3) user or system file exists into user directory.
141
 * Will display an error to prevent unexpected behavior.
142
 */
143
$testCase = 'testNoConfigFilesFoundIntoUserDir';
144
 
145
$GLOBALS['_PEAR_Config_instance'] = null;
146
 
147
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
148
    $user_file   = $userdir . $ds . 'name3.pear.ini';
149
    $system_file = $userdir . $ds . 'name3.pearsys.ini';
150
} else {
151
    $user_file   = $userdir . $ds . 'name3.pearrc';
152
    $system_file = $userdir . $ds . 'name3.pear.conf';
153
}
154
$pear_dir = '';
155
 
156
$pearInfo = new PEAR_Info($pear_dir, $user_file, $system_file);
157
 
158
$result = (is_null($pearInfo->reg))
159
    ? 'OK' : strip_tags($pearInfo->info);
160
 
161
echo $testCase . ' : ' . $result;
162
echo "\n";
163
 
164
/**
165
 * TestCase 6:
166
 * class constructor with only $options parameter
167
 */
168
$testCase = 'testShowResultsWithRenderOptions';
169
 
170
$GLOBALS['_PEAR_Config_instance'] = null;
171
 
172
$pear_dir    = $peardir;
173
$user_file   = '';
174
$system_file = '';
175
$options     = array(
176
    'resume' => PEAR_INFO_FULLPAGE |
177
                PEAR_INFO_GENERAL | PEAR_INFO_CHANNELS | PEAR_INFO_PACKAGES_VERSION |
178
                PEAR_INFO_CREDITS_PACKAGES,
179
    'channels' => array()
180
);
181
 
182
// try to load PEAR system config from pear dir
183
$pearInfo = new PEAR_Info($pear_dir, $user_file, $system_file, $options);
184
 
185
$result = (!is_null($pearInfo->reg))
186
    ? 'OK' : 'KO';
187
 
188
echo $testCase . ' : ' . $result;
189
echo "\n";
190
 
191
/**
192
 * TestCase 7:
193
 * class constructor with invalid $peardir parameter
194
 */
195
$testCase = 'testInvalidPearDir';
196
 
197
$GLOBALS['_PEAR_Config_instance'] = null;
198
 
199
$pear_dir = $dir . $ds . 'invalid_pear_dir';
200
 
201
$pearInfo = new PEAR_Info($pear_dir);
202
 
203
$result = (is_null($pearInfo->reg))
204
    ? 'OK' : 'Valid PEAR directory found';
205
 
206
echo $testCase . ' : ' . $result;
207
?>
208
--CLEAN--
209
<?php
210
$ds         = DIRECTORY_SEPARATOR;
211
$dir        = dirname(__FILE__);
212
$sysconfdir = $dir . $ds . 'sysconf_dir';
213
$peardir    = $dir . $ds . 'pear_dir';
214
$userdir    = $dir . $ds . 'user_dir';
215
 
216
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
217
    $conf_file    = $peardir . $ds . 'pearsys.ini';
218
    $custom_file1 = $peardir . $ds . 'name1.pearsys.ini';
219
    $custom_file2 = $userdir . $ds . 'name2.pearsys.ini';
220
} else {
221
    $conf_file    = $peardir . $ds . 'pear.conf';
222
    $custom_file1 = $peardir . $ds . 'name1.pear.conf';
223
    $custom_file2 = $userdir . $ds . 'name2.pear.conf';
224
}
225
 
226
unlink ($conf_file);
227
unlink ($custom_file1);
228
unlink ($custom_file2);
229
?>
230
--EXPECT--
231
testConfigFilesExistWithDefaultNameInPearDir : OK
232
testConfigFilesExistWithCustomNameInPearDir : OK
233
testConfigFilesExistInUserDir : OK
234
testNoConfigFilesFoundIntoPearDir : OK
235
testNoConfigFilesFoundIntoUserDir : OK
236
testShowResultsWithRenderOptions : OK
237
testInvalidPearDir : OK