1. <?php
  2. /**
  3. * PEAR_Info unit test case to output results.
  4. *
  5. * PHP version 5
  6. *
  7. * LICENSE: This source file is subject to version 3.0 of the PHP license
  8. * that is available through the world-wide-web at the following URI:
  9. * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10. * the PHP License and are unable to obtain it through the web, please
  11. * send a note to license@php.net so we can mail you a copy immediately.
  12. *
  13. * @category   PEAR
  14. * @package    PEAR_Info
  15. * @author     Laurent Laville <pear@laurent-laville.org>
  16. * @copyright  2007 Laurent Laville
  17. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18. * @version    CVS: $Id: PEAR_Info_TestCase_Output.php,v 1.1 2007/07/08 14:22:35 farell Exp $
  19. * @link       http://pear.php.net/package/PEAR_Info
  20. * @since      File available since Release 1.7.0
  21. */
  22.  
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24.     define("PHPUnit_MAIN_METHOD", "PEAR_Info_TestCase_Output::main");
  25. }
  26.  
  27. require_once 'PHPUnit/Framework.php';
  28. #require_once 'PHPUnit/Extensions/OutputTestCase.php';
  29. require_once 'OutputTestCase.php';
  30.  
  31. /**
  32. * Unit test case to get html code results
  33. *
  34. * @category   PEAR
  35. * @package    PEAR_Info
  36. * @author     Laurent Laville <pear@laurent-laville.org>
  37. * @copyright  2007 Laurent Laville
  38. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  39. * @version    CVS: $Id: PEAR_Info_TestCase_Output.php,v 1.1 2007/07/08 14:22:35 farell Exp $
  40. * @link       http://pear.php.net/package/PEAR_Info
  41. * @since      Class available since Release 1.7.0
  42. */
  43.  
  44. class PEAR_Info_TestCase_Output extends PHPUnit_Extensions_OutputTestCase
  45. {
  46.     /**
  47.      * Saves content of PHP_PEAR_SYSCONF_DIR environment variable
  48.      *
  49.      * @var    string
  50.      * @access private
  51.      * @since  1.7.0
  52.      */
  53.     private $sysconfdir;
  54.  
  55.     /**
  56.      * Templates directory. Where to find expected output.
  57.      *
  58.      * @var    string
  59.      * @access private
  60.      * @since  1.7.0
  61.      */
  62.     private $tpldir;
  63.  
  64.     /**
  65.      * Runs the test methods of this class.
  66.      *
  67.      * @access public
  68.      * @static
  69.      * @since  1.7.0
  70.      */
  71.     public static function main()
  72.     {
  73.         require_once "PHPUnit/TextUI/TestRunner.php";
  74.  
  75.         $suite = new PHPUnit_Framework_TestSuite("PEAR_Info test html output");
  76.         $result = PHPUnit_TextUI_TestRunner::run($suite);
  77.     }
  78.  
  79.     /**
  80.      * Sets up the fixture, for example, open a network connection.
  81.      * This method is called before a test is executed.
  82.      *
  83.      * @access protected
  84.      * @since  1.7.0
  85.      */
  86.     protected function setUp()
  87.     {
  88.         chdir(dirname(__FILE__));
  89.  
  90.         $this->tpldir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates';
  91.  
  92.         $this->sysconfdir = getenv('PHP_PEAR_SYSCONF_DIR');
  93.         putenv("PHP_PEAR_SYSCONF_DIR=" . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysconf_dir');
  94.  
  95.         // we get PEAR_Info class only here due to setting of PEAR_CONFIG_SYSCONFDIR
  96.         require_once '..' . DIRECTORY_SEPARATOR . 'Info.php';
  97.  
  98.         $this->setOutputCallback(array(&$this, 'normalizeOutput'));
  99.     }
  100.  
  101.     /**
  102.      * Tears down the fixture, for example, close a network connection.
  103.      * This method is called after a test is executed.
  104.      *
  105.      * @access protected
  106.      * @since  1.7.0
  107.      */
  108.     protected function tearDown()
  109.     {
  110.         putenv("PHP_PEAR_SYSCONF_DIR=" . $this->sysconfdir);
  111.     }
  112.  
  113.     /**
  114.      * Test the html output render.
  115.      *
  116.      * @access public
  117.      * @since  1.7.0
  118.      */
  119.     public function testHtmlOutputGeneral()
  120.     {
  121.         $sysconfdir = getenv('PHP_PEAR_SYSCONF_DIR');
  122.         if (OS_WINDOWS) {
  123.             $conf_file = $sysconfdir . DIRECTORY_SEPARATOR . 'pearsys.ini';
  124.         } else {
  125.             $conf_file = $sysconfdir . DIRECTORY_SEPARATOR . 'pear.conf';
  126.         }
  127.  
  128.         $options = array('resume' =>  PEAR_INFO_GENERAL);
  129.         $pearInfo = new PEAR_Info('', '', '', $options);
  130.         // We must specify here the default stylesheet used, because package source
  131.         // did not include the task replacement values
  132.         $css = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'
  133.             . DIRECTORY_SEPARATOR . 'pearinfo.css';
  134.         $pearInfo->setStyleSheet($css);
  135.  
  136.         $html = file_get_contents($this->tpldir . DIRECTORY_SEPARATOR . 'general.tpl');
  137.         $html = str_replace(array('{config_file}', '{script_filename}'),
  138.             array($conf_file, $_SERVER['SCRIPT_FILENAME']), $html);
  139.         $html = $this->normalizeOutput($html);
  140.  
  141.         $this->expectOutputString($html);
  142.         $pearInfo->show();
  143.     }
  144. }
  145.  
  146. // Call PEAR_Info_TestCase_Output::main() if this source file is executed directly.
  147. if (PHPUnit_MAIN_METHOD == "PEAR_Info_TestCase_Output::main") {
  148.     PEAR_Info_TestCase_Output::main();
  149. }
  150. ?>