phpUserTrack
[ class tree: phpUserTrack ] [ index: phpUserTrack ] [ all elements ]

Source for file libTest.php

Documentation is available at libTest.php

  1. <?php
  2. if (!function_exists('_')) {
  3.     function _($s{
  4.         return $s;
  5.     }
  6. }
  7.  
  8.  
  9.     var $_phpver;
  10.  
  11.     function phpUserTrack_Test({
  12.  
  13.         /* Store the PHP version information. */
  14.         $this->_phpver = $this->splitPHPVersion(phpversion());
  15.  
  16.         /* We want to be as verbose as possible here. */
  17.         error_reporting(E_ALL);
  18.  
  19.         /* Set character encoding. */
  20.         header('Content-type: text/html; charset=utf-8');
  21.         header('Vary: Accept-Language');
  22.     }
  23.  
  24.     function splitPHPVersion($version{
  25.         /* First pick off major version, and lower-case the rest. */
  26.         if ((strlen($version>= 3&& ($version[1== '.')) {
  27.             $phpver['major'substr($version03);
  28.             $version substr(strtolower($version)3);
  29.         else {
  30.             $phpver['major'$version;
  31.             $phpver['class''unknown';
  32.             return $phpver;
  33.         }
  34.  
  35.         if ($version[0== '.'{
  36.             $version substr($version1);
  37.         }
  38.  
  39.         /* Next, determine if this is 4.0b or 4.0rc; if so, there is no
  40.            minor, the rest is the subminor, and class is set to beta. */
  41.         $s strspn($version'0123456789');
  42.         if ($s == 0{
  43.             $phpver['subminor'$version;
  44.             $phpver['class''beta';
  45.             return $phpver;
  46.         }
  47.  
  48.         /* Otherwise, this is non-beta;  the numeric part is the minor,
  49.            the rest is either a classification (dev, cvs) or a subminor
  50.            version (rc<x>, pl<x>). */
  51.         $phpver['minor'substr($version0$s);
  52.         if ((strlen($version$s&& (($version[$s== '.'|| ($version[$s== '-'))) {
  53.             $s++;
  54.         }
  55.         $phpver['subminor'substr($version$s);
  56.         if (($phpver['subminor'== 'cvs'|| ($phpver['subminor'== 'dev'|| (substr($phpver['subminor']02== 'rc')) {
  57.             unset ($phpver['subminor']);
  58.             $phpver['class''dev';
  59.         else {
  60.             if (!$phpver['subminor']{
  61.                 unset ($phpver['subminor']);
  62.             }
  63.             $phpver['class''release';
  64.         }
  65.  
  66.         return $phpver;
  67.     }
  68.  
  69.     function phpModuleCheck($modlist{
  70.         $output '';
  71.         $output_array array ();
  72.         global $passTests;
  73.  
  74.         foreach ($modlist as $key => $val{
  75.             $error_msg $mod_test $status_out $fatal null;
  76.             $entry array ();
  77.  
  78.             if (is_array($val)) {
  79.                 $descrip $val['descrip'];
  80.                 $fatal !empty ($val['fatal']);
  81.                 if (isset ($val['phpver']&& (version_compare(phpversion()$val['phpver']== -1)) {
  82.                     $mod_test true;
  83.                     $status_out 'N/A';
  84.                 }
  85.                 if (isset ($val['error'])) {
  86.                     $error_msg $val['error'];
  87.                 }
  88.             else {
  89.                 $descrip $val;
  90.             }
  91.  
  92.             if (is_null($status_out)) {
  93.                 $mod_test extension_loaded($key);
  94.                 $status_out $this->_status($mod_test$fatal);
  95.             }
  96.  
  97.             $entry[$descrip;
  98.             $entry[$status_out;
  99.  
  100.             if (!is_null($error_msg&& !$mod_test{
  101.                 $entry[$error_msg;
  102.                 if (!$fatal{
  103.                     $entry[1;
  104.                 }
  105.             }
  106.  
  107.             $output .= $this->_outputLine($entry);
  108.  
  109.             if ($fatal && !$mod_test{
  110.                 $passTests false;
  111.             }
  112.         }
  113.  
  114.         return $output;
  115.     }
  116.     
  117.     function PEARModuleCheck($pear_list)
  118.     {
  119.         $output '';
  120.  
  121.         /* Turn tracking of errors on. */
  122.         ini_set('track_errors'1);
  123.  
  124.         /* Print the include_path. */
  125.         $output .= $this->_outputLine(array("<strong>PEAR Search Path (PHP's include_path)</strong>"'&nbsp;<tt>' ini_get('include_path''</tt>'));
  126.  
  127.         /* Go through module list. */
  128.         $succeeded array();
  129.         foreach ($pear_list as $key => $val{
  130.             $entry array();
  131.  
  132.             /* If this module depends on another module that we
  133.              * haven't succesfully found, fail the test. */
  134.             if (!empty($val['depends']&& empty($succeeded[$val['depends']])) {
  135.                 $result false;
  136.             else {
  137.                 $result @include_once $val['path'];
  138.             }
  139.             $error_msg $val['error'];
  140.             if ($result && isset($val['function'])) {
  141.                 $func_output call_user_func($val['function']);
  142.                 if ($func_output{
  143.                     $result false;
  144.                     $error_msg $func_output;
  145.                 }
  146.             }
  147.             $entry[$key;
  148.             $entry[$this->_status($result!empty($val['required']));
  149.  
  150.             if ($result{
  151.                 $succeeded[$keytrue;
  152.             else {
  153.                 if (!empty($val['required'])) {
  154.                     $error_msg .= ' THIS IS A REQUIRED MODULE!';
  155.                 }
  156.                 $entry[$error_msg;
  157.                 if (empty($val['required'])) {
  158.                     $entry[1;
  159.                 }
  160.             }
  161.  
  162.             $output .= $this->_outputLine($entry);
  163.         }
  164.  
  165.         /* Restore previous value of 'track_errors'. */
  166.         ini_restore('track_errors');
  167.  
  168.         return $output;
  169.     }
  170.  
  171.     function requiredFileCheck($file_list{
  172.         $output '';
  173.         global $passTests;
  174.  
  175.         foreach ($file_list as $key => $val{
  176.             $entry array ();
  177.             $result file_exists('./' $key);
  178.  
  179.             $entry[$key;
  180.             $entry[$this->_status($result);
  181.  
  182.             if (!$result{
  183.                 if (empty ($val)) {
  184.                     $entry['The file <code>' $key '</code> appears to be missing. You probably just forgot to copy <code>' $key '.dist</code> over. While you do that, take a look at the settings and make sure they are appropriate for your site.';
  185.                 else {
  186.                     $entry[$val;
  187.                 }
  188.                 $passTests false;
  189.             }
  190.  
  191.             $output .= $this->_outputLine($entry);
  192.         }
  193.  
  194.         return $output;
  195.     }
  196.  
  197.     function configFilesMissing($app$appBase$files$additional array ()) {
  198.         /* Try to load a basic framework if we're testing an app other than
  199.          * the Horde base files. */
  200.         if ($app != 'Horde'{
  201.             $GLOBALS['registry'Registry :: singleton();
  202.             $GLOBALS['registry']->pushApp('phpUserTrack'false);
  203.         }
  204.  
  205.         if (!is_array($files)) {
  206.             $files array (
  207.                 $files
  208.             );
  209.         }
  210.         $files array_merge($filesarray_keys($additional));
  211.  
  212.         /* Try to auto-create missing .dist files. */
  213.         $indices array_keys($files);
  214.         foreach ($indices as $index{
  215.             if (is_readable($appBase '/config/' $files[$index])) {
  216.                 unset ($files[$index]);
  217.             else {
  218.                 if (file_exists($appBase '/config/' $files[$index'.dist'&& copy($appBase '/config/' $files[$index'.dist'$appBase '/config/' $files[$index])) {
  219.                     unset ($files[$index]);
  220.                 }
  221.             }
  222.         }
  223.  
  224.         /* Return if we have no missing files left. */
  225.         if (!count($files)) {
  226.             return;
  227.         }
  228.  
  229.     }
  230.  
  231.     function getPhpVersionInformation({
  232.         $output new stdClass;
  233.         $url urlencode($_SERVER['PHP_SELF']);
  234.         $vers_check true;
  235.  
  236.         $testscript '.' '/test.php';
  237.         $output->phpinfo $testscript '?mode=phpinfo&url=' $url;
  238.         $output->extensions $testscript '?mode=extensions&url=' $url;
  239.         $output->version phpversion();
  240.         $output->major $this->_phpver['major'];
  241.         if (isset ($this->_phpver['minor'])) {
  242.             $output->minor $this->_phpver['minor'];
  243.         }
  244.         if (isset ($this->_phpver['subminor'])) {
  245.             $output->subminor $this->_phpver['subminor'];
  246.         }
  247.         $output->class $this->_phpver['class'];
  248.  
  249.         $output->status_color 'red';
  250.         if ($output->major '5.0'{
  251.             $output->status 'This version of PHP is not supported. You need to upgrade to at least PHP 5.0';
  252.             $vers_check false;
  253.         }
  254.         elseif (($output->major == '5.0'|| ($output->major == '5.1')) {
  255.             $output->status 'You are running a supported version of PHP.';
  256.             $output->status_color 'green';
  257.         else {
  258.             $output->status 'Wow, a mystical version of PHP from the future. Let <a href="mailto:mini@chatetheory.com">mini@chatetheory.com</a> know what version you have so we can fix this script.';
  259.             $output->status_color 'orange';
  260.         }
  261.  
  262.         if (!$vers_check{
  263.             $output->version_check 'Horde requires PHP 4.3.0 or greater.';
  264.         }
  265.  
  266.         return $output;
  267.     }
  268.  
  269.     function _status($bool$required true{
  270.         if ($bool{
  271.             return '<span class="supported">Yes</span>';
  272.         }
  273.         elseif ($required{
  274.             global $passTests;
  275.             $passTests false;
  276.             return '<span class="notsupported">No</span>';
  277.         else {
  278.             return '<span class="notrequired">No</span>';
  279.         }
  280.     }
  281.  
  282.     function _outputLine($entry{
  283.         $output '<li>' array_shift($entry': ' array_shift($entry);
  284.         if (!empty ($entry)) {
  285.             $msg array_shift($entry);
  286.             $output .= '<br /><span class="' (empty ($entry|| !array_shift($entry'notsupported' 'notrequired''">' $msg '</span>' "\n";
  287.         }
  288.         $output .= '</li>' "\n";
  289.  
  290.         return $output;
  291.     }
  292.  
  293. }

Documentation generated on Tue, 06 Nov 2007 09:22:08 -0800 by phpDocumentor 1.4.0a2