summaryrefslogtreecommitdiff
path: root/pear/tests/pear_downloader_invalid.phpt
blob: 7c10dcd80bdb85a4f0899379eac52fcace24ebf3 (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
--TEST--
PEAR_Downloader::download() invalid values test
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
    echo 'skip';
}
?>
--FILE--
<?php

$server = 'pear.Chiara';
//$server = 'test.pear.php.net';
$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');
}
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'cache')) {
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'cache');
}
// make the fake configuration - we'll use one of these and it should work
$config = serialize(array('master_server' => $server,
    'preferred_state' => 'stable',
    'cache_dir' => $temp_path . DIRECTORY_SEPARATOR . 'cache',
    '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/Downloader.php";
require_once 'PEAR/Installer.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'download_test_classes.php.inc';

// no UI is needed for these tests
$ui = false;
$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";
}

$config = &PEAR_Config::singleton();
// initialize fake pear channel
require_once 'PEAR/ChannelFile.php';
$chan = new PEAR_ChannelFile;
$chan->setName('pear');
$chan->setSummary('PEAR');
$chan->setServer($server);
$chan->setDefaultPEARProtocols();
$reg = new PEAR_Registry($config->get('php_dir'), $chan);
$options = array();
$installer = &new test_PEAR_Downloader($ui, $options, $config);

echo "-=-=-=-=-=-=-=-=- Failure Tests -=-=-=-=-=-=-=-=-=-=-\n";

echo "Test invalid package name:\n";
$packages = array("/invalid+packagename");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages);

echo "Test download of a package with no releases:\n";
$packages = array("noreleases");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages);

echo "Test download of a non-existing package version:\n";
$packages = array("pkg1-1976.9.2");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages);

echo "Test download of a non-existing package release state:\n";
$packages = array("pkg1-snapshot");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages);

echo "Test download of invalid release state:\n";
$packages = array("pkg1-burgerking");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages);

$installer->configSet('preferred_state', 'stable');

echo "Test automatic version resolution (stable):\n";
$packages = array("stabilitytoolow");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages);

echo "Test automatic version resolution (stable) with --force:\n";
$packages = array("stabilitytoolow");
$installer->setOptions(array('force' => true));
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages[0]['info']['version']);

$installer->configSet('preferred_state', 'beta');
$installer->setOptions(array());

echo "Test automatic version resolution (beta):\n";
$packages = array("stabilitytoolow");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages[0]['info']['version']);

$installer->configSet('preferred_state', 'alpha');

echo "Test automatic version resolution (alpha):\n";
$packages = array("stabilitytoolow");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages[0]['info']['version']);

$installer->configSet('preferred_state', 'devel');

echo "Test automatic version resolution (devel):\n";
$packages = array("stabilitytoolow");
$a = $installer->doDownload($packages);
$installpackages = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages[0]['info']['version']);

echo "Test download attempt if a version is already installed:\n";

$forinstall = &new PEAR_Installer($ui);
$forinstall->setOptions(array());
$installer->setOptions(array());

$installer->doDownload(array('pkg6'));
$pkgs = $installer->getDownloadedPackages();
$forinstall->install($pkgs[0]['file']);
$installer->doDownload(array('pkg6'));
var_dump(get_class($a), $installer->getErrorMsgs());

echo "Test download attempt if a version is already installed with --force:\n";

$installer->setOptions(array('force' => true));

$installer->doDownload(array('pkg6'));
$pkgs = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs(), $pkgs[0]['info']['version']);

echo "Test download attempt if a version is already installed with upgrade, same version:\n";

$installer->setOptions(array('upgrade' => true));

$installer->doDownload(array('pkg6'));
$pkgs = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs());

echo "Test download attempt if a version is already installed with upgrade, lesser version:\n";

$installer->setOptions(array('upgrade' => true));

$installer->doDownload(array('pkg6-1.1'));
$pkgs = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs());

echo "Test download attempt with --alldeps, but dependency has no releases:\n";

$installer->setOptions(array('alldeps' => true));

$installer->doDownload(array('depnoreleases'));
$pkgs = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs());

echo "Test download attempt with --onlyreqdeps, but dependency has no releases:\n";

