cvs: pear /PEAR_PackageUpdate/tests defaultConfig.phpt

[email protected] ("Laurent Laville")
Newsgroups php.pear.cvs
Message-ID <cvsfarell1209319113@cvsserver>
farell		Sun Apr 27 17:58:33 2008 UTC

  Added files:                 
    /pear/PEAR_PackageUpdate/tests	defaultConfig.phpt 
  Log:
  initial commit of PEAR_PackageUpdate using default configuration test case (with .phpt)
  

http://cvs.php.net/viewvc.cgi/pear/PEAR_PackageUpdate/tests/defaultConfig.phpt?view=markup&rev=1.1
Index: pear/PEAR_PackageUpdate/tests/defaultConfig.phpt
+++ pear/PEAR_PackageUpdate/tests/defaultConfig.phpt
--TEST--
PEAR_PackageUpdate using default configuration
--FILE--
<?php
require_once 'PEAR/Config.php';

$config =& PEAR_Config::singleton();
$cfgDir = $config->get('cfg_dir');  // available only since PEAR 1.7.0

$ds         = DIRECTORY_SEPARATOR;
$dir        = dirname(__FILE__);
$sysconfdir = $dir . $ds . 'sysconf_dir';
$peardir    = $dir . $ds . 'pear_dir';

if (!is_null($cfgDir) && is_dir($cfgDir)) {
    $pearcfgdir = $peardir . $ds . 'cfg';
} else {
    $pearcfgdir = $sysconfdir;
}

putenv("PHP_PEAR_SYSCONF_DIR=" . $sysconfdir);
chdir($dir);

// we get PEAR_PackageUpdate class only here due to setting of PEAR_CONFIG_SYSCONFDIR
require_once 'PEAR/PackageUpdate.php';

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    $system_file = $sysconfdir . $ds . 'pearsys.ini';
    $pref_file   = $pearcfgdir . $ds . 'ppurc.ini';
} else {
    $system_file = $sysconfdir . $ds . 'pear.conf';
    $pref_file   = $pearcfgdir . $ds . '.ppurc';
}
$user_file = '';

if (!file_exists($system_file)) {
    // write once PEAR system-wide config file for simulation
    $config->set('php_dir', $peardir);
    if (!is_null($cfgDir)) {
        // only for PEAR 1.7.0 or greater
        $config->set('cfg_dir', $pearcfgdir);
    }
    $config->writeConfigFile($system_file);
}

/**
 * TestCase 1:
 * default class constructor without parameter
 *
 * Must use the pear config files into the default system directory
 * (PEAR_CONFIG_SYSCONFDIR).
 */
$testCase = 'testConfigFilesExistInSysConfDir';

$ppu =& PEAR_PackageUpdate::factory('Cli', 'text_diff', 'pear');

$result = ($ppu !== false)
    ? 'OK' : 'System or Preference configuration file does not exist';

echo $testCase . ' initClass : ' . $result;
echo "\n";

$result = ($ppu->checkUpdate() === true)
    ? 'OK' : 'No update available for PEAR/Text_Diff';
echo $testCase . ' checkUpdate : ' . $result;
?>
--CLEAN--
<?php
require_once 'PEAR/Config.php';

$config =& PEAR_Config::singleton();
$cfgDir = $config->get('cfg_dir');  // available only since PEAR 1.7.0

$ds         = DIRECTORY_SEPARATOR;
$dir        = dirname(__FILE__);
$sysconfdir = $dir . $ds . 'sysconf_dir';
$peardir    = $dir . $ds . 'pear_dir';

if (!is_null($cfgDir) && is_dir($cfgDir)) {
    $pearcfgdir = $peardir . $ds . 'cfg';
} else {
    $pearcfgdir = $sysconfdir;
}

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    $system_file = $sysconfdir . $ds . 'pearsys.ini';
    $pref_file   = $pearcfgdir . $ds . 'ppurc.ini';
} else {
    $system_file = $sysconfdir . $ds . 'pear.conf';
    $pref_file   = $pearcfgdir . $ds . '.ppurc';
}

unlink ($system_file);
unlink ($pref_file);
?>
--EXPECT--
testConfigFilesExistInSysConfDir initClass : OK
testConfigFilesExistInSysConfDir checkUpdate : OK
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.