summaryrefslogtreecommitdiff
path: root/pear/tests/pear_installer3.phpt
blob: f997ab7e4ddbc5a68823ffa594fa21858ab90482 (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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
--TEST--
PEAR_Installer test #3 File Transactions
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
    echo 'skip';
}
?>
--FILE--
<?php
$temp_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp';
if (!is_dir($temp_path)) {
    mkdir($temp_path);
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'php')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'php');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'data')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'data');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'doc')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'doc');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'test')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'test');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'ext')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'ext');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'script')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'script');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'tmp')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'tmp');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'bin')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'bin');
}
// make the fake configuration - we'll use one of these and it should work
$config = serialize(array('master_server' => 'pear.php.net',
    'php_dir' => $temp_path . DIRECTORY_SEPARATOR . 'php',
    'ext_dir' => $temp_path . DIRECTORY_SEPARATOR . 'ext',
    'data_dir' => $temp_path . DIRECTORY_SEPARATOR . 'data',
    'doc_dir' => $temp_path . DIRECTORY_SEPARATOR . 'doc',
    'test_dir' => $temp_path . DIRECTORY_SEPARATOR . 'test',
    'bin_dir' => $temp_path . DIRECTORY_SEPARATOR . 'bin',));
touch($temp_path . DIRECTORY_SEPARATOR . 'pear.conf');
$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.conf', 'w');
fwrite($fp, $config);
fclose($fp);
touch($temp_path . DIRECTORY_SEPARATOR . 'pear.ini');
$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.ini', 'w');
fwrite($fp, $config);
fclose($fp);

putenv('PHP_PEAR_SYSCONF_DIR='.$temp_path);
$home = getenv('HOME');
if (!empty($home)) {
    // for PEAR_Config initialization
    putenv('HOME="'.$temp_path);
}
require_once "PEAR/Installer.php";

// no UI is needed for these tests
$ui = false;
$installer = new PEAR_Installer($ui);
$installer->debug = 2; // hack debugging in
$curdir = getcwd();
chdir(dirname(__FILE__));

echo "test addFileOperation():\n";
echo "invalid input to addFileOperation():\n";
$err = $installer->addFileOperation('rename', 2);
echo 'Returned PEAR_Error?';
echo (get_class($err) == 'pear_error' ? " yes\n" : " no\n");
if (get_class($err) == 'pear_error') {
    echo $err->getMessage() . "\n";
}
echo 'count($installer->file_operations) = ';
var_dump(count($installer->file_operations));
echo "Do valid addFileOperation() delete\n";
touch($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
$installer->addFileOperation('delete', array($temp_path . DIRECTORY_SEPARATOR .
    'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt'));
echo 'count($installer->file_operations) = ';
var_dump(count($installer->file_operations));

echo "test valid commitFileTransaction():\n";
if ($installer->commitFileTransaction()) {
    echo "worked\n";
} else {
    echo "didn't work!\n";
}

echo "Do valid addFileOperation() rename\n";
touch($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
$installer->addFileOperation('rename', array($temp_path . DIRECTORY_SEPARATOR .
    'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt', $temp_path .
    DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'renamed.phpt'));

echo 'file renamed.phpt exists?';
clearstatcache();
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
    . 'renamed.phpt') ? " yes\n" : " no\n");
echo "test valid commitFileTransaction():\n";
if ($installer->commitFileTransaction()) {
    echo "worked\n";
} else {
    echo "didn't work!\n";
}
echo 'file renamed.phpt exists?';
clearstatcache();
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
    . 'renamed.phpt') ? " yes\n" : " no\n");
unlink($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
    . 'renamed.phpt');

