]> granicus.if.org Git - php/commitdiff
This commit was manufactured by cvs2svn to create branch 'PHP_4_3'.
authorSVN Migration <svn@php.net>
Thu, 18 Dec 2003 09:50:21 +0000 (09:50 +0000)
committerSVN Migration <svn@php.net>
Thu, 18 Dec 2003 09:50:21 +0000 (09:50 +0000)
16 files changed:
ext/mbstring/tests/bug26639.phpt [new file with mode: 0644]
pear/tests/dirtree/multiplepackages/pkg1file.php [new file with mode: 0644]
pear/tests/dirtree/multiplepackages/pkg2file.php [new file with mode: 0644]
pear/tests/dirtree/nestedroot/emptydir/fakefile1.php [new file with mode: 0644]
pear/tests/dirtree/nestedroot/emptydir/nesteddir/nestedfile.php [new file with mode: 0644]
pear/tests/dirtree/nestedroot/rootfile.php [new file with mode: 0644]
pear/tests/dirtree/package-fail.xml [new file with mode: 0644]
pear/tests/dirtree/package.xml [new file with mode: 0644]
pear/tests/dirtree/package2.xml [new file with mode: 0644]
pear/tests/dirtree/pkg1-1.0.tgz [new file with mode: 0644]
pear/tests/dirtree/pkg2-1.0.tgz [new file with mode: 0644]
pear/tests/pear_downloader_invalid.phpt [new file with mode: 0644]
pear/tests/pear_downloader_new.phpt [new file with mode: 0644]
pear/tests/pear_downloader_old.phpt [new file with mode: 0644]
pear/tests/pear_installer5.phpt [new file with mode: 0644]
pear/tests/pear_packager.phpt [new file with mode: 0644]

