summaryrefslogtreecommitdiff
path: root/pear/tests/pear_installer4.phpt
blob: 593d38ad4502c0acdd0040550b38c39e56095ccd (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
--TEST--
PEAR_Installer test #4: PEAR_Installer::install()
--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);
$curdir = getcwd();
chdir(dirname(__FILE__));

PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchit');

$error_to_catch = false;
function catchit($err)
{
    global $error_to_catch;
    if ($error_to_catch) {
        if ($err->getMessage() == $error_to_catch) {
            $error_to_catch = false;
            echo "Caught expected error\n";
            return;
        }
    }
    echo "Caught error: " . $err->getMessage() . "\n";
}

echo "Test package.xml direct install:\n";
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'package.xml');
$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php');
var_dump($reg->listPackages());
echo "zoorb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
echo "goompness/Mopreeb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
echo "goompness/oggbrzitzkee.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";

echo "Test conflicting files:\n";
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'conflictpackage.xml');

echo "After uninstall:\n";
$installer->uninstall('pkg6');
var_dump($reg->listPackages());
echo "zoorb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
echo "goompness/Mopreeb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
echo "goompness/oggbrzitzkee.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";
echo "goompness exists? ";
echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'))
    ? "yes\n" : "no\n";

echo "Test .tgz install:\n";
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz');
$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php');
var_dump($reg->listPackages());
echo "zoorb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
echo "goompness/Mopreeb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
echo "goompness/oggbrzitzkee.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";
echo "After uninstall:\n";
$installer->uninstall('pkg6');
var_dump($reg->listPackages());
echo "zoorb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
echo "goompness/Mopreeb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
echo "goompness/oggbrzitzkee.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";
echo "goompness exists? ";
echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'))
    ? "yes\n" : "no\n";

echo "Test invalid .tgz install:\n";
$error_to_catch = 'unable to unpack ' . dirname(__FILE__) . DIRECTORY_SEPARATOR .
    'test-pkg6' . DIRECTORY_SEPARATOR . 'invalidtgz.tgz';
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'invalidtgz.tgz');
$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php');
var_dump($reg->listPackages());
echo "zoorb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
echo "goompness/Mopreeb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
echo "goompness/oggbrzitzkee.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";

echo "Test missing package.xml in .tgz install:\n";
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'nopackagexml.tgz');
$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php');
var_dump($reg->listPackages());
echo "zoorb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
echo "goompness/Mopreeb.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
echo "goompness/oggbrzitzkee.php exists? ";
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php'
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";

chdir($curdir);
cleanall($temp_path);

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

function cleanall($dir)
{
    $dp = opendir($dir);
    while ($ent = readdir($dp)) {
        if ($ent == '.' || $ent == '..') {
            continue;
        }
        if (is_dir($dir . DIRECTORY_SEPARATOR . $ent)) {
            cleanall($dir . DIRECTORY_SEPARATOR . $ent);
        } else {
            unlink($dir . DIRECTORY_SEPARATOR . $ent);
        }
    }
    closedir($dp);
    rmdir($dir);
}
?>
--EXPECT--
Test package.xml direct install:
array(1) {
  [0]=>
  string(4) "pkg6"
}
zoorb.php exists? yes
goompness/Mopreeb.php exists? yes
goompness/oggbrzitzkee.php exists? yes
Test conflicting files:
Caught error: pear::pkg6conflict: conflicting files found:
groob\goompness\oggbrzitzkee.php (pkg6)
     groob\goompness\Mopreeb.php (pkg6)

After uninstall:
array(0) {
}
zoorb.php exists? no
goompness/Mopreeb.php exists? no
goompness/oggbrzitzkee.php exists? no
goompness exists? no
Test .tgz install:
array(1) {
  [0]=>
  string(4) "pkg6"
}
zoorb.php exists? yes
goompness/Mopreeb.php exists? yes
goompness/oggbrzitzkee.php exists? yes
After uninstall:
array(0) {
}
zoorb.php exists? no
goompness/Mopreeb.php exists? no
goompness/oggbrzitzkee.php exists? no
goompness exists? no
Test invalid .tgz install:
Caught error: Invalid checksum for file "<?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/" : 37649 calculated, 0 expected
Caught expected error
array(0) {
}
zoorb.php exists? no
goompness/Mopreeb.php exists? no
goompness/oggbrzitzkee.php exists? no
Test missing package.xml in .tgz install:
warning : you are using an archive with an old format
Caught error: no package.xml file after extracting the archive
array(0) {
}
zoorb.php exists? no
goompness/Mopreeb.php exists? no
goompness/oggbrzitzkee.php exists? no