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

  1. <?php
  2.  
  3. /**
  4.  * API Unit tests for HTML_Progress_DM class.
  5.  * 
  6.  * @version    $Id: HTML_Progress_TestCase_DM.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_DM extends PHPUnit_TestCase
  12. {
  13.     /**
  14.      * HTML_Progress_DM instance
  15.      *
  16.      * @var        object
  17.      */
  18.     var $dataModel;
  19.  
  20.     function HTML_Progress_TestCase_DM($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->dataModel = new HTML_Progress_DM(25,200,10);
  32.         Error_Raise::setContextGrabber($this->dataModel->_package, array('Error_Util', '_getFileLine'));
  33.     }
  34.  
  35.     function tearDown()
  36.     {
  37.         unset($this->dataModel);
  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->dataModel))) {
  48.             return true;
  49.         }
  50.         $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->dataModel));
  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 setMinimum.
  62.      *
  63.      */
  64.     function test_setMinimum_fail_no_integer()
  65.     {
  66.         if (!$this->_methodExists('setMinimum')) {
  67.             return;
  68.         }
  69.         $this->dataModel->setMinimum('');
  70.     }
  71.  
  72.     function test_setMinimum_fail_no_positive()
  73.     {
  74.         if (!$this->_methodExists('setMinimum')) {
  75.             return;
  76.         }
  77.         $this->dataModel->setMinimum(-1);
  78.     }
  79.  
  80.     function test_setMinimum_fail_greater_max()
  81.     {
  82.         if (!$this->_methodExists('setMinimum')) {
  83.             return;
  84.         }
  85.         $this->dataModel->setMinimum(500);
  86.     }
  87.  
  88.     function test_setMinimum()
  89.     {
  90.         if (!$this->_methodExists('setMinimum')) {
  91.             return;
  92.         }
  93.         $this->dataModel->setMinimum(10);
  94.  
  95.         $this->assertFalse($this->errorThrown, 'error thrown');
  96.     }
  97.  
  98.     /**
  99.      * TestCases for method setMaximum.
  100.      *
  101.      */
  102.     function test_setMaximum_fail_no_integer()
  103.     {
  104.         if (!$this->_methodExists('setMaximum')) {
  105.             return;
  106.         }
  107.         $this->dataModel->setMaximum('');
  108.     }
  109.  
  110.     function test_setMaximum_fail_no_positive()
  111.     {
  112.         if (!$this->_methodExists('setMaximum')) {
  113.             return;
  114.         }
  115.         $this->dataModel->setMaximum(-1);
  116.     }
  117.  
  118.     function test_setMaximum_fail_less_min()
  119.     {
  120.         if (!$this->_methodExists('setMaximum')) {
  121.             return;
  122.         }
  123.         $this->dataModel->setMaximum(10);
  124.     }
  125.  
  126.     function test_setMaximum()
  127.     {
  128.         if (!$this->_methodExists('setMaximum')) {
  129.             return;
  130.         }
  131.         $this->dataModel->setMaximum(60);
  132.  
  133.         $this->assertFalse($this->errorThrown, 'error thrown');
  134.     }
  135.  
  136.     /**
  137.      * TestCases for method setIncrement.
  138.      *
  139.      */
  140.     function test_setIncrement_fail_no_integer()
  141.     {
  142.         if (!$this->_methodExists('setIncrement')) {
  143.             return;
  144.         }
  145.         $this->dataModel->setIncrement('');
  146.     }
  147.  
  148.     function test_setIncrement_fail_no_zero()
  149.     {
  150.         if (!$this->_methodExists('setIncrement')) {
  151.             return;
  152.         }
  153.         $this->dataModel->setIncrement(0);
  154.     }
  155.  
  156.     function test_setIncrement()
  157.     {
  158.         if (!$this->_methodExists('setIncrement')) {
  159.             return;
  160.         }
  161.         $this->dataModel->setIncrement(-10);
  162.  
  163.         $this->assertFalse($this->errorThrown, 'error thrown');
  164.     }
  165.  
  166.     /**
  167.      * TestCases for method setValue.
  168.      *
  169.      */
  170.     function test_setValue_fail_no_integer()
  171.     {
  172.         if (!$this->_methodExists('setValue')) {
  173.             return;
  174.         }
  175.         $this->dataModel->setValue('');
  176.     }
  177.  
  178.     function test_setValue_fail_less_min()
  179.     {
  180.         if (!$this->_methodExists('setValue')) {
  181.             return;
  182.         }
  183.         $this->dataModel->setValue(5);
  184.     }
  185.  
  186.     function test_setValue_fail_greater_max()
  187.     {
  188.         if (!$this->_methodExists('setValue')) {
  189.             return;
  190.         }
  191.         $this->dataModel->setValue(1500);
  192.     }
  193.  
  194.     function test_setValue()
  195.     {
  196.         if (!$this->_methodExists('setValue')) {
  197.             return;
  198.         }
  199.         $this->dataModel->setValue(30);
  200.  
  201.         $this->assertFalse($this->errorThrown, 'error thrown');
  202.     }
  203. }
  204.  
  205. ?>
  206.