home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / HTML_Progress_TestCase_getString.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.2 KB  |  88 lines

  1. <?php
  2.  
  3. /**
  4.  * API getString Unit tests for HTML_Progress class.
  5.  * 
  6.  * @version    $Id: HTML_Progress_TestCase_getString.php,v 1.1 2003/11/15 18:27:11 thesaur Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_Progress
  9.  */
  10.  
  11. class HTML_Progress_TestCase_getString extends PHPUnit_TestCase
  12. {
  13.     /**
  14.      * HTML_Progress instance
  15.      *
  16.      * @var        object
  17.      */
  18.     var $progress;
  19.  
  20.     function HTML_Progress_TestCase_getString($name)
  21.     {
  22.         $this->PHPUnit_TestCase($name);
  23.     }
  24.  
  25.     function setUp()
  26.     {
  27.         error_reporting(E_ALL);
  28.         $this->errorThrown = false;
  29.         set_error_handler(array(&$this, 'errorHandler'));
  30.  
  31.         $this->progress = new HTML_Progress();
  32.         Error_Raise::setContextGrabber($this->progress->_package, array('Error_Util', '_getFileLine'));
  33.     }
  34.  
  35.     function tearDown()
  36.     {
  37.         unset($this->progress);
  38.     }
  39.  
  40.     function _stripWhitespace($str)
  41.     {
  42.         return preg_replace('/\\s+/', '', $str);
  43.     }
  44.  
  45.     function _methodExists($name) 
  46.     {
  47.         if (in_array(strtolower($name), get_class_methods($this->progress))) {
  48.             return true;
  49.         }
  50.         $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->progress));
  51.         return false;
  52.     }
  53.  
  54.     function errorHandler($errno, $errstr, $errfile, $errline) {
  55.         //die("$errstr in $errfile at line $errline");
  56.         $this->errorThrown = true;
  57.         $this->assertTrue(false, $errstr);
  58.     }
  59.    
  60.     /**
  61.      * TestCases for method getString.
  62.      *
  63.      */
  64.     function test_getString_fail()
  65.     {
  66.         if (!$this->_methodExists('getString')) {
  67.             return;
  68.         }
  69.         $this->progress->setStringPainted(true);
  70.         $this->progress->setString('"Receiving 1 out of 5"');
  71.         $percent = $this->progress->getString();
  72.  
  73.         $this->assertEquals('"0 %"', $percent);
  74.     }
  75.  
  76.     function test_getString()
  77.     {
  78.         if (!$this->_methodExists('getString')) {
  79.             return;
  80.         }
  81.         $percent = $this->progress->getString();
  82.  
  83.         $this->assertEquals("0 %", $percent);
  84.     }
  85. }
  86.  
  87. ?>
  88.