echo "Do valid addFileOperation() chmod\n";
touch($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
clearstatcache();
$perms = fileperms($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
// check to see if chmod works on this OS
chmod($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt', 0776);
clearstatcache();
if (fileperms($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt')
      == $perms && substr(PHP_OS, 0, 3) == 'WIN') {
    // we are on windows, so skip this test, but simulate success
echo <<<EOF
file permissions are: 776
test valid commitFileTransaction():
about to commit 1 file operations
successfully committed 1 file operations
worked
file permissions are: 640

EOF;
} else {
    $installer->addFileOperation('chmod', array(0640, $temp_path . DIRECTORY_SEPARATOR .
        'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt'));
    
    echo 'file permissions are: ' . decoct(fileperms($temp_path . DIRECTORY_SEPARATOR .
        'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt')) . "\n";
    echo "test valid commitFileTransaction():\n";
    if ($installer->commitFileTransaction()) {
        echo "worked\n";
    } else {
        echo "didn't work!\n";
    }
    echo 'file permissions are: ' . decoct(fileperms($temp_path . DIRECTORY_SEPARATOR .
        'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt')) . "\n";
}
unlink($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
    . 'installertestfooblah.phpt');

mkdir($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
    . 'installertestfooblah');
echo "Do valid addFileOperation() rmdir\n";
echo 'directory exists?';
clearstatcache();
echo (is_dir($temp_path . DIRECTORY_SEPARATOR .
    'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah') ? " yes\n" : " no\n");
$installer->addFileOperation('rmdir', array($temp_path . DIRECTORY_SEPARATOR .
    'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah'));

echo "test valid commitFileTransaction():\n";
if ($installer->commitFileTransaction()) {
    echo "worked\n";
} else {
    echo "didn't work!\n";
}
echo 'directory exists?';

clearstatcache();
echo (is_dir($temp_path . DIRECTORY_SEPARATOR .
    'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah') ? " yes\n" : " no\n");

echo "Do valid addFileOperation() installed_as\n";
$installer->addFileOperation('installed_as', array('test.php',
    $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
    'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
    . 'installertestfooblah.phpt',
    $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
    'glomp' . DIRECTORY_SEPARATOR . 'fromp'));
echo "test valid commitFileTransaction():\n";
if ($installer->commitFileTransaction()) {
    echo "worked\n";
} else {
    echo "didn't work!\n";
}
if (isset($installer->pkginfo['filelist'])) {
    echo "filelist created\n";
} else {
    echo "filelist not created!\n";
}
if (isset($installer->pkginfo['filelist']['test.php'])) {
    echo "filelist test.php created\n";
} else {
    echo "filelist test.php not created!\n";
}
if (isset($installer->pkginfo['filelist']['test.php']['installed_as'])) {
    echo "filelist test.php installed_as created\n";
} else {
    echo "filelist test.php installed_as not created!\n";
}
$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
    'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
    . 'installertestfooblah.phpt';
if (@$installer->pkginfo['filelist']['test.php']['installed_as'] == $p) {
    echo "filelist test.php installed_as is correct\n";
} else {
    echo "filelist test.php installed_as is not correct!\n";
}
if (isset($installer->pkginfo['filelist']['dirtree'])) {
    echo "filelist dirtree created\n";
} else {
    echo "filelist dirtree not created!\n";
}
$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
    'glomp';
if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
    echo "filelist dirtree glomp created\n";
} else {
    echo "filelist dirtree glomp not created!\n";
}
$p .= DIRECTORY_SEPARATOR . 'fromp';
if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
    echo "filelist dirtree fromp created\n";
} else {
    echo "filelist dirtree fromp not created!\n";
}

echo "Do valid addFileOperation() installed_as\n";
$installer->addFileOperation('installed_as', array('test.php',
    $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
    'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
    . 'installertestfooblah.phpt',
    $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
    'glomp' . DIRECTORY_SEPARATOR . 'fromp'));
echo "test valid rollbackFileTransaction():\n";
$installer->rollbackFileTransaction();
if (isset($installer->pkginfo['filelist'])) {
    echo "filelist created\n";
} else {
    echo "filelist not created!\n";
}
if (isset($installer->pkginfo['filelist']['test.php'])) {
    echo "filelist test.php created\n";
} else {
    echo "filelist test.php not created!\n";
}
if (isset($installer->pkginfo['filelist']['test.php']['installed_as'])) {
    echo "filelist test.php installed_as created\n";
} else {
    echo "filelist test.php installed_as not created!\n";
}
$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
    'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
    . 'installertestfooblah.phpt';
if (@$installer->pkginfo['filelist']['test.php']['installed_as'] == $p) {
    echo "filelist test.php installed_as is correct\n";
} else {
    echo "filelist test.php installed_as is not correct!\n";
}
if (isset($installer->pkginfo['filelist']['dirtree'])) {
    echo "filelist dirtree created\n";
} else {
    echo "filelist dirtree not created!\n";
}
$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
    'glomp';
if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
    echo "filelist dirtree glomp created\n";
} else {
    echo "filelist dirtree glomp not created!\n";
}
$p .= DIRECTORY_SEPARATOR . 'fromp';
if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
    echo "filelist dirtree fromp created\n";
} else {
    echo "filelist dirtree fromp not created!\n";
}

