summaryrefslogtreecommitdiff
path: root/pear/tests/pear_installer1.phpt
blob: 9daf2ecf07e2427c9c079dbf9a9ea31016389528 (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
--TEST--
PEAR_Installer test extractDownloadFileName, checkDeps
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
    echo 'skip';
}
?>
--FILE--
<?php

require_once "PEAR/Installer.php";
require_once 'PEAR/ChannelFile.php';

$temp_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp';
if (!is_dir($temp_path)) {
    mkdir($temp_path);
}
touch($temp_path . DIRECTORY_SEPARATOR . 'user.conf');
// no UI is needed for these tests
$ui = false;
$config = new PEAR_Config($temp_path . DIRECTORY_SEPARATOR . 'user.conf');
$config->set('php_dir', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp');
$reg = &new PEAR_Registry($config->get('php_dir'));
$chan = new PEAR_ChannelFile;
$chan->setName('oddball');
$chan->setServer('example.com');
$chan->setSummary('oddball');
$chan->setPackageNameRegex('[a-z][a-z0-9]*(?:\.[a-z0-9]+)*');
$reg->addChannel($chan);
$installer = new PEAR_Installer($ui);
$installer->config = &$config;
echo "test extractDownloadFileName:\n";
echo 'existing file: ';
echo ($temp_path . DIRECTORY_SEPARATOR . 'user.conf' ==
     $installer->extractDownloadFileName($temp_path . DIRECTORY_SEPARATOR . 'user.conf',
    $ui)) ? "yes\n" : "no\n";
var_dump($ui);
echo 'invalid match: ';
echo $installer->extractDownloadFileName('27',
    $ui);
echo "\n";
var_dump($ui);
echo 'valid match, no version: ';
echo $installer->extractDownloadFileName('Testpackage', $ui);
echo "\n";
var_dump($ui);
echo 'invalid match, has invalid version: ';
echo $installer->extractDownloadFileName('Testpackage-##', $ui);
echo "\n";
var_dump($ui);
echo 'valid match, has version: ';
echo $installer->extractDownloadFileName('Testpackage-1.2', $ui);
echo "\n";
var_dump($ui);
echo "valid match, has unknown channel:\n";
var_dump($installer->extractDownloadFileName('Unknown::Testpackage', $ui));
var_dump($ui);
echo "invalid match, has known channel, invalid package name:\n";
var_dump($installer->extractDownloadFileName('Oddball::Testpackage', $ui));
var_dump($ui);
echo "valid match, has known channel, valid package name:\n";
var_dump($installer->extractDownloadFileName('Oddball::testpackage.third3', $ui));
var_dump($ui);
echo "valid match, has known channel, valid package name, version:\n";
var_dump($installer->extractDownloadFileName('Oddball::testpackage.third3-54.7354', $ui));
var_dump($ui);

echo "\ntest checkDeps 1:\n";
$fakerel = array('release_deps' =>
array(
    array(
        'type' => 'pkg',
        'rel '=> 'has',
        'name' => 'foo',
        'optional' => 'yes'
    ),
    array(
        'type' => 'pkg',
        'rel '=> 'ge',
        'version' => '1.6',
        'name' => 'bar',
    ),
));
$res = '';
var_dump($installer->checkDeps($fakerel, $res));
var_dump($res);

echo "\ntest checkDeps 1.1:\n";
$fakerel = array('release_deps' =>
array(
    array(
        'type' => 'pkg',
        'rel '=> 'has',
        'name' => 'foo',
        'optional' => 'yes',
        'channel' => 'grob',
    ),
    array(
        'type' => 'pkg',
        'rel '=> 'ge',
        'version' => '1.6',
        'name' => 'bar',
        'channel' => 'prego',
    ),
));
$res = '';
var_dump($installer->checkDeps($fakerel, $res));
var_dump($res);
$fakerel = array('release_deps' =>
array(
    array(
        'type' => 'pkg',
        'rel '=> 'has',
        'name' => 'foo',
        'optional' => 'yes'
    ),
));
echo "\ntest checkDeps 2:\n";
$res = '';
var_dump($installer->checkDeps($fakerel, $res));
var_dump($res);
$fakerel = array('release_deps' =>
array(
    array(
        'type' => 'pkg',
        'rel '=> 'has',
        'name' => 'foo',
        'optional' => 'yes',
        'channel' => 'purple',
    ),
));
echo "\ntest checkDeps 2.1:\n";
$res = '';
var_dump($installer->checkDeps($fakerel, $res));
var_dump($res);
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 extractDownloadFileName:
existing file: yes
bool(false)
invalid match: 27
NULL
valid match, no version: Testpackage
NULL
invalid match, has invalid version: Testpackage-##
NULL
valid match, has version: Testpackage
string(3) "1.2"
valid match, has unknown channel:
array(2) {
  ["channel"]=>
  string(7) "Unknown"
  ["package"]=>
  string(11) "Testpackage"
}
NULL
invalid match, has known channel, invalid package name:
string(20) "Oddball::Testpackage"
NULL
valid match, has known channel, valid package name:
array(2) {
  ["channel"]=>
  string(7) "Oddball"
  ["package"]=>
  string(18) "testpackage.third3"
}
NULL
valid match, has known channel, valid package name, version:
array(2) {
  ["channel"]=>
  string(7) "Oddball"
  ["package"]=>
  string(18) "testpackage.third3"
}
string(7) "54.7354"

test checkDeps 1:
bool(true)
string(29) "
requires package `pear::bar'"

test checkDeps 1.1:
bool(true)
string(30) "
requires package `prego::bar'"

test checkDeps 2:
bool(false)
string(83) "Optional dependencies:
package `pear::foo' is recommended to utilize some features."

test checkDeps 2.1:
bool(false)
string(85) "Optional dependencies:
package `purple::foo' is recommended to utilize some features."