diff --git a/ext/mbstring/tests/bug26639.phpt b/ext/mbstring/tests/bug26639.phpt
new file mode 100644 (file)
index 0000000..651e6f4
--- /dev/null
@@ -0,0 +1,100 @@
+--TEST--
+Bug #26639 (mb_convert_variables() clutters variables beyond the references)
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+$a = "\82 \82¢\82¤\82¦\82¨";
+$b = $a;
+mb_convert_variables("EUC-JP", "Shift_JIS", $b);
+debug_zval_dump($a);
+debug_zval_dump($b);
+unset($a);
+unset($b);
+
+$a = "\82 \82¢\82¤\82¦\82¨";
+$b = &$a;
+mb_convert_variables("EUC-JP", "Shift_JIS", $b);
+debug_zval_dump($a);
+debug_zval_dump($b);
+unset($a);
+unset($b);
+
+$a = "\82 \82¢\82¤\82¦\82¨";
+$b = array($a);
+$c = $b;
+mb_convert_variables("EUC-JP", "Shift_JIS", $c);
+debug_zval_dump($b);
+debug_zval_dump($c);
+unset($a);
+unset($b);
+unset($c);
+
+$a = "\82 \82¢\82¤\82¦\82¨";
+$b = array(&$a);
+$c = $b;
+mb_convert_variables("euc-jp", "shift_jis", $c);
+debug_zval_dump($b);
+debug_zval_dump($c);
+unset($a);
+unset($b);
+unset($c);
+
+$a = "\82 \82¢\82¤\82¦\82¨";
+$b = array($a);
+$c = &$b;
+mb_convert_variables("euc-jp", "shift_jis", $c);
+debug_zval_dump($b);
+debug_zval_dump($c);
+unset($a);
+unset($b);
+unset($c);
+
+$a = "\82 \82¢\82¤\82¦\82¨";
+$b = array(&$a);
+$c = &$b;
+mb_convert_variables("euc-jp", "shift_jis", $c);
+debug_zval_dump($b);
+debug_zval_dump($c);
+unset($a);
+unset($b);
+unset($c);
+?>
+--EXPECT--
+string(10) "\82 \82¢\82¤\82¦\82¨" refcount(2)
+string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(2)
+string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(1)
+string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(1)
+array(1) refcount(2){
+  [0]=>
+  string(10) "\82 \82¢\82¤\82¦\82¨" refcount(2)
+}
+array(1) refcount(2){
+  [0]=>
+  string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(1)
+}
+array(1) refcount(2){
+  [0]=>
+  &string(10) "\82 \82¢\82¤\82¦\82¨" refcount(2)
+}
+array(1) refcount(2){
+  [0]=>
+  string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(1)
+}
+array(1) refcount(1){
+  [0]=>
+  string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(2)
+}
+array(1) refcount(1){
+  [0]=>
+  string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(2)
+}
+array(1) refcount(1){
+  [0]=>
+  string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(2)
+}
+array(1) refcount(1){
+  [0]=>
+  string(10) "¤¢¤¤¤¦¤¨¤ª" refcount(2)
+}
+
diff --git a/pear/tests/dirtree/multiplepackages/pkg1file.php b/pear/tests/dirtree/multiplepackages/pkg1file.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pear/tests/dirtree/multiplepackages/pkg2file.php b/pear/tests/dirtree/multiplepackages/pkg2file.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pear/tests/dirtree/nestedroot/emptydir/fakefile1.php b/pear/tests/dirtree/nestedroot/emptydir/fakefile1.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pear/tests/dirtree/nestedroot/emptydir/nesteddir/nestedfile.php b/pear/tests/dirtree/nestedroot/emptydir/nesteddir/nestedfile.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pear/tests/dirtree/nestedroot/rootfile.php b/pear/tests/dirtree/nestedroot/rootfile.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pear/tests/dirtree/package-fail.xml b/pear/tests/dirtree/package-fail.xml
new file mode 100644 (file)
index 0000000..f2bf6f1
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+    <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
+    <package version="1.0">
+      <name>pkg2</name>
+      <summary>required test for PEAR_Installer</summary>
+      <description>
+        fake package
+      </description>
+      <license>PHP License</license>
+      <maintainers>
+        <maintainer>
+          <user>fakeuser</user>
+          <name>Joe Shmoe</name>
+          <email>nobody@example.com</email>
+          <role>lead</role>
+        </maintainer>
+      </maintainers>
+      <release>
+        <version>1.0</version>
+        <date>2003-12-11</date>
+        <state>stable</state>
+        <notes>
+                       second package
+        </notes>
+        <filelist>
+          <dir name="/" baseinstalldir="test" role="php">
+                  <dir name="multiplepackages" role="php">
+            <file>pkg2file.php</file>
+                  </dir>
+                  <dir name="nestedroot" role="php">
+            <file>rootfile.php</file>
+                       <dir name="emptydir" role="php">
+                        <dir name="nesteddir" role="php">
+                         <file>nestedfile.php</file>
+                         <file>doesntexist.php</file>
+                        </dir>
+                       </dir>
+                  </dir>
+          </dir>
+        </filelist>
+      </release>
+   </package>
diff --git a/pear/tests/dirtree/package.xml b/pear/tests/dirtree/package.xml
new file mode 100644 (file)
index 0000000..8ba556e
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+    <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
+    <package version="1.0">
+      <name>pkg1</name>
+      <summary>required test for PEAR_Installer</summary>
+      <description>
+        fake package
+      </description>
+      <license>PHP License</license>
+      <maintainers>
+        <maintainer>
+          <user>fakeuser</user>
+          <name>Joe Shmoe</name>
+          <email>nobody@example.com</email>
+          <role>lead</role>
+        </maintainer>
+      </maintainers>
+      <release>
+        <version>1.0</version>
+        <date>2003-12-11</date>
+        <state>stable</state>
+        <notes>
+                       first package
+        </notes>
+        <filelist>
+          <dir name="/" baseinstalldir="test" role="php">
+                  <dir name="multiplepackages" role="php">
+            <file>pkg1file.php</file>
+                  </dir>
+                  <dir name="pkg1" role="php">
+            <file>randomfile.php</file>
+                  </dir>
+          </dir>
+        </filelist>
+      </release>
+   </package>
diff --git a/pear/tests/dirtree/package2.xml b/pear/tests/dirtree/package2.xml
new file mode 100644 (file)
index 0000000..c0bde59
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+    <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
+    <package version="1.0">
+      <name>pkg2</name>
+      <summary>required test for PEAR_Installer</summary>
+      <description>
+        fake package
+      </description>
+      <license>PHP License</license>
+      <maintainers>
+        <maintainer>
+          <user>fakeuser</user>
+          <name>Joe Shmoe</name>
+          <email>nobody@example.com</email>
+          <role>lead</role>
+        </maintainer>
+      </maintainers>
+      <release>
+        <version>1.0</version>
+        <date>2003-12-11</date>
+        <state>stable</state>
+        <notes>
+                       second package
+        </notes>
+        <filelist>
+          <dir name="/" baseinstalldir="test" role="php">
+                  <dir name="multiplepackages" role="php">
+            <file>pkg2file.php</file>
+                  </dir>
+                  <dir name="nestedroot" role="php">
+            <file>rootfile.php</file>
+                       <dir name="emptydir" role="php">
+                        <dir name="nesteddir" role="php">
+                         <file>nestedfile.php</file>
+                        </dir>
+                       </dir>
+                  </dir>
+          </dir>
+        </filelist>
+      </release>
+   </package>
diff --git a/pear/tests/dirtree/pkg1-1.0.tgz b/pear/tests/dirtree/pkg1-1.0.tgz
new file mode 100644 (file)
index 0000000..ab305f7
Binary files /dev/null and b/pear/tests/dirtree/pkg1-1.0.tgz differ
diff --git a/pear/tests/dirtree/pkg2-1.0.tgz b/pear/tests/dirtree/pkg2-1.0.tgz
new file mode 100644 (file)
index 0000000..18bc9d2
Binary files /dev/null and b/pear/tests/dirtree/pkg2-1.0.tgz differ
diff --git a/pear/tests/pear_downloader_invalid.phpt b/pear/tests/pear_downloader_invalid.phpt
new file mode 100644 (file)
index 0000000..04e41c0
--- /dev/null
@@ -0,0 +1,366 @@
+--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";
+
+// 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();
+$options = array();
+$installer = &new PEAR_Downloader($ui, $options, $config);
+
+echo "-=-=-=-=-=-=-=-=- Failure Tests -=-=-=-=-=-=-=-=-=-=-\n";
+
+echo "Test invalid package name:\n";
+$packages = array("/invalid+packagename");
+$a = $installer->download($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->download($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->download($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->download($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->download($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->download($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->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump(get_class($a), $installer->getErrorMsgs(), $installpackages[0]['info']['version']);
+
+$installer->configSet('preferred_state', 'beta');
+
+echo "Test automatic version resolution (beta):\n";
+$packages = array("stabilitytoolow");
+$a = $installer->download($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->download($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->download($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";
+
+require_once 'PEAR/Installer.php';
+$install = &new PEAR_Installer($ui);
+$installer->setOptions(array());
+
+$installer->download(array('pkg6'));
+$pkgs = $installer->getDownloadedPackages();
+$install->install($pkgs[0]['file']);
+$installer->download(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->download(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->download(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->download(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->download(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->download(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->download(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->download(array('depunstable'));
+$pkgs = $installer->getDownloadedPackages();
+var_dump(get_class($a), $installer->getErrorMsgs());
+
+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);
+}
+?>
+--GET--
+--POST--
+--EXPECT--
+-=-=-=-=-=-=-=-=- Failure Tests -=-=-=-=-=-=-=-=-=-=-
+Test invalid package name:
+Caught error: Package name '/invalid+packagename' not valid
+string(10) "pear_error"
+array(0) {
+}
+array(0) {
+}
+Test download of a package with no releases:
+Caught error: No releases found for package 'noreleases'
+string(10) "pear_error"
+array(0) {
+}
+array(0) {
+}
+Test download of a non-existing package version:
+Caught error: No release with version '1976.9.2' found for 'pkg1'
+string(10) "pear_error"
+array(0) {
+}
+array(0) {
+}
+Test download of a non-existing package release state:
+Caught error: No release with state 'snapshot' found for 'pkg1'
+string(10) "pear_error"
+array(0) {
+}
+array(0) {
+}
+Test download of invalid release state:
+Caught error: Invalid postfix '-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 with state equal to: 'stable' found for 'stabilitytoolow'
+string(10) "pear_error"
+array(0) {
+}
+array(0) {
+}
+Test automatic version resolution (stable) with --force:
+Warning: stabilitytoolow is state 'devel' which is less stable than state 'stable'
+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 '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 'pkg6-2.0b1' already installed, skipping
+bool(false)
+array(0) {
+}
+Test download attempt if a version is already installed with upgrade, lesser version:
+Package '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(63) "Package 'depnoreleases' dependency 'noreleases' has no releases"
+}
+Test download attempt with --onlyreqdeps, but dependency has no releases:
+bool(false)
+array(1) {
+  [0]=>
+  string(63) "Package 'depnoreleases' dependency 'noreleases' has no releases"
+}
+Test download attempt with --alldeps, but dependency is too unstable:
+bool(false)
+array(1) {
+  [0]=>
+  string(91) "Release for 'depunstable' dependency 'stabilitytoolow' has state 'devel', requires 'stable'"
+}
+Test download attempt with --onlyreqdeps, but dependency is too unstable:
+bool(false)
+array(1) {
+  [0]=>
+  string(91) "Release for 'depunstable' dependency 'stabilitytoolow' has state 'devel', requires 'stable'"
+}
\ No newline at end of file
diff --git a/pear/tests/pear_downloader_new.phpt b/pear/tests/pear_downloader_new.phpt
new file mode 100644 (file)
index 0000000..4d6e8c7
--- /dev/null
@@ -0,0 +1,570 @@
+--TEST--
+PEAR_Downloader::download() 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";
+
+// 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";
+}
+
+echo "Test simple direct url download:\n";
+
+$config = &PEAR_Config::singleton();
+$packages = array("http://$server/get/pkg6-1.1.tgz");
+$options = array();
+$installer = &new PEAR_Downloader($ui, $options, $config);
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+unset($installpackages[0]['file']);
+var_dump($installpackages);
+
+echo "Test simple package name download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6');
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+unset($installpackages[0]['file']);
+var_dump($installpackages);
+
+echo "Test package name with version download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6-1.1');
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+
+echo "Test package name with state stable download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6-stable');
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+
+echo "Test package name with state beta download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6-beta');
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-2.0b1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+
+echo "================\nTest preferred_state = beta\n";
+$installer->configSet('preferred_state', 'beta');
+
+echo "Test simple package name download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6');
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-2.0b1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+unset($installpackages[0]['file']);
+
+echo "\n================Test --alldeps\nTest preferred_state = stable\n";
+$installer->configSet('preferred_state', 'stable');
+
+$installer = &new PEAR_Downloader($ui, array('alldeps' => true), $config);
+$packages = array("http://$server/get/pkg1-1.1.tgz");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+$packages = array("pkg1");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = beta:\n";
+$installer->configSet('preferred_state', 'beta');
+
+$packages = array("pkg1");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = alpha:\n";
+$installer->configSet('preferred_state', 'alpha');
+
+$packages = array("pkg1");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+echo "\n================Test --onlyreqdeps\nTest preferred_state = stable\n";
+$config->set('preferred_state', 'stable');
+
+$installer = &new PEAR_Downloader($ui, array('onlyreqdeps' => true), $config);
+$packages = array("http://$server/get/pkg1-1.1.tgz");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+$packages = array("pkg1");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = beta:\n";
+$installer->configSet('preferred_state', 'beta');
+
+$packages = array("pkg1");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = alpha:\n";
+$installer->configSet('preferred_state', 'alpha');
+
+$packages = array("pkg1");
+$a = $installer->download($packages);
+$installpackages = $installer->getDownloadedPackages();
+var_dump($a, $installer->getErrorMsgs());
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\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);
+}
+?>
+--GET--
+--POST--
+--EXPECT--
+Test simple direct url download:
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+array(1) {
+  [0]=>
+  array(2) {
+    ["pkg"]=>
+    string(4) "pkg6"
+    ["info"]=>
+    array(11) {
+      ["provides"]=>
+      array(0) {
+      }
+      ["filelist"]=>
+      &array(3) {
+        ["zoorb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\oggbrzitzkee.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\Mopreeb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+      }
+      ["package"]=>
+      string(4) "pkg6"
+      ["summary"]=>
+      string(32) "required test for PEAR_Installer"
+      ["description"]=>
+      string(12) "fake package"
+      ["maintainers"]=>
+      array(1) {
+        [0]=>
+        &array(4) {
+          ["handle"]=>
+          string(8) "fakeuser"
+          ["name"]=>
+          string(9) "Joe Shmoe"
+          ["email"]=>
+          string(18) "nobody@example.com"
+          ["role"]=>
+          string(4) "lead"
+        }
+      }
+      ["version"]=>
+      string(3) "1.1"
+      ["release_date"]=>
+      string(10) "2003-09-09"
+      ["release_license"]=>
+      string(11) "PHP License"
+      ["release_state"]=>
+      string(6) "stable"
+      ["release_notes"]=>
+      string(24) "required dependency test"
+    }
+  }
+}
+Test simple package name download:
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+array(1) {
+  [0]=>
+  array(2) {
+    ["pkg"]=>
+    string(4) "pkg6"
+    ["info"]=>
+    array(11) {
+      ["provides"]=>
+      array(0) {
+      }
+      ["filelist"]=>
+      &array(3) {
+        ["zoorb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\oggbrzitzkee.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\Mopreeb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+      }
+      ["package"]=>
+      string(4) "pkg6"
+      ["summary"]=>
+      string(32) "required test for PEAR_Installer"
+      ["description"]=>
+      string(12) "fake package"
+      ["maintainers"]=>
+      array(1) {
+        [0]=>
+        &array(4) {
+          ["handle"]=>
+          string(8) "fakeuser"
+          ["name"]=>
+          string(9) "Joe Shmoe"
+          ["email"]=>
+          string(18) "nobody@example.com"
+          ["role"]=>
+          string(4) "lead"
+        }
+      }
+      ["version"]=>
+      string(3) "1.1"
+      ["release_date"]=>
+      string(10) "2003-09-09"
+      ["release_license"]=>
+      string(11) "PHP License"
+      ["release_state"]=>
+      string(6) "stable"
+      ["release_notes"]=>
+      string(24) "required dependency test"
+    }
+  }
+}
+Test package name with version download:
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+Test package name with state stable download:
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+Test package name with state beta download:
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+================
+Test preferred_state = beta
+Test simple package name download:
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+
+================Test --alldeps
+Test preferred_state = stable
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+Test preferred_state = beta:
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
+Test preferred_state = alpha:
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.4
+pkg4AndAHalf-1.3
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
+
+================Test --onlyreqdeps
+Test preferred_state = stable
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+Test preferred_state = beta:
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
+Test preferred_state = alpha:
+skipping Package 'pkg3' optional dependency 'pkg4AndAHalf'
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.4
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
\ No newline at end of file
diff --git a/pear/tests/pear_downloader_old.phpt b/pear/tests/pear_downloader_old.phpt
new file mode 100644 (file)
index 0000000..381dfca
--- /dev/null
@@ -0,0 +1,598 @@
+--TEST--
+PEAR_Installer test: PEAR_Installer::download() (deprecated)
+--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/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');
+set_error_handler('catchphp');
+
+function catchphp($errno, $errmsg)
+{
+    if (error_reporting() == 0) {
+        return;
+    }
+    $errlevel = array(
+        E_USER_NOTICE => 'Notice',
+        E_USER_WARNING => 'Warning',
+        E_USER_ERROR => 'Error',
+        E_WARNING => 'Warning',
+        E_NOTICE => 'Notice'
+    );
+    echo $errlevel[$errno] . ': ' . $errmsg . "\n";
+}
+$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 simple direct url download:\n";
+
+$config = &PEAR_Config::singleton();
+$packages = array("http://$server/get/pkg6-1.1.tgz");
+$a = $installer->download($packages, array(), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+unset($installpackages[0]['file']);
+var_dump($installpackages);
+
+echo "Test simple package name download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6');
+$a = $installer->download($packages, array(), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+unset($installpackages[0]['file']);
+var_dump($installpackages);
+
+echo "Test package name with version download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6-1.1');
+$a = $installer->download($packages, array(), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+
+echo "Test package name with state stable download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6-stable');
+$a = $installer->download($packages, array(), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+
+echo "Test package name with state beta download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6-beta');
+$a = $installer->download($packages, array(), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-2.0b1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+
+echo "================\nTest preferred_state = beta\n";
+$config->set('preferred_state', 'beta');
+
+echo "Test simple package name download:\n";
+$installpackages = $errors = array();
+$packages = array('pkg6');
+$a = $installer->download($packages, array(), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-2.0b1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+unset($installpackages[0]['file']);
+
+echo "\n================Test --alldeps\nTest preferred_state = stable\n";
+$config->set('preferred_state', 'stable');
+
+$config = &PEAR_Config::singleton();
+$packages = array("http://$server/get/pkg1-1.1.tgz");
+$a = $installer->download($packages, array('alldeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+$packages = array("pkg1");
+$a = $installer->download($packages, array('alldeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = beta:\n";
+$config->set('preferred_state', 'beta');
+
+$config = &PEAR_Config::singleton();
+$packages = array("pkg1");
+$a = $installer->download($packages, array('alldeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = alpha:\n";
+$config->set('preferred_state', 'alpha');
+
+$config = &PEAR_Config::singleton();
+$packages = array("pkg1");
+$a = $installer->download($packages, array('alldeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+echo "\n================Test --onlyreqdeps\nTest preferred_state = stable\n";
+$config->set('preferred_state', 'stable');
+
+$config = &PEAR_Config::singleton();
+$packages = array("http://$server/get/pkg1-1.1.tgz");
+$a = $installer->download($packages, array('onlyreqdeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+$packages = array("pkg1");
+$a = $installer->download($packages, array('onlyreqdeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = beta:\n";
+$config->set('preferred_state', 'beta');
+
+$config = &PEAR_Config::singleton();
+$packages = array("pkg1");
+$a = $installer->download($packages, array('onlyreqdeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+echo "Test preferred_state = alpha:\n";
+$config->set('preferred_state', 'alpha');
+
+$config = &PEAR_Config::singleton();
+$packages = array("pkg1");
+$a = $installer->download($packages, array('onlyreqdeps' => true), &$config, &$installpackages, &$errors);
+var_dump($a, $errors);
+echo "Packages downloaded and version:\n";
+foreach ($installpackages as $package) {
+    echo $package['pkg'] . '-' . $package['info']['version'] . "\n";
+}
+
+
+chdir($curdir);
+cleanall($temp_path);
+/*
+echo "File exists? ";
+echo (is_file($installpackages[0]['file'])) ? "yes\n" : "no\n";
+echo "File is the same? ";
+$good = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'));
+$dled = implode('', file($installpackages[0]['file']));
+echo ($good == $dled) ? "yes\n" : "no\n";
+unlink($installpackages[0]['file']);
+unset($installpackages[0]['file']);*/
+// ------------------------------------------------------------------------- //
+
+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);
+}
+?>
+--GET--
+--POST--
+--EXPECT--
+Test simple direct url download:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+array(1) {
+  [0]=>
+  array(2) {
+    ["pkg"]=>
+    string(4) "pkg6"
+    ["info"]=>
+    array(11) {
+      ["provides"]=>
+      array(0) {
+      }
+      ["filelist"]=>
+      &array(3) {
+        ["zoorb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\oggbrzitzkee.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\Mopreeb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+      }
+      ["package"]=>
+      string(4) "pkg6"
+      ["summary"]=>
+      string(32) "required test for PEAR_Installer"
+      ["description"]=>
+      string(12) "fake package"
+      ["maintainers"]=>
+      array(1) {
+        [0]=>
+        &array(4) {
+          ["handle"]=>
+          string(8) "fakeuser"
+          ["name"]=>
+          string(9) "Joe Shmoe"
+          ["email"]=>
+          string(18) "nobody@example.com"
+          ["role"]=>
+          string(4) "lead"
+        }
+      }
+      ["version"]=>
+      string(3) "1.1"
+      ["release_date"]=>
+      string(10) "2003-09-09"
+      ["release_license"]=>
+      string(11) "PHP License"
+      ["release_state"]=>
+      string(6) "stable"
+      ["release_notes"]=>
+      string(24) "required dependency test"
+    }
+  }
+}
+Test simple package name download:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+array(1) {
+  [0]=>
+  array(2) {
+    ["pkg"]=>
+    string(4) "pkg6"
+    ["info"]=>
+    array(11) {
+      ["provides"]=>
+      array(0) {
+      }
+      ["filelist"]=>
+      &array(3) {
+        ["zoorb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\oggbrzitzkee.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+        ["goompness\Mopreeb.php"]=>
+        array(2) {
+          ["role"]=>
+          string(3) "php"
+          ["baseinstalldir"]=>
+          string(5) "groob"
+        }
+      }
+      ["package"]=>
+      string(4) "pkg6"
+      ["summary"]=>
+      string(32) "required test for PEAR_Installer"
+      ["description"]=>
+      string(12) "fake package"
+      ["maintainers"]=>
+      array(1) {
+        [0]=>
+        &array(4) {
+          ["handle"]=>
+          string(8) "fakeuser"
+          ["name"]=>
+          string(9) "Joe Shmoe"
+          ["email"]=>
+          string(18) "nobody@example.com"
+          ["role"]=>
+          string(4) "lead"
+        }
+      }
+      ["version"]=>
+      string(3) "1.1"
+      ["release_date"]=>
+      string(10) "2003-09-09"
+      ["release_license"]=>
+      string(11) "PHP License"
+      ["release_state"]=>
+      string(6) "stable"
+      ["release_notes"]=>
+      string(24) "required dependency test"
+    }
+  }
+}
+Test package name with version download:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+Test package name with state stable download:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+Test package name with state beta download:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+================
+Test preferred_state = beta
+Test simple package name download:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+File exists? yes
+File is the same? yes
+
+================Test --alldeps
+Test preferred_state = stable
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+Test preferred_state = beta:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
+Test preferred_state = alpha:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.4
+pkg4AndAHalf-1.3
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
+
+================Test --onlyreqdeps
+Test preferred_state = stable
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-1.1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-1.1
+Test preferred_state = beta:
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.1
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
+Test preferred_state = alpha:
+skipping Package 'pkg3' optional dependency 'pkg4AndAHalf'
+Warning: PEAR Warning: PEAR_Installer::download() is deprecated in favor of PEAR_Downloader class
+NULL
+array(0) {
+}
+Packages downloaded and version:
+pkg1-2.0b1
+pkg2-1.1
+pkg3-1.4
+pkg4-1.1
+pkg5-1.1
+pkg6-2.0b1
\ No newline at end of file
diff --git a/pear/tests/pear_installer5.phpt b/pear/tests/pear_installer5.phpt
new file mode 100644 (file)
index 0000000..77415b9
--- /dev/null
@@ -0,0 +1,226 @@
+--TEST--
+PEAR_Installer test #5: test directory tracking/deletion of installation
+--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";
+}
+
+$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirtree' . DIRECTORY_SEPARATOR . 'package.xml');
+$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirtree' . DIRECTORY_SEPARATOR . 'package2.xml');
+$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php');
+var_dump($reg->listPackages());
+$info = $reg->packageInfo('pkg1');
+echo "pkg1 dir tree contains test/? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test'])) ? "yes\n" : "no\n";
+echo "pkg1 dir tree contains test/multiplepackages? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'multiplepackages'])) ? "yes\n" : "no\n";
+echo "pkg1 dir tree contains test/pkg1? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'pkg1'])) ? "yes\n" : "no\n";
+
+$info = $reg->packageInfo('pkg2');
+echo "pkg2 dir tree contains test/? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test'])) ? "yes\n" : "no\n";
+echo "pkg2 dir tree contains test/multiplepackages? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'multiplepackages'])) ? "yes\n" : "no\n";
+echo "pkg2 dir tree contains test/nestedroot? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot'])) ? "yes\n" : "no\n";
+echo "pkg2 dir tree contains test/nestedroot/emptydir? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot'
+    . DIRECTORY_SEPARATOR . 'emptydir'])) ? "yes\n" : "no\n";
+echo "pkg2 dir tree contains test/nestedroot/emptydir/nesteddir? ";
+echo (isset($info['filelist']['dirtree'][$temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot'
+    . DIRECTORY_SEPARATOR . 'emptydir' . DIRECTORY_SEPARATOR . 'nesteddir'])) ? "yes\n" : "no\n";
+
+echo "After uninstall of pkg1:\n";
+$installer->uninstall('pkg1');
+echo "test/ exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test')) ? "yes\n" : "no\n";
+echo "test/multiplepackages exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'multiplepackages')) ? "yes\n" : "no\n";
+echo "test/pkg1 exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'pkg1')) ? "yes\n" : "no\n";
+echo "test/nestedroot exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot')) ? "yes\n" : "no\n";
+echo "test/nestedroot/emptydir exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot'
+    . DIRECTORY_SEPARATOR . 'emptydir')) ? "yes\n" : "no\n";
+echo "test/nestedroot/emptydir/nesteddir exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot'
+    . DIRECTORY_SEPARATOR . 'emptydir'. DIRECTORY_SEPARATOR . 'nesteddir')) ? "yes\n" : "no\n";
+var_dump($reg->listPackages());
+
+echo "After uninstall of pkg2:\n";
+$installer->uninstall('pkg2');
+echo "test/ exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test')) ? "yes\n" : "no\n";
+echo "test/multiplepackages exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'multiplepackages')) ? "yes\n" : "no\n";
+echo "test/pkg1 exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'pkg1')) ? "yes\n" : "no\n";
+echo "test/nestedroot exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot')) ? "yes\n" : "no\n";
+echo "test/nestedroot/emptydir exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot'
+    . DIRECTORY_SEPARATOR . 'emptydir')) ? "yes\n" : "no\n";
+echo "test/nestedroot/emptydir/nesteddir exists? ";
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php'
+    . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'nestedroot'
+    . DIRECTORY_SEPARATOR . 'emptydir'. DIRECTORY_SEPARATOR . 'nesteddir')) ? "yes\n" : "no\n";
+var_dump($reg->listPackages());
+
+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);
+}
+?>
+--GET--
+--POST--
+--EXPECT--
+array(2) {
+  [0]=>
+  string(4) "pkg1"
+  [1]=>
+  string(4) "pkg2"
+}
+pkg1 dir tree contains test/? yes
+pkg1 dir tree contains test/multiplepackages? yes
+pkg1 dir tree contains test/pkg1? yes
+pkg2 dir tree contains test/? yes
+pkg2 dir tree contains test/multiplepackages? yes
+pkg2 dir tree contains test/nestedroot? yes
+pkg2 dir tree contains test/nestedroot/emptydir? yes
+pkg2 dir tree contains test/nestedroot/emptydir/nesteddir? yes
+After uninstall of pkg1:
+test/ exists? yes
+test/multiplepackages exists? yes
+test/pkg1 exists? no
+test/nestedroot exists? yes
+test/nestedroot/emptydir exists? yes
+test/nestedroot/emptydir/nesteddir exists? yes
+array(1) {
+  [0]=>
+  string(4) "pkg2"
+}
+After uninstall of pkg2:
+test/ exists? no
+test/multiplepackages exists? no
+test/pkg1 exists? no
+test/nestedroot exists? no
+test/nestedroot/emptydir exists? no
+test/nestedroot/emptydir/nesteddir exists? no
+array(0) {
+}
\ No newline at end of file
diff --git a/pear/tests/pear_packager.phpt b/pear/tests/pear_packager.phpt
new file mode 100644 (file)
index 0000000..9d584b2
--- /dev/null
@@ -0,0 +1,432 @@
+--TEST--
+PEAR_Packager test
+--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/Packager.php";
+
+$packager = new PEAR_Packager();
+$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";
+}
+ob_start();
+$packager->package(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirtree' . DIRECTORY_SEPARATOR . 'package.xml');
+$packager->package(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirtree' . DIRECTORY_SEPARATOR . 'package2.xml');
+$stuff = str_replace(array(dirname(__FILE__) . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), array('', '/'),
+    ob_get_contents());
+ob_end_clean();
+echo $stuff;
+
+$archive1 = &new Archive_Tar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pkg1-1.0.tgz');
+$archive1c = &new Archive_Tar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirtree' .
+    DIRECTORY_SEPARATOR . 'pkg1-1.0.tgz');
+$x1 = $archive1->listContent();
+$x2 = $archive1c->listContent();
+for($i=0;$i<count($x1); $i++) {
+    if ($x1[$i]['filename'] == 'package.xml') {
+        unset($x1[$i]['mtime']);
+        unset($x1[$i]['checksum']);
+    }
+}
+for($i=0;$i<count($x2); $i++) {
+    if ($x2[$i]['filename'] == 'package.xml') {
+        unset($x2[$i]['mtime']);
+        unset($x2[$i]['checksum']);
+    }
+}
+var_dump($x1, $x2);
+$archive1 = &new Archive_Tar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pkg2-1.0.tgz');
+$archive1c = &new Archive_Tar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirtree' .
+    DIRECTORY_SEPARATOR . 'pkg2-1.0.tgz');
+$x1 = $archive1->listContent();
+$x2 = $archive1c->listContent();
+for($i=0;$i<count($x1); $i++) {
+    if ($x1[$i]['filename'] == 'package.xml') {
+        unset($x1[$i]['mtime']);
+        unset($x1[$i]['checksum']);
+    }
+}
+for($i=0;$i<count($x2); $i++) {
+    if ($x2[$i]['filename'] == 'package.xml') {
+        unset($x2[$i]['mtime']);
+        unset($x2[$i]['checksum']);
+    }
+}
+var_dump($x1, $x2);
+
+echo "test failure:\n";
+$packager->package(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'dirtree' . DIRECTORY_SEPARATOR . 'package-fail.xml');
+
+unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pkg1-1.0.tgz');
+unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pkg2-1.0.tgz');
+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);
+}
+?>
+--GET--
+--POST--
+--EXPECT--
+Analyzing multiplepackages/pkg1file.php
+Analyzing pkg1/randomfile.php
+Package pkg1-1.0.tgz done
+Tag the released code with `pear cvstag package.xml'
+(or set the CVS tag RELEASE_1_0 by hand)
+Analyzing multiplepackages/pkg2file.php
+Analyzing nestedroot/rootfile.php
+Analyzing nestedroot/emptydir/nesteddir/nestedfile.php
+Package pkg2-1.0.tgz done
+Tag the released code with `pear cvstag package2.xml'
+(or set the CVS tag RELEASE_1_0 by hand)
+array(3) {
+  [0]=>
+  array(6) {
+    ["filename"]=>
+    string(11) "package.xml"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(817)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [1]=>
+  array(8) {
+    ["checksum"]=>
+    int(5592)
+    ["filename"]=>
+    string(38) "pkg1-1.0/multiplepackages/pkg1file.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119017)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [2]=>
+  array(8) {
+    ["checksum"]=>
+    int(4534)
+    ["filename"]=>
+    string(28) "pkg1-1.0/pkg1/randomfile.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071120110)
+    ["typeflag"]=>
+    string(0) ""
+  }
+}
+array(3) {
+  [0]=>
+  array(6) {
+    ["filename"]=>
+    string(11) "package.xml"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(817)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [1]=>
+  array(8) {
+    ["checksum"]=>
+    int(5592)
+    ["filename"]=>
+    string(38) "pkg1-1.0/multiplepackages/pkg1file.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119017)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [2]=>
+  array(8) {
+    ["checksum"]=>
+    int(4534)
+    ["filename"]=>
+    string(28) "pkg1-1.0/pkg1/randomfile.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071120110)
+    ["typeflag"]=>
+    string(0) ""
+  }
+}
+array(4) {
+  [0]=>
+  array(6) {
+    ["filename"]=>
+    string(11) "package.xml"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(921)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [1]=>
+  array(8) {
+    ["checksum"]=>
+    int(5600)
+    ["filename"]=>
+    string(38) "pkg2-1.0/multiplepackages/pkg2file.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119030)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [2]=>
+  array(8) {
+    ["checksum"]=>
+    int(5066)
+    ["filename"]=>
+    string(32) "pkg2-1.0/nestedroot/rootfile.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119266)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [3]=>
+  array(8) {
+    ["checksum"]=>
+    int(7193)
+    ["filename"]=>
+    string(53) "pkg2-1.0/nestedroot/emptydir/nesteddir/nestedfile.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119310)
+    ["typeflag"]=>
+    string(0) ""
+  }
+}
+array(4) {
+  [0]=>
+  array(6) {
+    ["filename"]=>
+    string(11) "package.xml"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(921)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [1]=>
+  array(8) {
+    ["checksum"]=>
+    int(5600)
+    ["filename"]=>
+    string(38) "pkg2-1.0/multiplepackages/pkg2file.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119030)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [2]=>
+  array(8) {
+    ["checksum"]=>
+    int(5066)
+    ["filename"]=>
+    string(32) "pkg2-1.0/nestedroot/rootfile.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119266)
+    ["typeflag"]=>
+    string(0) ""
+  }
+  [3]=>
+  array(8) {
+    ["checksum"]=>
+    int(7193)
+    ["filename"]=>
+    string(53) "pkg2-1.0/nestedroot/emptydir/nesteddir/nestedfile.php"
+    ["mode"]=>
+    int(33206)
+    ["uid"]=>
+    int(0)
+    ["gid"]=>
+    int(0)
+    ["size"]=>
+    int(0)
+    ["mtime"]=>
+    int(1071119310)
+    ["typeflag"]=>
+    string(0) ""
+  }
+}
+test failure:
+Analyzing multiplepackages\pkg2file.php
+Analyzing nestedroot\rootfile.php
+Analyzing nestedroot\emptydir\nesteddir\nestedfile.php
+Analyzing nestedroot\emptydir\nesteddir\doesntexist.php
+Caught error: File does not exist: nestedroot\emptydir\nesteddir\doesntexist.php
\ No newline at end of file