$installer->setOptions(array('onlyreqdeps' => true));

$installer->doDownload(array('depnoreleases'));
$pkgs = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs());

$installer->configSet('preferred_state', 'stable');
echo "Test download attempt with --alldeps, but dependency is too unstable:\n";
$installer->setOptions(array('alldeps' => true));

$installer->doDownload(array('depunstable'));
$pkgs = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs());

echo "Test download attempt with --onlyreqdeps, but dependency is too unstable:\n";

$installer->setOptions(array('onlyreqdeps' => true));

$installer->doDownload(array('depunstable'));
$pkgs = $installer->getDownloadedPackages();
var_dump(get_class($a), $installer->getErrorMsgs());

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

//echo implode("\n", array_values($GLOBALS['totalPHP']));


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

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--
-=-=-=-=-=-=-=-=- Failure Tests -=-=-=-=-=-=-=-=-=-=-
Test invalid package name:
Caught error: Package name '/invalid+packagename' not valid for channel 'pear'
string(10) "pear_error"
array(0) {
}
array(0) {
}
Test download of a package with no releases:
Caught error: No releases found for package 'pear::noreleases'
string(10) "pear_error"
array(0) {
}
array(0) {
}
Test download of a non-existing package version:
Caught error: No release of 'pear::pkg1' with version '1976.9.2' found, latest release is version '2.0b1', stability 'beta', use --force to install
string(10) "pear_error"
array(0) {
}
array(0) {
}
Test download of a non-existing package release state:
Caught error: No release of 'pear::pkg1' with state 'snapshot' found, latest release is version '2.0b1', stability 'beta', use --force to install
string(10) "pear_error"
array(0) {
}
array(0) {
}
Test download of invalid release state:
Caught error: Invalid suffix '-burgerking', be sure to pass a valid PEAR version number or release state
string(10) "pear_error"
array(0) {
}
array(0) {
}
Test automatic version resolution (stable):
Caught error: No release of 'pear::stabilitytoolow' within preferred_state of 'stable' found, latest release is version '3.0dev', stability 'devel', use --force to install
string(10) "pear_error"
array(0) {
}
array(0) {
}
Test automatic version resolution (stable) with --force:
Warning: No release of 'pear::stabilitytoolow' within preferred_state of 'stable' found, latest release, version '3.0dev', stability 'devel' will be downloaded
bool(false)
array(0) {
}
string(6) "3.0dev"
Test automatic version resolution (beta):
bool(false)
array(0) {
}
string(5) "1.0b1"
Test automatic version resolution (alpha):
bool(false)
array(0) {
}
string(5) "2.0a1"
Test automatic version resolution (devel):
bool(false)
array(0) {
}
string(6) "3.0dev"
Test download attempt if a version is already installed:
Package 'pear::pkg6' already installed, skipping
bool(false)
array(0) {
}
Test download attempt if a version is already installed with --force:
bool(false)
array(0) {
}
string(5) "2.0b1"
Test download attempt if a version is already installed with upgrade, same version:
Package 'pear::pkg6', version '2.0b1' already installed, skipping
bool(false)
array(0) {
}
Test download attempt if a version is already installed with upgrade, lesser version:
Package 'pear::pkg6' version '2.0b1'  is installed and 2.0b1 is > requested '1.1', skipping
bool(false)
array(0) {
}
Test download attempt with --alldeps, but dependency has no releases:
bool(false)
array(1) {
  [0]=>
  string(75) "Package 'pear::depnoreleases' dependency 'pear::noreleases' has no releases"
}
Test download attempt with --onlyreqdeps, but dependency has no releases:
bool(false)
array(1) {
  [0]=>
  string(75) "Package 'pear::depnoreleases' dependency 'pear::noreleases' has no releases"
}
Test download attempt with --alldeps, but dependency is too unstable:
bool(false)
array(1) {
  [0]=>
  string(103) "Release for 'pear::depunstable' dependency 'pear::stabilitytoolow' has state 'devel', requires 'stable'"
}
Test download attempt with --onlyreqdeps, but dependency is too unstable:
bool(false)
array(1) {
  [0]=>
  string(103) "Release for 'pear::depunstable' dependency 'pear::stabilitytoolow' has state 'devel', requires 'stable'"
}