~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to pear/tests/pear_installer_install_channels.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
PEAR_Installer test #4: PEAR_Installer::install() with channels
 
3
--SKIPIF--
 
4
<?php
 
5
if (!getenv('PHP_PEAR_RUNTESTS')) {
 
6
    echo 'skip';
 
7
}
 
8
?>
 
9
--FILE--
 
10
<?php
 
11
$temp_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp';
 
12
if (!is_dir($temp_path)) {
 
13
    mkdir($temp_path);
 
14
}
 
15
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'php')) {
 
16
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'php');
 
17
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob');
 
18
}
 
19
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'data')) {
 
20
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'data');
 
21
}
 
22
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'doc')) {
 
23
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'doc');
 
24
}
 
25
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'test')) {
 
26
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'test');
 
27
}
 
28
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'ext')) {
 
29
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'ext');
 
30
}
 
31
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'script')) {
 
32
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'script');
 
33
}
 
34
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'tmp')) {
 
35
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'tmp');
 
36
}
 
37
if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'bin')) {
 
38
    mkdir($temp_path . DIRECTORY_SEPARATOR . 'bin');
 
39
}
 
40
// make the fake configuration - we'll use one of these and it should work
 
41
$config = serialize(array('master_server' => 'pear.php.net',
 
42
    'default_channel' => 'pear',
 
43
    'php_dir' => $temp_path . DIRECTORY_SEPARATOR . 'php',
 
44
    'ext_dir' => $temp_path . DIRECTORY_SEPARATOR . 'ext',
 
45
    'data_dir' => $temp_path . DIRECTORY_SEPARATOR . 'data',
 
46
    'doc_dir' => $temp_path . DIRECTORY_SEPARATOR . 'doc',
 
47
    'test_dir' => $temp_path . DIRECTORY_SEPARATOR . 'test',
 
48
    'bin_dir' => $temp_path . DIRECTORY_SEPARATOR . 'bin',
 
49
    '__channels' => array(
 
50
        'frob' => array(
 
51
            'php_dir' => $temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob',
 
52
    ))));
 
53
touch($temp_path . DIRECTORY_SEPARATOR . 'pear.conf');
 
54
$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.conf', 'w');
 
55
fwrite($fp, $config);
 
56
fclose($fp);
 
57
touch($temp_path . DIRECTORY_SEPARATOR . 'pear.ini');
 
58
$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.ini', 'w');
 
59
fwrite($fp, $config);
 
60
fclose($fp);
 
61
 
 
62
putenv('PHP_PEAR_SYSCONF_DIR='.$temp_path);
 
63
$home = getenv('HOME');
 
64
if (!empty($home)) {
 
65
    // for PEAR_Config initialization
 
66
    putenv('HOME="'.$temp_path);
 
67
}
 
68
require_once 'PEAR/ChannelFile.php';
 
69
require_once 'PEAR/Registry.php';
 
70
$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php');
 
71
$chan = new PEAR_ChannelFile;
 
72
$chan->setName('frob');
 
73
$chan->setSummary('test');
 
74
$chan->setServer('test');
 
75
$reg->addChannel($chan);
 
76
$chan->setName('groob');
 
77
$reg->addChannel($chan);
 
78
require_once "PEAR/Installer.php";
 
79
 
 
80
// no UI is needed for these tests
 
81
$ui = false;
 
82
$installer = new PEAR_Installer($ui);
 
83
$curdir = getcwd();
 
84
chdir(dirname(__FILE__));
 
85
 
 
86
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchit');
 
87
 
 
88
$error_to_catch = false;
 
89
function catchit($err)
 
90
{
 
91
    global $error_to_catch;
 
92
    if ($error_to_catch) {
 
93
        if ($err->getMessage() == $error_to_catch) {
 
94
            $error_to_catch = false;
 
95
            echo "Caught expected error\n";
 
96
            return;
 
97
        }
 
98
    }
 
99
    echo "Caught error: " . $err->getMessage() . "\n";
 
100
}
 
101
 
 
102
echo "Test package.xml direct install:\n";
 
103
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'package2.xml');
 
104
$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php');
 
105
var_dump($reg->listAllPackages());
 
