From: SVN Migration Date: Sat, 6 Dec 2003 06:06:51 +0000 (+0000) Subject: This commit was manufactured by cvs2svn to create branch 'PHP_4_3'. X-Git-Tag: php-4.3.5RC1~109 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e0820820a41780fd7665d365a9b521549cd397a;p=php This commit was manufactured by cvs2svn to create branch 'PHP_4_3'. --- diff --git a/pear/PEAR/Downloader.php b/pear/PEAR/Downloader.php new file mode 100644 index 0000000000..46527e5c12 --- /dev/null +++ b/pear/PEAR/Downloader.php @@ -0,0 +1,612 @@ + | +// | Tomas V.V.Cox | +// | Martin Jansen | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once 'PEAR/Common.php'; +require_once 'PEAR/Registry.php'; +require_once 'PEAR/Dependency.php'; +require_once 'PEAR/Remote.php'; +require_once 'System.php'; + +/** + * Administration class used to download PEAR packages and maintain the + * installed package database. + * + * @since PEAR 1.4 + * @author Greg Beaver + */ +class PEAR_Downloader extends PEAR_Common +{ + /** + * @var PEAR_Config + * @access private + */ + var $_config; + + /** + * @var PEAR_Registry + * @access private + */ + var $_registry; + + /** + * @var PEAR_Remote + * @access private + */ + var $_remote; + + /** + * Preferred Installation State (snapshot, devel, alpha, beta, stable) + * @var string|null + * @access private + */ + var $_preferredState; + + /** + * Options from command-line passed to Install. + * + * Recognized options:
+ * - onlyreqdeps : install all required dependencies as well + * - alldeps : install all dependencies, including optional + * - installroot : base relative path to install files in + * - force : force a download even if warnings would prevent it + * @see PEAR_Command_Install + * @access private + * @var array + */ + var $_options; + + /** + * Downloaded Packages after a call to download(). + * + * Format of each entry: + * + * + * array('pkg' => 'package_name', 'file' => '/path/to/local/file', + * 'info' => array() // parsed package.xml + * ); + * + * @access private + * @var array + */ + var $_downloadedPackages = array(); + + /** + * Packages slated for download. + * + * This is used to prevent downloading a package more than once should it be a dependency + * for two packages to be installed. + * Format of each entry: + * + *
+     * array('package_name1' => parsed package.xml, 'package_name2' => parsed package.xml,
+     * );
+     * 
+ * @access private + * @var array + */ + var $_toDownload = array(); + + /** + * Array of every package installed, with names lower-cased. + * + * Format: + * + * array('package1' => 0, 'package2' => 1, ); + * + * @var array + */ + var $_installed = array(); + + /** + * @var array + * @access private + */ + var $_errorStack = array(); + + // {{{ PEAR_Downloader() + + function PEAR_Downloader(&$ui, $options, &$config) + { + $this->_options = $options; + $this->_config = &$config; + $this->_preferredState = $this->_config->get('preferred_state'); + if (!$this->_preferredState) { + // don't inadvertantly use a non-set preferred_state + $this->_preferredState = null; + } + + $php_dir = $this->_config->get('php_dir'); + if (isset($this->_options['installroot'])) { + if (substr($this->_options['installroot'], -1) == DIRECTORY_SEPARATOR) { + $this->_options['installroot'] = substr($this->_options['installroot'], 0, -1); + } + $php_dir = $this->_prependPath($php_dir, $this->_options['installroot']); + } + $this->_registry = &new PEAR_Registry($php_dir); + $this->_remote = &new PEAR_Remote($config); + + if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) { + $this->_installed = $this->_registry->listPackages(); + array_walk($this->_installed, create_function('&$v,$k','$v = strtolower($v);')); + $this->_installed = array_flip($this->_installed); + } + parent::PEAR_Common($ui); + } + + // }}} + // {{{ configSet() + function configSet($key, $value, $layer = 'user') + { + $this->_config->set($key, $value, $layer); + $this->_preferredState = $this->_config->get('preferred_state'); + if (!$this->_preferredState) { + // don't inadvertantly use a non-set preferred_state + $this->_preferredState = null; + } + } + + // }}} + // {{{ setOptions() + function setOptions($options) + { + $this->_options = $options; + } + + // }}} + // {{{ _downloadFile() + /** + * @param string filename to download + * @param string version/state + * @param string original value passed to command-line + * @param string|null preferred state (snapshot/devel/alpha/beta/stable) + * Defaults to configuration preferred state + * @return null|PEAR_Error|string + * @access private + */ + function _downloadFile($pkgfile, $version, $origpkgfile, $state = null) + { + if (is_null($state)) { + $state = $this->_preferredState; + } + // {{{ check the package filename, and whether it's already installed + $need_download = false; + if (preg_match('#^(http|ftp)://#', $pkgfile)) { + $need_download = true; + } elseif (!@is_file($pkgfile)) { + if ($this->validPackageName($pkgfile)) { + if ($this->_registry->packageExists($pkgfile)) { + if (empty($this->_options['upgrade']) && empty($this->_options['force'])) { + $errors[] = "$pkgfile already installed"; + return; + } + } + $pkgfile = $this->getPackageDownloadUrl($pkgfile, $version); + $need_download = true; + } else { + if (strlen($pkgfile)) { + $errors[] = "Could not open the package file: $pkgfile"; + } else { + $errors[] = "No package file given"; + } + return; + } + } + // }}} + + // {{{ Download package ----------------------------------------------- + if ($need_download) { + $downloaddir = $this->_config->get('download_dir'); + if (empty($downloaddir)) { + if (PEAR::isError($downloaddir = System::mktemp('-d'))) { + return $downloaddir; + } + $this->log(3, '+ tmp dir created at ' . $downloaddir); + } + $callback = $this->ui ? array(&$this, '_downloadCallback') : null; + $this->pushErrorHandling(PEAR_ERROR_RETURN); + $file = $this->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback); + $this->popErrorHandling(); + if (PEAR::isError($file)) { + if ($this->validPackageName($origpkgfile)) { + if (!PEAR::isError($info = $this->_remote->call('package.info', + $origpkgfile))) { + if (!count($info['releases'])) { + return $this->raiseError('Package ' . $origpkgfile . + ' has no releases'); + } else { + return $this->raiseError('No releases of preferred state "' + . $state . '" exist for package ' . $origpkgfile . + '. Use ' . $origpkgfile . '-state to install another' . + ' state (like ' . $origpkgfile .'-beta)', + PEAR_INSTALLER_ERROR_NO_PREF_STATE); + } + } else { + return $pkgfile; + } + } else { + return $this->raiseError($file); + } + } + $pkgfile = $file; + } + // }}} + return $pkgfile; + } + // }}} + // {{{ getPackageDownloadUrl() + + function getPackageDownloadUrl($package, $version = null) + { + if ($version) { + $package .= "-$version"; + } + if ($this === null || $this->_config === null) { + $package = "http://pear.php.net/get/$package"; + } else { + $package = "http://" . $this->_config->get('master_server') . + "/get/$package"; + } + if (!extension_loaded("zlib")) { + $package .= '?uncompress=yes'; + } + return $package; + } + + // }}} + // {{{ extractDownloadFileName($pkgfile, &$version) + + function extractDownloadFileName($pkgfile, &$version) + { + if (@is_file($pkgfile)) { + return $pkgfile; + } + // regex defined in Common.php + if (preg_match(PEAR_COMMON_PACKAGE_DOWNLOAD_PREG, $pkgfile, $m)) { + $version = (isset($m[3])) ? $m[3] : null; + return $m[1]; + } + $version = null; + return $pkgfile; + } + + // }}} + + // }}} + // {{{ getDownloadedPackages() + + /** + * Retrieve a list of downloaded packages after a call to {@link download()}. + * + * Also resets the list of downloaded packages. + * @return array + */ + function getDownloadedPackages() + { + $ret = $this->_downloadedPackages; + $this->_downloadedPackages = array(); + $this->_toDownload = array(); + return $ret; + } + + // }}} + // {{{ download() + + /** + * Download any files and their dependencies, if necessary + * + * BC-compatible method name + * @param array a mixed list of package names, local files, or package.xml + */ + function download($packages) + { + return $this->doDownload($packages); + } + + // }}} + // {{{ doDownload() + + /** + * Download any files and their dependencies, if necessary + * + * @param array a mixed list of package names, local files, or package.xml + */ + function doDownload($packages) + { + $mywillinstall = array(); + $state = $this->_preferredState; + + // {{{ download files in this list if necessary + foreach($packages as $pkgfile) { + $need_download = false; + if (!is_file($pkgfile)) { + if (preg_match('#^(http|ftp)://#', $pkgfile)) { + $need_download = true; + } + $pkgfile = $this->_downloadNonFile($pkgfile); + if (PEAR::isError($pkgfile)) { + return $pkgfile; + } + if ($pkgfile === false) { + continue; + } + } // end is_file() + + $tempinfo = $this->infoFromAny($pkgfile); + if ($need_download) { + $this->_toDownload[] = $tempinfo['package']; + } + if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) { + // ignore dependencies if there are any errors + if (!PEAR::isError($tempinfo)) { + $mywillinstall[strtolower($tempinfo['package'])] = @$tempinfo['release_deps']; + } + } + $this->_downloadedPackages[] = array('pkg' => $tempinfo['package'], + 'file' => $pkgfile, 'info' => $tempinfo); + } // end foreach($packages) + // }}} + + // {{{ extract dependencies from downloaded files and then download + // them if necessary + if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) { + $deppackages = array(); + foreach ($mywillinstall as $package => $alldeps) { + if (!is_array($alldeps)) { + // there are no dependencies + continue; + } + foreach($alldeps as $info) { + if ($info['type'] != 'pkg') { + continue; + } + $ret = $this->_processDependency($package, $info, $mywillinstall); + if ($ret === false) { + continue; + } + if (PEAR::isError($ret)) { + return $ret; + } + $deppackages[] = $ret; + } // foreach($alldeps + } + + if (count($deppackages)) { + $this->doDownload($deppackages); + } + } // }}} if --alldeps or --onlyreqdeps + } + + // }}} + // {{{ _downloadNonFile($pkgfile) + + /** + * @return false|PEAR_Error|string false if loop should be broken out of, + * string if the file was downloaded, + * PEAR_Error on exception + * @access private + */ + function _downloadNonFile($pkgfile) + { + $origpkgfile = $pkgfile; + $state = null; + $pkgfile = $this->extractDownloadFileName($pkgfile, $version); + if (preg_match('#^(http|ftp)://#', $pkgfile)) { + return $this->_downloadFile($pkgfile, $version, $origpkgfile); + } + if (!$this->validPackageName($pkgfile)) { + return $this->raiseError("Package name '$pkgfile' not valid"); + } + // ignore packages that are installed unless we are upgrading + $curinfo = $this->_registry->packageInfo($pkgfile); + if ($this->_registry->packageExists($pkgfile) + && empty($this->_options['upgrade']) && empty($this->_options['force'])) { + $this->log(0, "Package '{$curinfo['package']}' already installed, skipping"); + return false; + } + if (in_array($pkgfile, $this->_toDownload)) { + return false; + } + $releases = $this->_remote->call('package.info', $pkgfile, 'releases'); + if (!count($releases)) { + return $this->raiseError("No releases found for package '$pkgfile'"); + } + // Want a specific version/state + if ($version !== null) { + // Passed Foo-1.2 + if ($this->validPackageVersion($version)) { + if (!isset($releases[$version])) { + return $this->raiseError("No release with version '$version' found for '$pkgfile'"); + } + // Passed Foo-alpha + } elseif (in_array($version, $this->getReleaseStates())) { + $state = $version; + $version = 0; + foreach ($releases as $ver => $inf) { + if ($inf['state'] == $state && version_compare("$version", "$ver") < 0) { + $version = $ver; + } + } + if ($version == 0) { + return $this->raiseError("No release with state '$state' found for '$pkgfile'"); + } + // invalid postfix passed + } else { + return $this->raiseError("Invalid postfix '-$version', be sure to pass a valid PEAR ". + "version number or release state"); + } + // Guess what to download + } else { + $states = $this->betterStates($this->_preferredState, true); + $possible = false; + $version = 0; + foreach ($releases as $ver => $inf) { + if (in_array($inf['state'], $states) && version_compare("$version", "$ver") < 0) { + $version = $ver; + } + } + if ($version == 0 && !isset($this->_options['force'])) { + return $this->raiseError('No release with state equal to: \'' . implode(', ', $states) . + "' found for '$pkgfile'"); + } elseif ($version == 0) { + $this->log(0, "Warning: $pkgfile is state '$inf[state]' which is less stable " . + "than state '$this->_preferredState'"); + } + } + // Check if we haven't already the version + if (empty($this->_options['force'])) { + if ($curinfo['version'] == $version) { + $this->log(0, "Package '{$curinfo['package']}-{$curinfo['version']}' already installed, skipping"); + return false; + } elseif (version_compare("$version", "{$curinfo['version']}") < 0) { + $this->log(0, "Package '{$curinfo['package']}' version '{$curinfo['version']}' " . + " is installed and {$curinfo['version']} is > requested '$version', skipping"); + return false; + } + } + $this->_toDownload[] = $pkgfile; + return $this->_downloadFile($pkgfile, $version, $origpkgfile, $state); + } + + // }}} + // {{{ _processDependency($package, $info, $mywillinstall) + + /** + * Process a dependency, download if necessary + * @param array dependency information from PEAR_Remote call + * @param array packages that will be installed in this iteration + * @return false|string|PEAR_Error + * @access private + * @todo Add test for relation 'lt'/'le' -> make sure that the dependency requested is + * in fact lower than the required value. This will be very important for BC dependencies + */ + function _processDependency($package, $info, $mywillinstall) + { + $state = $this->_preferredState; + if (!isset($this->_options['alldeps']) && isset($info['optional']) && + $info['optional'] == 'yes') { + // skip optional deps + $this->log(0, "skipping Package $package optional dependency $info[name]"); + return false; + } + // {{{ get releases + $releases = $this->_remote->call('package.info', $info['name'], 'releases'); + if (PEAR::isError($releases)) { + return $releases; + } + if (!count($releases)) { + if (!isset($this->_installed[strtolower($info['name'])])) { + $this->pushError("Package $package dependency $info[name] ". + "has no releases"); + } + return false; + } + $found = false; + $save = $releases; + while(count($releases) && !$found) { + if (!empty($state) && $state != 'any') { + list($release_version, $release) = each($releases); + if ($state != $release['state'] && + !in_array($release['state'], $this->betterStates($state))) + { + // drop this release - it ain't stable enough + array_shift($releases); + } else { + $found = true; + } + } else { + $found = true; + } + } + if (!count($releases) && !$found) { + $get = array(); + foreach($save as $release) { + $get = array_merge($get, + $this->betterStates($release['state'], true)); + } + $savestate = array_shift($get); + $this->pushError( "Release for $package dependency $info[name] " . + "has state '$savestate', requires $state"); + return false; + } + if (in_array(strtolower($info['name']), $this->_toDownload) || + isset($mywillinstall[strtolower($info['name'])])) { + // skip upgrade check for packages we will install + return false; + } + if (!isset($this->_installed[strtolower($info['name'])])) { + // check to see if we can install the specific version required + if ($info['rel'] == 'eq') { + return $info['name'] . '-' . $info['version']; + } + // skip upgrade check for packages we don't have installed + return $info['name']; + } + // }}} + + // {{{ see if a dependency must be upgraded + $inst_version = $this->_registry->packageInfo($info['name'], 'version'); + if (!isset($info['version'])) { + // this is a rel='has' dependency, check against latest + if (version_compare($release_version, $inst_version, 'le')) { + return false; + } else { + return $info['name']; + } + } + if (version_compare($info['version'], $inst_version, 'le')) { + // installed version is up-to-date + return false; + } + return $info['name']; + } + + // }}} + // {{{ pushError($errmsg, $code) + + /** + * @param string + * @param integer + */ + function pushError($errmsg, $code = -1) + { + array_push($this->_errorStack, array($errmsg, $code)); + } + + // }}} + // {{{ getErrorMsgs() + + function getErrorMsgs() + { + $msgs = array(); + $errs = $this->_errorStack; + foreach ($errs as $err) { + $msgs[] = $err[0]; + } + $this->_errorStack = array(); + return $msgs; + } + + // }}} +} +// }}} + +?> diff --git a/pear/tests/common_sortPkgDeps1_package.xml b/pear/tests/common_sortPkgDeps1_package.xml new file mode 100644 index 0000000000..a103b10c66 --- /dev/null +++ b/pear/tests/common_sortPkgDeps1_package.xml @@ -0,0 +1,38 @@ + + + + pkg1 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + pkg2 + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/common_sortPkgDeps2_package.xml b/pear/tests/common_sortPkgDeps2_package.xml new file mode 100644 index 0000000000..3e7c03852d --- /dev/null +++ b/pear/tests/common_sortPkgDeps2_package.xml @@ -0,0 +1,39 @@ + + + + pkg2 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + pkg3 + + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/common_sortPkgDeps3_package.xml b/pear/tests/common_sortPkgDeps3_package.xml new file mode 100644 index 0000000000..830a94c70a --- /dev/null +++ b/pear/tests/common_sortPkgDeps3_package.xml @@ -0,0 +1,39 @@ + + + + pkg3 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + pkg4 + pkg5 + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/common_sortPkgDeps4_package.xml b/pear/tests/common_sortPkgDeps4_package.xml new file mode 100644 index 0000000000..ff3394ee56 --- /dev/null +++ b/pear/tests/common_sortPkgDeps4_package.xml @@ -0,0 +1,38 @@ + + + + pkg4 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + pkg6 + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/common_sortPkgDeps5_package.xml b/pear/tests/common_sortPkgDeps5_package.xml new file mode 100644 index 0000000000..6dea22f403 --- /dev/null +++ b/pear/tests/common_sortPkgDeps5_package.xml @@ -0,0 +1,38 @@ + + + + pkg5 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + pkg6 + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/common_sortPkgDeps6_package.xml b/pear/tests/common_sortPkgDeps6_package.xml new file mode 100644 index 0000000000..a196e7003b --- /dev/null +++ b/pear/tests/common_sortPkgDeps6_package.xml @@ -0,0 +1,35 @@ + + + + pkg6 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/pear2.phpt b/pear/tests/pear2.phpt new file mode 100644 index 0000000000..a0174a1963 --- /dev/null +++ b/pear/tests/pear2.phpt @@ -0,0 +1,852 @@ +--TEST-- +PEAR complete set/push/pop error-handling test (run from pear/tests dir) +--SKIPIF-- + +--FILE-- +_default_error_mode', $this->_default_error_mode, + '$this->_default_error_options', $this->_default_error_options); + } + + function doSetErrorHandlingStatic() + { + print "testing in PEAR setErrorHandling array(obj, method)\n"; + $obj = new testErrorHandlingPEAR; + PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$obj, 'fakeHandleError')); + echoPEARVars('_PEAR_default_error_mode', $GLOBALS['_PEAR_default_error_mode'], + '_PEAR_default_error_options', $GLOBALS['_PEAR_default_error_options']); + echoPEARVars('$this->_default_error_mode', $this->_default_error_mode, + '$this->_default_error_options', $this->_default_error_options); + } + + function doSetErrorHandlingObject() + { + print "testing in PEAR setErrorHandling array(class, method)\n"; + PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('testErrorHandlingStatic', 'fakeHandleError')); + echoPEARVars('_PEAR_default_error_mode', $GLOBALS['_PEAR_default_error_mode'], + '_PEAR_default_error_options', $GLOBALS['_PEAR_default_error_options']); + echoPEARVars('$this->_default_error_mode', $this->_default_error_mode, + '$this->_default_error_options', $this->_default_error_options); + } + + function doPushErrorHandlingFunction() + { + print "testing in PEAR pushErrorHandling\n"; + PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, 'get_error_mode'); + echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); + } + + function doPushErrorHandlingObject() + { + print "testing in PEAR pushErrorHandling array(obj, method)\n"; + $obj = new testErrorHandlingPEAR; + PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array(&$obj, 'fakeHandleError')); + echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); + } + + function doPushErrorHandlingStatic() + { + print "testing in PEAR pushErrorHandling array(class, method)\n"; + PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array('testErrorHandlingStatic', 'fakeHandleError')); + echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); + } + + function doPopErrorHandling() + { + print "testing in PEAR popErrorHandling\n"; + PEAR::popErrorHandling(); + echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); + } +} + +function echoPEARVars($name1, $mode, $name2, $options, $indent = '') +{ + $levelMap = + array( + E_USER_NOTICE => 'E_USER_NOTICE', + E_USER_WARNING => 'E_USER_WARNING', + E_USER_ERROR => 'E_USER_ERROR', + ); + $pearLevelMap = + array( + PEAR_ERROR_RETURN =>'PEAR_ERROR_RETURN', + PEAR_ERROR_PRINT =>'PEAR_ERROR_PRINT', + PEAR_ERROR_TRIGGER =>'PEAR_ERROR_TRIGGER', + PEAR_ERROR_DIE =>'PEAR_ERROR_DIE', + PEAR_ERROR_CALLBACK =>'PEAR_ERROR_CALLBACK', + PEAR_ERROR_EXCEPTION =>'PEAR_ERROR_EXCEPTION', + ); + print $indent . "echoing PEAR error-handling Variables:\n"; + print "$indent--------------------------------------\n"; + print $indent . "$name1:\n"; + $levels = get_error_mode($mode); + print $indent; + foreach($levels as $level) { + print $pearLevelMap[$level] . ','; + } + print "\n"; + print $indent . "$name2:\n"; + if (is_string($options)) { + print $indent . 'Callback: ' . $options. "()\n"; + } elseif (is_array($options)) { + print $indent . 'Callback: '; + if (is_string($options[0])) { + print '(static) ' . $options[0] . '::'; + } else { + print get_class($options[0]) . '->'; + } + print $options[1] . "()\n"; + } else { + print $indent . $levelMap[$options] . "\n"; + } + print "$indent--------------------------------------\n"; +} + +function echoPEARStack($name, $stack) +{ + print "stack $name:\n"; + foreach ($stack as $i => $item) { + print "Index $i:\n"; + echoPEARVars('mode', $item[0], 'options', $item[1], ' '); + } +} + +function get_error_mode($err) +{ + $ret = array(); + $level = 0; + while($level < 7) { + $a = ($err >> $level++) & 1; + if ($a) { + $ret[] = 1 << ($level - 1); + } + } + return $ret; +} +print "testing static error-handling global code\n"; +echoPEARVars('_PEAR_default_error_mode', $GLOBALS['_PEAR_default_error_mode'], + '_PEAR_default_error_options', $GLOBALS['_PEAR_default_error_options']); +print "testing setErrorHandling\n"; +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'get_error_mode'); +echoPEARVars('_PEAR_default_error_mode', $GLOBALS['_PEAR_default_error_mode'], + '_PEAR_default_error_options', $GLOBALS['_PEAR_default_error_options']); +print "testing setErrorHandling array(obj, method)\n"; +$obj = new testErrorHandlingPEAR; +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$obj, 'fakeHandleError')); +echoPEARVars('_PEAR_default_error_mode', $GLOBALS['_PEAR_default_error_mode'], + '_PEAR_default_error_options', $GLOBALS['_PEAR_default_error_options']); +print "testing setErrorHandling array(class, method)\n"; +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('testErrorHandlingStatic', 'fakeHandleError')); +echoPEARVars('_PEAR_default_error_mode', $GLOBALS['_PEAR_default_error_mode'], + '_PEAR_default_error_options', $GLOBALS['_PEAR_default_error_options']); + + +print "testing pushErrorHandling\n"; +PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, 'get_error_mode'); +echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); +print "testing pushErrorHandling array(obj, method)\n"; +$obj = new testErrorHandlingPEAR; +PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array(&$obj, 'fakeHandleError')); +echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); +print "testing pushErrorHandling array(class, method)\n"; +PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array('testErrorHandlingStatic', 'fakeHandleError')); +echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); + + +print "testing popErrorHandling\n"; +PEAR::popErrorHandling(); +echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); +print "testing popErrorHandling\n"; +$obj = new testErrorHandlingPEAR; +PEAR::popErrorHandling(); +echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); +print "testing popErrorHandling\n"; +PEAR::popErrorHandling(); +echoPEARStack('_PEAR_error_handler_stack', $GLOBALS['_PEAR_error_handler_stack']); +print "*******************************************\n"; +print "testing static error-handling in-class code\n"; +print "*******************************************\n"; +PEAR::setErrorHandling(PEAR_ERROR_RETURN, E_USER_NOTICE); +$obj = new testErrorHandlingStatic; +$obj->doSetErrorHandlingFunction(); +$obj->doSetErrorHandlingStatic(); +$obj->doSetErrorHandlingObject(); +$obj->doPushErrorHandlingFunction(); +$obj->doPushErrorHandlingStatic(); +$obj->doPushErrorHandlingObject(); +$obj->doPopErrorHandling(); +$obj->doPopErrorHandling(); +$obj->doPopErrorHandling(); +print "*******************************************\n"; +print "testing non-static error-handling in-class code\n"; +print "*******************************************\n"; +PEAR::setErrorHandling(PEAR_ERROR_RETURN, E_USER_NOTICE); +$obj = new testErrorHandlingPEAR; +$obj->doSetErrorHandlingFunction(); +$obj->doSetErrorHandlingStatic(); +$obj->doSetErrorHandlingObject(); +$obj->doPushErrorHandlingFunction(); +$obj->doPushErrorHandlingStatic(); +$obj->doPushErrorHandlingObject(); +$obj->doPopErrorHandling(); +$obj->doPopErrorHandling(); +$obj->doPopErrorHandling(); + +?> +--GET-- +--POST-- +--EXPECT-- +testing static error-handling global code +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_RETURN, +_PEAR_default_error_options: +E_USER_NOTICE +-------------------------------------- +testing setErrorHandling +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_CALLBACK, +_PEAR_default_error_options: +Callback: get_error_mode() +-------------------------------------- +testing setErrorHandling array(obj, method) +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_CALLBACK, +_PEAR_default_error_options: +Callback: testerrorhandlingpear->fakeHandleError() +-------------------------------------- +testing setErrorHandling array(class, method) +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_CALLBACK, +_PEAR_default_error_options: +Callback: (static) testErrorHandlingStatic::fakeHandleError() +-------------------------------------- +testing pushErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +testing pushErrorHandling array(obj, method) +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: testerrorhandlingpear->fakeHandleError() + -------------------------------------- +testing pushErrorHandling array(class, method) +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: testerrorhandlingpear->fakeHandleError() + -------------------------------------- +Index 4: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: testerrorhandlingpear->fakeHandleError() + -------------------------------------- +Index 5: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +testing popErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: testerrorhandlingpear->fakeHandleError() + -------------------------------------- +testing popErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +testing popErrorHandling +stack _PEAR_error_handler_stack: +******************************************* +testing static error-handling in-class code +******************************************* +testing in class setErrorHandling +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_CALLBACK, +_PEAR_default_error_options: +Callback: get_error_mode() +-------------------------------------- +testing in class setErrorHandling array(obj, method) +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_CALLBACK, +_PEAR_default_error_options: +Callback: testerrorhandlingpear->fakeHandleError() +-------------------------------------- +testing in class setErrorHandling array(class, method) +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_CALLBACK, +_PEAR_default_error_options: +Callback: (static) testErrorHandlingStatic::fakeHandleError() +-------------------------------------- +testing in class pushErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +testing in class pushErrorHandling array(class, method) +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +testing in class pushErrorHandling array(obj, method) +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 4: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 5: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: testerrorhandlingpear->fakeHandleError() + -------------------------------------- +testing in class popErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +testing in class popErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +testing in class popErrorHandling +stack _PEAR_error_handler_stack: +******************************************* +testing non-static error-handling in-class code +******************************************* +testing in PEAR setErrorHandling +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_RETURN, +_PEAR_default_error_options: +E_USER_NOTICE +-------------------------------------- +echoing PEAR error-handling Variables: +-------------------------------------- +$this->_default_error_mode: +PEAR_ERROR_CALLBACK, +$this->_default_error_options: +Callback: get_error_mode() +-------------------------------------- +testing in PEAR setErrorHandling array(obj, method) +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_RETURN, +_PEAR_default_error_options: +E_USER_NOTICE +-------------------------------------- +echoing PEAR error-handling Variables: +-------------------------------------- +$this->_default_error_mode: +PEAR_ERROR_CALLBACK, +$this->_default_error_options: +Callback: testerrorhandlingpear->fakeHandleError() +-------------------------------------- +testing in PEAR setErrorHandling array(class, method) +echoing PEAR error-handling Variables: +-------------------------------------- +_PEAR_default_error_mode: +PEAR_ERROR_RETURN, +_PEAR_default_error_options: +E_USER_NOTICE +-------------------------------------- +echoing PEAR error-handling Variables: +-------------------------------------- +$this->_default_error_mode: +PEAR_ERROR_CALLBACK, +$this->_default_error_options: +Callback: (static) testErrorHandlingStatic::fakeHandleError() +-------------------------------------- +testing in PEAR pushErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +testing in PEAR pushErrorHandling array(class, method) +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +testing in PEAR pushErrorHandling array(obj, method) +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 4: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 5: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: testerrorhandlingpear->fakeHandleError() + -------------------------------------- +testing in PEAR popErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 2: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +Index 3: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +testing in PEAR popErrorHandling +stack _PEAR_error_handler_stack: +Index 0: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: (static) testErrorHandlingStatic::fakeHandleError() + -------------------------------------- +Index 1: + echoing PEAR error-handling Variables: + -------------------------------------- + mode: + PEAR_ERROR_CALLBACK, + options: + Callback: get_error_mode() + -------------------------------------- +testing in PEAR popErrorHandling +stack _PEAR_error_handler_stack: diff --git a/pear/tests/pear_common_analyzeSC.phpt b/pear/tests/pear_common_analyzeSC.phpt new file mode 100644 index 0000000000..720c1a6c1e --- /dev/null +++ b/pear/tests/pear_common_analyzeSC.phpt @@ -0,0 +1,164 @@ +--TEST-- +PEAR_Common::analyzeSourceCode test +--SKIPIF-- + +--FILE-- + +'; +$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test1.php', 'w'); +fwrite($fp, $test1); +fclose($fp); + +$ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test1.php'); +echo "second test: returns false with invalid PHP? "; +echo $ret ? "no\n" : "yes\n"; +unlink($testdir . DIRECTORY_SEPARATOR . 'test1.php'); + +$test3 = ' + +'; +$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test3.php', 'w'); +fwrite($fp, $test3); +fclose($fp); + +$ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test3.php'); +echo "fourth test: returns false with invalid PHP? "; +echo $ret ? "no\n" : "yes\n"; +unlink($testdir . DIRECTORY_SEPARATOR . 'test3.php'); + +$test4 = ' + +'; +$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test4.php', 'w'); +fwrite($fp, $test4); +fclose($fp); + +$ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test4.php'); +echo "fifth test: returns false with invalid PHP? "; +echo $ret ? "no\n" : "yes\n"; +unlink($testdir . DIRECTORY_SEPARATOR . 'test4.php'); + +$test5 = ' + +'; +$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test5.php', 'w'); +fwrite($fp, $test5); +fclose($fp); + +$ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test5.php'); +echo "sixth test: returns false with valid PHP? "; +echo $ret ? "no\n" : "yes\n"; +var_dump($ret); +unlink($testdir . DIRECTORY_SEPARATOR . 'test5.php'); + +rmdir($testdir); +?> +--GET-- +--POST-- +--EXPECT-- +first test: returns false with non-existing filename? yes +second test: returns false with invalid PHP? yes +fourth test: returns false with invalid PHP? yes +fifth test: returns false with invalid PHP? yes +sixth test: returns false with valid PHP? no +array(5) { + ["declared_classes"]=> + array(2) { + [0]=> + string(5) "test2" + [1]=> + string(4) "blah" + } + ["declared_methods"]=> + array(2) { + ["test2"]=> + array(1) { + [0]=> + string(5) "test2" + } + ["blah"]=> + array(1) { + [0]=> + string(4) "blah" + } + } + ["declared_functions"]=> + array(2) { + [0]=> + string(4) "test" + [1]=> + string(4) "fool" + } + ["used_classes"]=> + array(2) { + [0]=> + string(4) "Greg" + [1]=> + string(6) "Pierre" + } + ["inheritance"]=> + array(1) { + ["blah"]=> + string(5) "test2" + } +} \ No newline at end of file diff --git a/pear/tests/pear_common_buildProvidesArray.phpt b/pear/tests/pear_common_buildProvidesArray.phpt new file mode 100644 index 0000000000..d76c3503e1 --- /dev/null +++ b/pear/tests/pear_common_buildProvidesArray.phpt @@ -0,0 +1,143 @@ +--TEST-- +PEAR_Common::buildProvidesArray test +--SKIPIF-- + +--FILE-- + +'; +$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test5.php', 'w'); +fwrite($fp, $test5); +fclose($fp); + +$ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test5.php'); +echo "pre-test: returns false with valid PHP? "; +echo $ret ? "no\n" : "yes\n"; +var_dump($ret); +unlink($testdir . DIRECTORY_SEPARATOR . 'test5.php'); +$common = new PEAR_Common; +$common->buildProvidesArray($ret); +var_dump($common->pkginfo); +rmdir($testdir); +?> +--GET-- +--POST-- +--EXPECT-- +pre-test: returns false with valid PHP? no +array(5) { + ["declared_classes"]=> + array(2) { + [0]=> + string(5) "test2" + [1]=> + string(4) "blah" + } + ["declared_methods"]=> + array(2) { + ["test2"]=> + array(1) { + [0]=> + string(5) "test2" + } + ["blah"]=> + array(1) { + [0]=> + string(4) "blah" + } + } + ["declared_functions"]=> + array(2) { + [0]=> + string(4) "test" + [1]=> + string(4) "fool" + } + ["used_classes"]=> + array(2) { + [0]=> + string(4) "Greg" + [1]=> + string(6) "Pierre" + } + ["inheritance"]=> + array(1) { + ["blah"]=> + string(5) "test2" + } +} +array(1) { + ["provides"]=> + array(4) { + ["class;test2"]=> + array(2) { + ["type"]=> + string(5) "class" + ["name"]=> + string(5) "test2" + } + ["class;blah"]=> + array(3) { + ["type"]=> + string(5) "class" + ["name"]=> + string(4) "blah" + ["extends"]=> + string(5) "test2" + } + ["function;test"]=> + array(2) { + ["type"]=> + string(8) "function" + ["name"]=> + string(4) "test" + } + ["function;fool"]=> + array(2) { + ["type"]=> + string(8) "function" + ["name"]=> + string(4) "fool" + } + } +} \ No newline at end of file diff --git a/pear/tests/pear_common_downloadHttp.phpt b/pear/tests/pear_common_downloadHttp.phpt new file mode 100644 index 0000000000..b11d904191 --- /dev/null +++ b/pear/tests/pear_common_downloadHttp.phpt @@ -0,0 +1,216 @@ +--TEST-- +PEAR_Common::downloadHttp test +--SKIPIF-- + +--FILE-- + '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/Common.php"; + +$common = &new PEAR_Common; + +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchit'); + +function catchit($err) +{ + echo "Caught error: " . $err->getMessage() . "\n"; +} + +echo "Test static:\n"; + +echo "Simple: "; +PEAR_Common::downloadHttp('http://test.pear.php.net/testdownload.tgz', $ui, $temp_path); +$firstone = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testdownload.tgz')); +$secondone = implode('', file($temp_path . DIRECTORY_SEPARATOR . 'testdownload.tgz')); +echo ($firstone == $secondone) ? "passed\n" : "failed\n"; + +echo "Simple fail:\n"; +PEAR_Common::downloadHttp('http://test.poop.php.net/stuff.tgz', $ui, $temp_path); + +echo "Test callback:\n"; + +$ui = 'My UI'; + +PEAR_Common::downloadHttp('http://test.pear.php.net/testdownload.tgz', $ui, $temp_path, 'myCallback'); +$firstone = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testdownload.tgz')); +$secondone = implode('', file($temp_path . DIRECTORY_SEPARATOR . 'testdownload.tgz')); +echo "Working Callback: "; +echo ($firstone == $secondone) ? "passed\n" : "failed\n"; + + +function myCallback($message, $payload) +{ + $stuff = serialize($payload); + echo "Callback Message: $message\n"; + echo "Callback Payload: $stuff\n"; +} + +echo "Callback fail:\n"; +PEAR_Common::downloadHttp('http://test.poop.php.net/stuff.tgz', $ui, $temp_path, 'myCallback'); + +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 static: +Simple: passed +Simple fail: +Caught error: Connection to `test.poop.php.net:80' failed: The operation completed successfully. + +Test callback: +Callback Message: setup +Callback Payload: a:1:{i:0;s:5:"My UI";} +Callback Message: message +Callback Payload: s:35:"Using HTTP proxy test.pear.php.net:"; +Callback Message: saveas +Callback Payload: s:16:"testdownload.tgz"; +Callback Message: start +Callback Payload: a:2:{i:0;s:16:"testdownload.tgz";i:1;s:5:"41655";} +Callback Message: bytesread +Callback Payload: i:1024; +Callback Message: bytesread +Callback Payload: i:2048; +Callback Message: bytesread +Callback Payload: i:3072; +Callback Message: bytesread +Callback Payload: i:4096; +Callback Message: bytesread +Callback Payload: i:5120; +Callback Message: bytesread +Callback Payload: i:6144; +Callback Message: bytesread +Callback Payload: i:7168; +Callback Message: bytesread +Callback Payload: i:8192; +Callback Message: bytesread +Callback Payload: i:9216; +Callback Message: bytesread +Callback Payload: i:10240; +Callback Message: bytesread +Callback Payload: i:11264; +Callback Message: bytesread +Callback Payload: i:12288; +Callback Message: bytesread +Callback Payload: i:13312; +Callback Message: bytesread +Callback Payload: i:14336; +Callback Message: bytesread +Callback Payload: i:15360; +Callback Message: bytesread +Callback Payload: i:16384; +Callback Message: bytesread +Callback Payload: i:17408; +Callback Message: bytesread +Callback Payload: i:18432; +Callback Message: bytesread +Callback Payload: i:19456; +Callback Message: bytesread +Callback Payload: i:20480; +Callback Message: bytesread +Callback Payload: i:21504; +Callback Message: bytesread +Callback Payload: i:22528; +Callback Message: bytesread +Callback Payload: i:23552; +Callback Message: bytesread +Callback Payload: i:24576; +Callback Message: bytesread +Callback Payload: i:25600; +Callback Message: bytesread +Callback Payload: i:26624; +Callback Message: bytesread +Callback Payload: i:27648; +Callback Message: bytesread +Callback Payload: i:28672; +Callback Message: bytesread +Callback Payload: i:29696; +Callback Message: bytesread +Callback Payload: i:30720; +Callback Message: bytesread +Callback Payload: i:31744; +Callback Message: bytesread +Callback Payload: i:32768; +Callback Message: bytesread +Callback Payload: i:33792; +Callback Message: bytesread +Callback Payload: i:34816; +Callback Message: bytesread +Callback Payload: i:35840; +Callback Message: bytesread +Callback Payload: i:36864; +Callback Message: bytesread +Callback Payload: i:37888; +Callback Message: bytesread +Callback Payload: i:38912; +Callback Message: bytesread +Callback Payload: i:39936; +Callback Message: bytesread +Callback Payload: i:40960; +Callback Message: bytesread +Callback Payload: i:41655; +Callback Message: done +Callback Payload: i:41655; +Working Callback: passed +Callback fail: +Callback Message: setup +Callback Payload: a:1:{i:0;s:5:"My UI";} +Callback Message: message +Callback Payload: s:35:"Using HTTP proxy test.poop.php.net:"; +Callback Message: connfailed +Callback Payload: a:4:{i:0;s:17:"test.poop.php.net";i:1;i:80;i:2;i:0;i:3;s:39:"The operation completed successfully. +";} +Caught error: Connection to `test.poop.php.net:80' failed: The operation completed successfully. \ No newline at end of file diff --git a/pear/tests/pear_common_infoFromString.phpt b/pear/tests/pear_common_infoFromString.phpt new file mode 100644 index 0000000000..fa45390afb --- /dev/null +++ b/pear/tests/pear_common_infoFromString.phpt @@ -0,0 +1,1754 @@ +--TEST-- +PEAR_Common::infoFromString test +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} + +echo "Test invalid XML\n"; + +$common->infoFromString('\\goober'); + +echo "Test valid XML, not a package.xml\n"; + +$common->infoFromString('' . + "\n"); + +echo "Test valid package.xml, invalid version number\n"; + +$common->infoFromString('' . + ''); + +echo "Test empty package.xml\n"; + +$ret = $common->infoFromString('' . + ''); + +var_dump($ret); + +echo "Test 1\n"; + +$ret = $common->infoFromString('' . + 'test'); + +var_dump($ret); + +echo "Test 2\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + ''); + +var_dump($ret); + +echo "Test 3\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The test'); + +var_dump($ret); + +echo "Test 4\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License'); + +var_dump($ret); + +echo "Test 5\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + +'); + +var_dump($ret); + +echo "Test 6\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + + 1.3b4 +'); + +var_dump($ret); + +echo "Test 7\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + + 1.3b4 + 2003-11-17 + beta + test +'); + +var_dump($ret); + +echo "Test 8\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + + 1.3b4 + 2003-11-17 + beta + test + +'); + +var_dump($ret); + +echo "Test 9\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + + 1.3b4 + 2003-11-17 + beta + test + + + xmlrpc + + +'); + +var_dump($ret); + +echo "Test 10\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + + 1.3b4 + 2003-11-17 + beta + test + + + xmlrpc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +'); + +var_dump($ret); + +echo "Test 11\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + + 1.3b4 + 2003-11-17 + beta + test + + + xmlrpc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +'); + +var_dump($ret); + +echo "Test 12\n"; + +$ret = $common->infoFromString('' . + 'testPEAR test' . + 'The testPHP License + + test + lead + test tester + test@php.net + + 1.3b4 + 2003-11-17 + beta + test + + + xmlrpc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0.1 + 2003-07-21 + PHP License + alpha + First release of test + + + 0.2 + 2003-07-21 + PHP License + alpha + Generation of package.xml from scratch is now supported. In addition, +generation of <provides> is supported and so is addition of +maintainers and configure options + +- Fixed a bug in <release> generation +- Added _addProvides() to generate a <provides> section + + +'); + +var_dump($ret); + +?> +--GET-- +--POST-- +--EXPECT-- +Test invalid XML +Caught error: XML error: not well-formed (invalid token) at line 1 +Test valid XML, not a package.xml +Caught error: Invalid Package File, no tag +Test valid package.xml, invalid version number +Caught error: No handlers for package.xml version 10000000 +Test empty package.xml +array(2) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } +} +Test 1 +array(3) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" +} +Test 2 +array(4) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" +} +Test 3 +array(5) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" +} +Test 4 +array(6) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" +} +Test 5 +array(7) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } +} +Test 6 +array(8) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } + ["version"]=> + string(5) "1.3b4" +} +Test 7 +array(11) { + ["provides"]=> + array(0) { + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } + ["version"]=> + string(5) "1.3b4" + ["release_date"]=> + string(10) "2003-11-17" + ["release_state"]=> + string(4) "beta" + ["release_notes"]=> + string(4) "test" +} +Test 8 +array(11) { + ["provides"]=> + array(1) { + ["class;furngy"]=> + array(3) { + ["type"]=> + string(5) "class" + ["name"]=> + string(6) "furngy" + ["explicit"]=> + bool(true) + } + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } + ["version"]=> + string(5) "1.3b4" + ["release_date"]=> + string(10) "2003-11-17" + ["release_state"]=> + string(4) "beta" + ["release_notes"]=> + string(4) "test" +} +Test 9 +array(12) { + ["provides"]=> + array(1) { + ["class;furngy"]=> + array(3) { + ["type"]=> + string(5) "class" + ["name"]=> + string(6) "furngy" + ["explicit"]=> + bool(true) + } + } + ["filelist"]=> + &array(0) { + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } + ["version"]=> + string(5) "1.3b4" + ["release_date"]=> + string(10) "2003-11-17" + ["release_state"]=> + string(4) "beta" + ["release_notes"]=> + string(4) "test" + ["release_deps"]=> + array(1) { + [1]=> + array(4) { + ["type"]=> + string(3) "ext" + ["rel"]=> + string(3) "has" + ["optional"]=> + string(3) "yes" + ["name"]=> + string(6) "xmlrpc" + } + } +} +Test 10 +array(12) { + ["provides"]=> + array(1) { + ["class;furngy"]=> + array(3) { + ["type"]=> + string(5) "class" + ["name"]=> + string(6) "furngy" + ["explicit"]=> + bool(true) + } + } + ["filelist"]=> + &array(28) { + ["package.dtd"]=> + array(1) { + ["role"]=> + string(4) "data" + } + ["template.spec"]=> + array(1) { + ["role"]=> + string(4) "data" + } + ["PEAR.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["System.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Autoloader.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Auth.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Build.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Common.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Config.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Install.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Package.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Registry.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Remote.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Mirror.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Common.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Config.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Dependency.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Frontend\CLI.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Builder.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Installer.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Packager.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Registry.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Remote.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["OS\Guess.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["scripts\pear.sh"]=> + array(4) { + ["role"]=> + string(6) "script" + ["install-as"]=> + string(4) "pear" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(4) { + [0]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_dir@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@pear_version@" + ["to"]=> + string(7) "version" + ["type"]=> + string(12) "package-info" + } + [3]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + ["scripts\pear.bat"]=> + array(5) { + ["role"]=> + string(6) "script" + ["platform"]=> + string(7) "windows" + ["install-as"]=> + string(8) "pear.bat" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(3) { + [0]=> + array(3) { + ["from"]=> + string(9) "@bin_dir@" + ["to"]=> + string(7) "bin_dir" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + ["scripts\pearcmd.php"]=> + array(4) { + ["role"]=> + string(3) "php" + ["install-as"]=> + string(11) "pearcmd.php" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(4) { + [0]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_dir@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@pear_version@" + ["to"]=> + string(7) "version" + ["type"]=> + string(12) "package-info" + } + [3]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } + ["version"]=> + string(5) "1.3b4" + ["release_date"]=> + string(10) "2003-11-17" + ["release_state"]=> + string(4) "beta" + ["release_notes"]=> + string(4) "test" + ["release_deps"]=> + array(1) { + [1]=> + array(4) { + ["type"]=> + string(3) "ext" + ["rel"]=> + string(3) "has" + ["optional"]=> + string(3) "yes" + ["name"]=> + string(6) "xmlrpc" + } + } +} +Test 11 +array(13) { + ["provides"]=> + array(1) { + ["class;furngy"]=> + array(3) { + ["type"]=> + string(5) "class" + ["name"]=> + string(6) "furngy" + ["explicit"]=> + bool(true) + } + } + ["filelist"]=> + &array(28) { + ["package.dtd"]=> + array(1) { + ["role"]=> + string(4) "data" + } + ["template.spec"]=> + array(1) { + ["role"]=> + string(4) "data" + } + ["PEAR.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["System.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Autoloader.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Auth.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Build.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Common.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Config.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Install.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Package.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Registry.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Remote.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Mirror.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Common.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Config.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Dependency.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Frontend\CLI.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Builder.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Installer.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Packager.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Registry.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Remote.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["OS\Guess.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["scripts\pear.sh"]=> + array(4) { + ["role"]=> + string(6) "script" + ["install-as"]=> + string(4) "pear" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(4) { + [0]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_dir@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@pear_version@" + ["to"]=> + string(7) "version" + ["type"]=> + string(12) "package-info" + } + [3]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + ["scripts\pear.bat"]=> + array(5) { + ["role"]=> + string(6) "script" + ["platform"]=> + string(7) "windows" + ["install-as"]=> + string(8) "pear.bat" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(3) { + [0]=> + array(3) { + ["from"]=> + string(9) "@bin_dir@" + ["to"]=> + string(7) "bin_dir" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + ["scripts\pearcmd.php"]=> + array(4) { + ["role"]=> + string(3) "php" + ["install-as"]=> + string(11) "pearcmd.php" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(4) { + [0]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_dir@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@pear_version@" + ["to"]=> + string(7) "version" + ["type"]=> + string(12) "package-info" + } + [3]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } + ["version"]=> + string(5) "1.3b4" + ["release_date"]=> + string(10) "2003-11-17" + ["release_state"]=> + string(4) "beta" + ["release_notes"]=> + string(4) "test" + ["release_deps"]=> + array(1) { + [1]=> + array(4) { + ["type"]=> + string(3) "ext" + ["rel"]=> + string(3) "has" + ["optional"]=> + string(3) "yes" + ["name"]=> + string(6) "xmlrpc" + } + } + ["configure_options"]=> + array(1) { + [0]=> + array(3) { + ["name"]=> + string(4) "test" + ["prompt"]=> + string(15) "The prompt test" + ["default"]=> + string(3) "foo" + } + } +} +Test 12 +array(14) { + ["provides"]=> + array(1) { + ["class;furngy"]=> + array(3) { + ["type"]=> + string(5) "class" + ["name"]=> + string(6) "furngy" + ["explicit"]=> + bool(true) + } + } + ["filelist"]=> + &array(28) { + ["package.dtd"]=> + array(1) { + ["role"]=> + string(4) "data" + } + ["template.spec"]=> + array(1) { + ["role"]=> + string(4) "data" + } + ["PEAR.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["System.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Autoloader.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Auth.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Build.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Common.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Config.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Install.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Package.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Registry.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Remote.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Command\Mirror.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Common.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Config.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Dependency.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Frontend\CLI.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Builder.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Installer.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Packager.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Registry.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["PEAR\Remote.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["OS\Guess.php"]=> + array(1) { + ["role"]=> + string(3) "php" + } + ["scripts\pear.sh"]=> + array(4) { + ["role"]=> + string(6) "script" + ["install-as"]=> + string(4) "pear" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(4) { + [0]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_dir@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@pear_version@" + ["to"]=> + string(7) "version" + ["type"]=> + string(12) "package-info" + } + [3]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + ["scripts\pear.bat"]=> + array(5) { + ["role"]=> + string(6) "script" + ["platform"]=> + string(7) "windows" + ["install-as"]=> + string(8) "pear.bat" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(3) { + [0]=> + array(3) { + ["from"]=> + string(9) "@bin_dir@" + ["to"]=> + string(7) "bin_dir" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + ["scripts\pearcmd.php"]=> + array(4) { + ["role"]=> + string(3) "php" + ["install-as"]=> + string(11) "pearcmd.php" + ["baseinstalldir"]=> + string(1) "/" + ["replacements"]=> + array(4) { + [0]=> + array(3) { + ["from"]=> + string(9) "@php_bin@" + ["to"]=> + string(7) "php_bin" + ["type"]=> + string(11) "pear-config" + } + [1]=> + array(3) { + ["from"]=> + string(9) "@php_dir@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + [2]=> + array(3) { + ["from"]=> + string(14) "@pear_version@" + ["to"]=> + string(7) "version" + ["type"]=> + string(12) "package-info" + } + [3]=> + array(3) { + ["from"]=> + string(14) "@include_path@" + ["to"]=> + string(7) "php_dir" + ["type"]=> + string(11) "pear-config" + } + } + } + } + ["package"]=> + string(4) "test" + ["summary"]=> + string(9) "PEAR test" + ["description"]=> + string(8) "The test" + ["release_license"]=> + string(11) "PHP License" + ["maintainers"]=> + array(1) { + [0]=> + &array(4) { + ["handle"]=> + string(4) "test" + ["role"]=> + string(4) "lead" + ["name"]=> + string(11) "test tester" + ["email"]=> + string(12) "test@php.net" + } + } + ["version"]=> + string(5) "1.3b4" + ["release_date"]=> + string(10) "2003-11-17" + ["release_state"]=> + string(4) "beta" + ["release_notes"]=> + string(4) "test" + ["release_deps"]=> + array(1) { + [1]=> + array(4) { + ["type"]=> + string(3) "ext" + ["rel"]=> + string(3) "has" + ["optional"]=> + string(3) "yes" + ["name"]=> + string(6) "xmlrpc" + } + } + ["configure_options"]=> + array(1) { + [0]=> + array(3) { + ["name"]=> + string(4) "test" + ["prompt"]=> + string(15) "The prompt test" + ["default"]=> + string(3) "foo" + } + } + ["changelog"]=> + array(2) { + [0]=> + &array(5) { + ["version"]=> + string(3) "0.1" + ["release_date"]=> + string(10) "2003-07-21" + ["release_license"]=> + string(11) "PHP License" + ["release_state"]=> + string(5) "alpha" + ["release_notes"]=> + string(22) "First release of test +" + } + [1]=> + &array(5) { + ["version"]=> + string(3) "0.2" + ["release_date"]=> + string(10) "2003-07-21" + ["release_license"]=> + string(11) "PHP License" + ["release_state"]=> + string(5) "alpha" + ["release_notes"]=> + string(260) "Generation of package.xml from scratch is now supported. In addition, +generation of is supported and so is addition of +maintainers and configure options + +- Fixed a bug in generation +- Added _addProvides() to generate a section +" + } + } +} \ No newline at end of file diff --git a/pear/tests/pear_common_sortPkgDeps.phpt b/pear/tests/pear_common_sortPkgDeps.phpt new file mode 100644 index 0000000000..e05cbc6a0a --- /dev/null +++ b/pear/tests/pear_common_sortPkgDeps.phpt @@ -0,0 +1,75 @@ +--TEST-- +PEAR_Common::sortPkgDeps test +--SKIPIF-- + +--FILE-- +infoFromAny('common_sortPkgDeps6_package.xml'), +$c->infoFromAny('common_sortPkgDeps2_package.xml'), +$c->infoFromAny('common_sortPkgDeps1_package.xml'), +$c->infoFromAny('common_sortPkgDeps4_package.xml'), +$c->infoFromAny('common_sortPkgDeps5_package.xml'), +$c->infoFromAny('common_sortPkgDeps3_package.xml'), +); + +echo "Test Install Sort:\n"; +$c->sortPkgDeps($packages); +dumpPacks($packages); + +echo "Test Uninstall Sort:\n"; +$c->sortPkgDeps($uninstallpackages, true); +dumpPacks($uninstallpackages); + +chdir($dir); + +function dumpPacks($p) +{ + echo "Packages(\n"; + foreach ($p as $inf) { + echo $inf['info']['package'] . ",\n"; + } + echo ")\n"; +} +?> +--GET-- +--POST-- +--EXPECT-- +Test Install Sort: +Packages( +pkg6, +pkg5, +pkg4, +pkg3, +pkg2, +pkg1, +) +Test Uninstall Sort: +Packages( +pkg1, +pkg2, +pkg3, +pkg5, +pkg4, +pkg6, +) \ No newline at end of file diff --git a/pear/tests/pear_common_validPackageVersion.phpt b/pear/tests/pear_common_validPackageVersion.phpt new file mode 100644 index 0000000000..a23477a2b2 --- /dev/null +++ b/pear/tests/pear_common_validPackageVersion.phpt @@ -0,0 +1,83 @@ +--TEST-- +PEAR_Common::validPackageVersion test +--SKIPIF-- + +--FILE-- + +--GET-- +--POST-- +--EXPECT-- +==Valid Tests== +1 valid +1.1 valid +1.1.1 valid +1.1.1.1 valid +1.1.1abc3 valid +1.234beta4 valid +1alpha3 valid +1alpha valid +1.1a valid +==Invalid Tests== +1.0.0-alpha2 invalid +1alpha.4 invalid +1.1alpha.4 invalid diff --git a/pear/tests/pear_dependency_checkExtension.phpt b/pear/tests/pear_dependency_checkExtension.phpt new file mode 100644 index 0000000000..37d808e9e4 --- /dev/null +++ b/pear/tests/pear_dependency_checkExtension.phpt @@ -0,0 +1,262 @@ +--TEST-- +PEAR_Dependency::checkExtension() test +--SKIPIF-- + +--FILE-- +statedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'; +$dep = new PEAR_Dependency($reg); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, null, 'has'); +echo 'extension 1 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $notloaded, null, 'not'); +echo 'extension 2 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$loadedver = phpversion($loaded); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver + 1, 'ge'); +echo 'extension 3 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version >= " . ($loadedver + 1) . + " is required" ? "match\n" : "$msg\n" ); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver + 1, 'ge', true); +echo 'extension 3 optional ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version >= " . ($loadedver + 1) . + " is recommended to utilize some features" ? "match\n" : "$msg\n" ); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver, 'ne'); +echo 'extension 4 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version != " . $loadedver . + " is required" ? "match\n" : "$msg\n" ); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver, 'gt'); +echo 'extension 5 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version > " . $loadedver . + " is required" ? "match\n" : "$msg\n" ); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver, 'gt', true); +echo 'extension 5 optional ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version > " . $loadedver . + " is recommended to utilize some features" ? "match\n" : "$msg\n" ); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver, 'lt'); +echo 'extension 6 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version < " . $loadedver . + " is required" ? "match\n" : "$msg\n" ); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver, 'lt', true); +echo 'extension 6 optional ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version < " . $loadedver . + " is recommended to utilize some features" ? "match\n" : "$msg\n" ); + +if ($loadedver == 0) { + echo "extension 7 ok? no\nmessage : match\n"; + echo "extension 7 optional ok? no\nmessage : match\n"; +} else { + $msg = 'no error'; + $ret = $dep->checkExtension($msg, $loaded, $loadedver - 1, 'le'); + echo 'extension 7 ok? '; + echo $ret ? "no\n" : "yes\n"; + echo 'message : ' . ($msg == "'$loaded' PHP extension version <= " . ($loadedver - 1). + " is required" ? "match\n" : "$msg\n"); + + $msg = 'no error'; + $ret = $dep->checkExtension($msg, $loaded, $loadedver - 1, 'le', true); + echo 'extension 7 ok? '; + echo $ret ? "no\n" : "yes\n"; + echo 'message : ' . ($msg == "'$loaded' PHP extension version <= " . ($loadedver - 1). + " is recommended to utilize some features" ? "match\n" : "$msg\n"); +} + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver, 'eq'); +echo 'extension 8 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $notloaded, $loadedver, 'ne'); +echo 'extension 9 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver + 1, 'eq'); +echo 'extension 10 ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version == " . ($loadedver + 1). + " is required" ? "match\n" : "$msg\n"); + +$msg = 'no error'; +$ret = $dep->checkExtension($msg, $loaded, $loadedver + 1, 'eq', true); +echo 'extension 10 optional ok? '; +echo $ret ? "no\n" : "yes\n"; +echo 'message : ' . ($msg == "'$loaded' PHP extension version == " . ($loadedver + 1). + " is recommended to utilize some features" ? "match\n" : "$msg\n"); + +cleanall(); +// ------------------------------------------------------------------------- // + +function cleanall() +{ + $dp = opendir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'); + while ($ent = readdir($dp)) { + if (substr($ent, -4) == ".reg") { + unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp' . DIRECTORY_SEPARATOR . $ent); + } + } + closedir($dp); + rmdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'); +} + +?> +--GET-- +--POST-- +--EXPECT-- +extension 1 ok? yes +no error +extension 2 ok? yes +no error +extension 3 ok? no +message : match +extension 3 optional ok? no +message : match +extension 4 ok? no +message : match +extension 5 ok? no +message : match +extension 5 optional ok? no +message : match +extension 6 ok? no +message : match +extension 6 optional ok? no +message : match +extension 7 ok? no +message : match +extension 7 optional ok? no +message : match +extension 8 ok? yes +no error +extension 9 ok? yes +no error +extension 10 ok? no +message : match +extension 10 optional ok? no +message : match diff --git a/pear/tests/pear_dependency_checkPackage.phpt b/pear/tests/pear_dependency_checkPackage.phpt new file mode 100644 index 0000000000..1bb2120455 --- /dev/null +++ b/pear/tests/pear_dependency_checkPackage.phpt @@ -0,0 +1,269 @@ +--TEST-- +PEAR_Dependency::checkPackage() test +--SKIPIF-- + +--FILE-- +statedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'; + +$files1 = array( + "pkg1-1.php" => array( + "role" => "php", + ), + "pkg1-2.php" => array( + "role" => "php", + "baseinstalldir" => "pkg1", + ), + ); +$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0", "filelist" => $files1)); + +$dep = new PEAR_Dependency($reg); +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1'); +echo 'has works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'eq'); +echo 'eq 1.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'le'); +echo 'le 1.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'lt'); +echo 'lt 1.1 works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'ne'); +echo 'ne 1.1 works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'ge'); +echo 'ge 1.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '0.9', 'gt'); +echo 'ge 0.9 works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg2', null, 'not'); +echo 'not pkg2 works? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; + +// error conditions + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg2', null, 'has'); +echo 'has pkg2 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_MISSING? '; +echo ($ret == PEAR_DEPENDENCY_MISSING) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg2', null, 'has', true); +echo 'has optional pkg2 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_MISSING_OPTIONAL? '; +echo ($ret == PEAR_DEPENDENCY_MISSING_OPTIONAL) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '0.9', 'le'); +echo 'le 0.9 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_CONFLICT? '; +echo ($ret == PEAR_DEPENDENCY_CONFLICT) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '0.9', 'le', true); +echo 'optional le 0.9 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? '; +echo ($ret == PEAR_DEPENDENCY_CONFLICT_OPTIONAL) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'ne'); +echo 'ne 1.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_CONFLICT? '; +echo ($ret == PEAR_DEPENDENCY_CONFLICT) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'ne', true); +echo 'optional ne 1.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? '; +echo ($ret == PEAR_DEPENDENCY_CONFLICT_OPTIONAL) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'ge'); +echo 'ge 1.1 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? '; +echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'ge', true); +echo 'optional ge 1.1 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? '; +echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '2.0', 'ge'); +echo 'ge 2.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR? '; +echo ($ret == PEAR_DEPENDENCY_UPGRADE_MAJOR) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '2.0', 'ge', true); +echo 'optional ge 2.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL? '; +echo ($ret == PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'gt'); +echo 'gt 1.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? '; +echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'gt', true); +echo 'optional gt 1.0 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? '; +echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', null, 'not'); +echo 'not pkg1 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_CONFLICT? '; +echo ($ret == PEAR_DEPENDENCY_CONFLICT) ? "yes\n" : "no\n"; +echo $msg . "\n"; + +$msg = 'no error'; +$ret = $dep->checkPackage($msg, 'pkg1', null, 'foobar'); +echo 'foobar pkg1 works? '; +echo $ret ? "no\n" : "yes\n"; +echo '$ret is PEAR_DEPENDENCY_BAD_DEPENDENCY? '; +echo ($ret == PEAR_DEPENDENCY_BAD_DEPENDENCY) ? "yes\n" : "no\n"; +echo $msg . "\n"; +cleanall(); + +// ------------------------------------------------------------------------- // + +function cleanall() +{ + $dp = opendir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'); + while ($ent = readdir($dp)) { + if (substr($ent, -4) == ".reg") { + unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp' . DIRECTORY_SEPARATOR . $ent); + } + } + closedir($dp); + rmdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'); +} + +?> +--GET-- +--POST-- +--EXPECT-- +has works? yes +no error +eq 1.0 works? yes +no error +le 1.0 works? yes +no error +lt 1.1 works? yes +no error +ne 1.1 works? yes +no error +ge 1.0 works? yes +no error +ge 0.9 works? yes +no error +not pkg2 works? yes +no error +has pkg2 works? no +$ret is PEAR_DEPENDENCY_MISSING? yes +requires package `pkg2' +has optional pkg2 works? no +$ret is PEAR_DEPENDENCY_MISSING_OPTIONAL? yes +package `pkg2' is recommended to utilize some features. +le 0.9 works? no +$ret is PEAR_DEPENDENCY_CONFLICT? yes +requires package `pkg1' <= 0.9 +optional le 0.9 works? no +$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? yes +package `pkg1' version <= 0.9 is recommended to utilize some features. Installed version is 1.0 +ne 1.0 works? no +$ret is PEAR_DEPENDENCY_CONFLICT? yes +requires package `pkg1' != 1.0 +optional ne 1.0 works? no +$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? yes +package `pkg1' version != 1.0 is recommended to utilize some features. Installed version is 1.0 +ge 1.1 works? no +$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? yes +requires package `pkg1' >= 1.1 +optional ge 1.1 works? no +$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? yes +package `pkg1' version >= 1.1 is recommended to utilize some features. Installed version is 1.0 +ge 2.0 works? no +$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR? yes +requires package `pkg1' >= 2.0 +optional ge 2.0 works? no +$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL? yes +package `pkg1' version >= 2.0 is recommended to utilize some features. Installed version is 1.0 +gt 1.0 works? no +$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? yes +requires package `pkg1' > 1.0 +optional gt 1.0 works? no +$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? yes +package `pkg1' version > 1.0 is recommended to utilize some features. Installed version is 1.0 +not pkg1 works? no +$ret is PEAR_DEPENDENCY_CONFLICT? yes +conflicts with package `pkg1' +foobar pkg1 works? no +$ret is PEAR_DEPENDENCY_BAD_DEPENDENCY? yes +relation 'foobar' with requirement '' is not supported (name=pkg1) diff --git a/pear/tests/pear_dependency_checkPackageUninstall.phpt b/pear/tests/pear_dependency_checkPackageUninstall.phpt new file mode 100644 index 0000000000..0206733a1f --- /dev/null +++ b/pear/tests/pear_dependency_checkPackageUninstall.phpt @@ -0,0 +1,178 @@ +--TEST-- +PEAR_Dependency::checkPackageUninstall() test +--SKIPIF-- + +--FILE-- +statedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'; + +$files1 = array( + "pkg1-1.php" => array( + "role" => "php", + ), + "pkg1-2.php" => array( + "role" => "php", + "baseinstalldir" => "pkg1", + ), + ); +$files2 = array( + "pkg2-1.php" => array( + "role" => "php", + ), + "pkg2-2.php" => array( + "role" => "php", + "baseinstalldir" => "pkg2", + ), + ); +$files3 = array( + "pkg3-1.php" => array( + "role" => "php", + ), + "pkg3-2.php" => array( + "role" => "php", + "baseinstalldir" => "pkg3", + ), + ); + +$reg->addPackage("pkg2", array("name" => "pkg2", "version" => "2.0", "filelist" => $files2)); +$reg->addPackage("pkg3", array("name" => "pkg3", "version" => "3.0", "filelist" => $files3)); + +$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0", "filelist" => $files1, + 'release_deps' => array( + array('type' => 'pkg', 'name' => 'pkg3', 'rel' => 'not') + ))); + +$dep = new PEAR_Dependency($reg); +$msg = ''; +$warn = ''; +$ret = $dep->checkPackageUninstall($msg, $warn, 'pkg1'); +echo 'uninstall ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; +echo $warn . "\n"; + +cleanall(); + +$reg->addPackage("pkg2", array("name" => "pkg2", "version" => "2.0", "filelist" => $files2)); +$reg->addPackage("pkg3", array("name" => "pkg3", "version" => "3.0", "filelist" => $files3)); + +$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0", "filelist" => $files1, + 'release_deps' => array( + array('type' => 'pkg', 'name' => 'pkg2', 'rel' => 'ne', 'version' => '6.0') + ))); + +$dep = new PEAR_Dependency($reg); +$msg = ''; +$warn = ''; +$ret = $dep->checkPackageUninstall($msg, $warn, 'pkg2'); +echo 'uninstall ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; +echo $warn . "\n"; + +cleanall(); + +$reg->addPackage("pkg2", array("name" => "pkg2", "version" => "2.0", "filelist" => $files2)); +$reg->addPackage("pkg3", array("name" => "pkg3", "version" => "3.0", "filelist" => $files3)); + +$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0", "filelist" => $files1, + 'release_deps' => array( + array('type' => 'pkg', 'name' => 'pkg2', 'rel' => 'has') + ))); + +$dep = new PEAR_Dependency($reg); +$msg = ''; +$warn = ''; +$ret = $dep->checkPackageUninstall($msg, $warn, 'pkg2'); +echo 'uninstall ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; +echo $warn . "\n"; + +cleanall(); + +$reg->addPackage("pkg2", array("name" => "pkg2", "version" => "2.0", "filelist" => $files2)); +$reg->addPackage("pkg3", array("name" => "pkg3", "version" => "3.0", "filelist" => $files3)); + +$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0", "filelist" => $files1, + 'release_deps' => array( + array('type' => 'pkg', 'name' => 'pkg2', 'rel' => 'has', 'optional' => 'no') + ))); + +$dep = new PEAR_Dependency($reg); +$msg = ''; +$warn = ''; +$ret = $dep->checkPackageUninstall($msg, $warn, 'pkg2'); +echo 'uninstall ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; +echo $warn . "\n"; + +cleanall(); + +$reg->addPackage("pkg2", array("name" => "pkg2", "version" => "2.0", "filelist" => $files2)); +$reg->addPackage("pkg3", array("name" => "pkg3", "version" => "3.0", "filelist" => $files3)); + +$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0", "filelist" => $files1, + 'release_deps' => array( + array('type' => 'pkg', 'name' => 'pkg2', 'rel' => 'has', 'optional' => 'yes') + ))); + +$dep = new PEAR_Dependency($reg); +$msg = ''; +$warn = ''; +$ret = $dep->checkPackageUninstall($msg, $warn, 'pkg2'); +echo 'uninstall ok? '; +echo $ret ? "no\n" : "yes\n"; +echo $msg . "\n"; +echo $warn . "\n"; + +cleanall(); + +// ------------------------------------------------------------------------- // + +function cleanall() +{ + $dp = opendir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'); + while ($ent = readdir($dp)) { + if (substr($ent, -4) == ".reg") { + unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp' . DIRECTORY_SEPARATOR . $ent); + } + } + closedir($dp); + rmdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp'); +} + +?> +--GET-- +--POST-- +--EXPECT-- +uninstall ok? yes + + +uninstall ok? yes + + +uninstall ok? no +Package 'pkg1' depends on 'pkg2' + + +uninstall ok? no +Package 'pkg1' depends on 'pkg2' + + +uninstall ok? yes + + +Warning: Package 'pkg1' optionally depends on 'pkg2' \ No newline at end of file diff --git a/pear/tests/pear_installer4.phpt b/pear/tests/pear_installer4.phpt new file mode 100644 index 0000000000..c9af6c43b0 --- /dev/null +++ b/pear/tests/pear_installer4.phpt @@ -0,0 +1,259 @@ +--TEST-- +PEAR_Installer test #4: PEAR_Installer::install() +--SKIPIF-- + +--FILE-- + 'pear.php.net', + 'php_dir' => $temp_path . DIRECTORY_SEPARATOR . 'php', + 'ext_dir' => $temp_path . DIRECTORY_SEPARATOR . 'ext', + 'data_dir' => $temp_path . DIRECTORY_SEPARATOR . 'data', + 'doc_dir' => $temp_path . DIRECTORY_SEPARATOR . 'doc', + 'test_dir' => $temp_path . DIRECTORY_SEPARATOR . 'test', + 'bin_dir' => $temp_path . DIRECTORY_SEPARATOR . 'bin',)); +touch($temp_path . DIRECTORY_SEPARATOR . 'pear.conf'); +$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.conf', 'w'); +fwrite($fp, $config); +fclose($fp); +touch($temp_path . DIRECTORY_SEPARATOR . 'pear.ini'); +$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.ini', 'w'); +fwrite($fp, $config); +fclose($fp); + +putenv('PHP_PEAR_SYSCONF_DIR='.$temp_path); +$home = getenv('HOME'); +if (!empty($home)) { + // for PEAR_Config initialization + putenv('HOME="'.$temp_path); +} +require_once "PEAR/Installer.php"; + +// no UI is needed for these tests +$ui = false; +$installer = new PEAR_Installer($ui); +$curdir = getcwd(); +chdir(dirname(__FILE__)); + +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchit'); + +$error_to_catch = false; +function catchit($err) +{ + global $error_to_catch; + if ($error_to_catch) { + if ($err->getMessage() == $error_to_catch) { + $error_to_catch = false; + echo "Caught expected error\n"; + return; + } + } + echo "Caught error: " . $err->getMessage() . "\n"; +} + +echo "Test package.xml direct install:\n"; +$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'package.xml'); +$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php'); +var_dump($reg->listPackages()); +echo "zoorb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n"; +echo "goompness/Mopreeb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n"; +echo "goompness/oggbrzitzkee.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n"; +echo "After uninstall:\n"; +$installer->uninstall('pkg6'); +var_dump($reg->listPackages()); +echo "zoorb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n"; +echo "goompness/Mopreeb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n"; +echo "goompness/oggbrzitzkee.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n"; +echo "goompness exists? "; +echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness')) + ? "yes\n" : "no\n"; + +echo "Test .tgz install:\n"; +$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'pkg6-1.1.tgz'); +$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php'); +var_dump($reg->listPackages()); +echo "zoorb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n"; +echo "goompness/Mopreeb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n"; +echo "goompness/oggbrzitzkee.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n"; +echo "After uninstall:\n"; +$installer->uninstall('pkg6'); +var_dump($reg->listPackages()); +echo "zoorb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n"; +echo "goompness/Mopreeb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n"; +echo "goompness/oggbrzitzkee.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n"; +echo "goompness exists? "; +echo (is_dir($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness')) + ? "yes\n" : "no\n"; + +echo "Test invalid .tgz install:\n"; +$error_to_catch = 'unable to unpack ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . + 'test-pkg6' . DIRECTORY_SEPARATOR . 'invalidtgz.tgz'; +$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'invalidtgz.tgz'); +$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php'); +var_dump($reg->listPackages()); +echo "zoorb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n"; +echo "goompness/Mopreeb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n"; +echo "goompness/oggbrzitzkee.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n"; + +echo "Test missing package.xml in .tgz install:\n"; +$installer->install(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test-pkg6' . DIRECTORY_SEPARATOR . 'nopackagexml.tgz'); +$reg = &new PEAR_Registry($temp_path . DIRECTORY_SEPARATOR . 'php'); +var_dump($reg->listPackages()); +echo "zoorb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'zoorb.php')) ? "yes\n" : "no\n"; +echo "goompness/Mopreeb.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'Mopreeb.php')) ? "yes\n" : "no\n"; +echo "goompness/oggbrzitzkee.php exists? "; +echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' + . DIRECTORY_SEPARATOR . 'groob' . DIRECTORY_SEPARATOR . 'goompness' + . DIRECTORY_SEPARATOR . 'oggbrzitzkee.php')) ? "yes\n" : "no\n"; + +chdir($curdir); +cleanall($temp_path); + +// ------------------------------------------------------------------------- // + +function cleanall($dir) +{ + $dp = opendir($dir); + while ($ent = readdir($dp)) { + if ($ent == '.' || $ent == '..') { + continue; + } + if (is_dir($dir . DIRECTORY_SEPARATOR . $ent)) { + cleanall($dir . DIRECTORY_SEPARATOR . $ent); + } else { + unlink($dir . DIRECTORY_SEPARATOR . $ent); + } + } + closedir($dp); + rmdir($dir); +} +?> +--GET-- +--POST-- +--EXPECT-- +Test package.xml direct install: +array(1) { + [0]=> + string(4) "pkg6" +} +zoorb.php exists? yes +goompness/Mopreeb.php exists? yes +goompness/oggbrzitzkee.php exists? yes +After uninstall: +array(0) { +} +zoorb.php exists? no +goompness/Mopreeb.php exists? no +goompness/oggbrzitzkee.php exists? no +goompness exists? no +Test .tgz install: +array(1) { + [0]=> + string(4) "pkg6" +} +zoorb.php exists? yes +goompness/Mopreeb.php exists? yes +goompness/oggbrzitzkee.php exists? yes +After uninstall: +array(0) { +} +zoorb.php exists? no +goompness/Mopreeb.php exists? no +goompness/oggbrzitzkee.php exists? no +goompness exists? no +Test invalid .tgz install: +Caught error: Invalid checksum for file " + \ No newline at end of file diff --git a/pear/tests/test-pkg6/goompness/oggbrzitzkee.php b/pear/tests/test-pkg6/goompness/oggbrzitzkee.php new file mode 100644 index 0000000000..5422435ff8 --- /dev/null +++ b/pear/tests/test-pkg6/goompness/oggbrzitzkee.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/pear/tests/test-pkg6/invalidtgz.tgz b/pear/tests/test-pkg6/invalidtgz.tgz new file mode 100644 index 0000000000..909d507ca6 --- /dev/null +++ b/pear/tests/test-pkg6/invalidtgz.tgz @@ -0,0 +1,35 @@ + + + + pkg6 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/test-pkg6/nopackagexml.tgz b/pear/tests/test-pkg6/nopackagexml.tgz new file mode 100644 index 0000000000..8b9d9aad02 Binary files /dev/null and b/pear/tests/test-pkg6/nopackagexml.tgz differ diff --git a/pear/tests/test-pkg6/package.xml b/pear/tests/test-pkg6/package.xml new file mode 100644 index 0000000000..102f972766 --- /dev/null +++ b/pear/tests/test-pkg6/package.xml @@ -0,0 +1,35 @@ + + + + pkg6 + required test for PEAR_Installer + + fake package + + PHP License + + + fakeuser + Joe Shmoe + nobody@example.com + lead + + + + 1.1 + 2003-09-09 + stable + + required dependency test + + + + zoorb.php + + oggbrzitzkee.php + Mopreeb.php + + + + + diff --git a/pear/tests/test-pkg6/pkg6-1.1.tgz b/pear/tests/test-pkg6/pkg6-1.1.tgz new file mode 100644 index 0000000000..09868cab44 Binary files /dev/null and b/pear/tests/test-pkg6/pkg6-1.1.tgz differ diff --git a/pear/tests/test-pkg6/pkg6-2.0b1.tgz b/pear/tests/test-pkg6/pkg6-2.0b1.tgz new file mode 100644 index 0000000000..45e8877d61 Binary files /dev/null and b/pear/tests/test-pkg6/pkg6-2.0b1.tgz differ diff --git a/pear/tests/test-pkg6/zoorb.php b/pear/tests/test-pkg6/zoorb.php new file mode 100644 index 0000000000..5422435ff8 --- /dev/null +++ b/pear/tests/test-pkg6/zoorb.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/pear/tests/testdownload.tgz b/pear/tests/testdownload.tgz new file mode 100644 index 0000000000..0ddc3df361 Binary files /dev/null and b/pear/tests/testdownload.tgz differ