// invalid tests
echo "\n==>Invalid tests\n";
echo "Do valid addFileOperation() delete with non-existing file\n";
$installer->addFileOperation('delete', array('gloober62456.phpt'));
echo 'count($installer->file_operations) = ';
var_dump(count($installer->file_operations));

echo "test invalid commitFileTransaction():\n";
if ($installer->commitFileTransaction()) {
    echo "worked\n";
} else {
    echo "didn't work!\n";
    $installer->rollbackFileTransaction();
}

echo "Do valid addFileOperation() rename with non-existing file\n";
$installer->addFileOperation('rename', array('gloober62456.phpt', 'faber.com'));
echo 'count($installer->file_operations) = ';
var_dump(count($installer->file_operations));

echo "test invalid commitFileTransaction():\n";
if ($installer->commitFileTransaction()) {
    echo "worked\n";
} else {
    echo "didn't work!\n";
    $installer->rollbackFileTransaction();
}

echo "Do valid addFileOperation() chmod with non-existing file\n";
$installer->addFileOperation('chmod', array(0640, 'faber.com'));
echo 'count($installer->file_operations) = ';
var_dump(count($installer->file_operations));

echo "test invalid commitFileTransaction():\n";
if ($installer->commitFileTransaction()) {
    echo "worked\n";
} else {
    echo "didn't work!\n";
    $installer->rollbackFileTransaction();
}

//cleanup
chdir($curdir);
unlink ($temp_path . DIRECTORY_SEPARATOR . 'pear.conf');
unlink ($temp_path . DIRECTORY_SEPARATOR . 'pear.ini');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'php');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'data');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'doc');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'test');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'script');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'ext');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'tmp');
rmdir($temp_path . DIRECTORY_SEPARATOR . 'bin');
rmdir($temp_path);
?>
--EXPECT--
test addFileOperation():
invalid input to addFileOperation():
Returned PEAR_Error? yes
Internal Error: $data in addFileOperation must be an array, was integer
count($installer->file_operations) = int(0)
Do valid addFileOperation() delete
count($installer->file_operations) = int(1)
test valid commitFileTransaction():
about to commit 1 file operations
successfully committed 1 file operations
worked
Do valid addFileOperation() rename
file renamed.phpt exists? no
test valid commitFileTransaction():
about to commit 1 file operations
successfully committed 1 file operations
worked
file renamed.phpt exists? yes
Do valid addFileOperation() chmod
file permissions are: 776
test valid commitFileTransaction():
about to commit 1 file operations
successfully committed 1 file operations
worked
file permissions are: 640
Do valid addFileOperation() rmdir
directory exists? yes
test valid commitFileTransaction():
about to commit 1 file operations
successfully committed 1 file operations
worked
directory exists? no
Do valid addFileOperation() installed_as
test valid commitFileTransaction():
about to commit 1 file operations
successfully committed 1 file operations
worked
filelist created
filelist test.php created
filelist test.php installed_as created
filelist test.php installed_as is correct
filelist dirtree created
filelist dirtree glomp created
filelist dirtree fromp created
Do valid addFileOperation() installed_as
test valid rollbackFileTransaction():
rolling back 1 file operations
filelist created
filelist test.php created
filelist test.php installed_as not created!
filelist test.php installed_as is not correct!
filelist dirtree not created!
filelist dirtree glomp not created!
filelist dirtree fromp not created!

==>Invalid tests
Do valid addFileOperation() delete with non-existing file
count($installer->file_operations) = int(1)
test invalid commitFileTransaction():
about to commit 1 file operations
warning: file gloober62456.phpt doesn't exist, can't be deleted
successfully committed 1 file operations
worked
Do valid addFileOperation() rename with non-existing file
count($installer->file_operations) = int(1)
test invalid commitFileTransaction():
about to commit 1 file operations
cannot rename file gloober62456.phpt, doesn't exist
didn't work!
rolling back 1 file operations
Do valid addFileOperation() chmod with non-existing file
count($installer->file_operations) = int(1)
test invalid commitFileTransaction():
about to commit 1 file operations
permission denied (chmod): faber.com 640
didn't work!
rolling back 1 file operations