106
echo "zoorb.php exists? ";
 
107
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob'
 
108
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
 
109
echo "goompness/Mopreeb.php exists? ";
 
110
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob'
 
111
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
 
112
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
 
113
echo "goompness/oggbrzitzkee.php exists? ";
 
114
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob'
 
115
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
 
116
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";
 
117
echo "goompness/test.dat exists? ";
 
118
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'pkg6'
 
119
    . DIRECTORY_SEPARATOR . 'goompness'
 
120
    . DIRECTORY_SEPARATOR . 'test.dat')) ? "yes\n" : "no\n";
 
121
 
 
122
echo "Test conflicting files:\n";
 
123
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'conflictpackage2.xml');
 
124
 
 
125
echo "Test unknown channel:\n";
 
126
$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'package2_invalid.xml');
 
127
 
 
128
echo "After uninstall:\n";
 
129
$installer->uninstall('frob::pkg6');
 
130
var_dump($reg->listAllPackages());
 
131
echo "zoorb.php exists? ";
 
132
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob'
 
133
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n";
 
134
echo "goompness/Mopreeb.php exists? ";
 
135
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob'
 
136
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
 
137
    . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n";
 
138
echo "goompness/oggbrzitzkee.php exists? ";
 
139
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'frob'
 
140
    . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness'
 
141
    . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n";
 
142
echo "goompness/test.dat exists? ";
 
143
echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'pkg6'
 
144
    . DIRECTORY_SEPARATOR . 'goompness'
 
145
    . DIRECTORY_SEPARATOR . 'test.dat')) ? "yes\n" : "no\n";
 
146
 
 
147
chdir($curdir);
 
148
cleanall($temp_path);
 
149
 
 
150
// ------------------------------------------------------------------------- //
 
151
 
 
152
function cleanall($dir)
 
153
{
 
154
    $dp = opendir($dir);
 
155
    while ($ent = readdir($dp)) {
 
156
        if ($ent == '.' || $ent == '..') {
 
157
            continue;
 
158
        }
 
159
        if (is_dir($dir . DIRECTORY_SEPARATOR . $ent)) {
 
160
            cleanall($dir . DIRECTORY_SEPARATOR . $ent);
 
161
        } else {
 
162
            unlink($dir . DIRECTORY_SEPARATOR . $ent);
 
163
        }
 
164
    }
 
165
    closedir($dp);
 
166
    rmdir($dir);
 
167
}
 
168
?>
 
169
--GET--
 
170
--POST--
 
171
--EXPECT--
 
172
Test package.xml direct install:
 
173
array(3) {
 
174
  ["frob"]=>
 
175
  array(1) {
 
176
    [0]=>
 
177
    string(4) "pkg6"
 
178
  }
 
179
  ["groob"]=>
 
180
  array(0) {
 
181
  }
 
182
  ["pear"]=>
 
183
  array(0) {
 
184
  }
 
185
}
 
186
zoorb.php exists? yes
 
187
goompness/Mopreeb.php exists? yes
 
188
goompness/oggbrzitzkee.php exists? yes
 
189
goompness/test.dat exists? yes
 
190
Test conflicting files:
 
191
Caught error: groob::pkg6conflict: conflicting files found:
 
192
groob\goompness\oggbrzitzkee.php (frob::pkg6)
 
193
     groob\goompness\Mopreeb.php (frob::pkg6)
 
194
        groob\goompness\test.dat (frob::pkg6)
 
195
 
 
196
Test unknown channel:
 
197
Error: Unknown channel, "gorp"
 
198
Caught error: Installation failed: invalid package file, use option force to install anyway
 
199
After uninstall:
 
200
array(3) {
 
201
  ["frob"]=>
 
202
  array(0) {
 
203
  }
 
204
  ["groob"]=>
 
205
  array(0) {
 
206
  }
 
207
  ["pear"]=>
 
208
  array(0) {
 
209
  }
 
210
}
 
211
zoorb.php exists? no
 
212
goompness/Mopreeb.php exists? no
 
213
goompness/oggbrzitzkee.php exists? no
 
214
goompness/test.dat exists? no