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

  1. <?php
  2.  
  3. class IT_Usage_TestCase extends PHPUnit_TestCase
  4. {
  5.    /**
  6.     * An HTML_Template_IT object
  7.     * @var object
  8.     */
  9.     var $tpl;
  10.  
  11.     function IT_Usage_TestCase($name)
  12.     {
  13.         $this->PHPUnit_TestCase($name);
  14.     }
  15.  
  16.     function setUp()
  17.     {
  18.         $this->tpl =& new HTML_Template_IT('./templates');
  19.     }
  20.  
  21.     function tearDown()
  22.     {
  23.         unset($this->tpl);
  24.     }
  25.  
  26.     function _stripWhitespace($str)
  27.     {
  28.         return preg_replace('/\\s+/', '', $str);
  29.     }
  30.  
  31.     function _methodExists($name) 
  32.     {
  33.         if (in_array(strtolower($name), get_class_methods($this->tpl))) {
  34.             return true;
  35.         }
  36.         $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->tpl));
  37.         return false;
  38.     }
  39.  
  40.  
  41.    /**
  42.     * Tests iterations over two blocks
  43.     *
  44.     */
  45.     function testBlockIteration()
  46.     {
  47.         $data = array(
  48.             'a',
  49.             array('b', array('1', '2', '3', '4')),
  50.             'c',
  51.             array('d', array('5', '6', '7'))
  52.         );
  53.         
  54.         $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
  55.         if (PEAR::isError($result)) {
  56.             $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  57.         }
  58.         foreach ($data as $value) {
  59.             if (is_array($value)) {
  60.                 $this->tpl->setVariable('outer', $value[0]);
  61.                 foreach ($value[1] as $v) {
  62.                     $this->tpl->setVariable('inner', $v);
  63.                     $this->tpl->parse('inner_block');
  64.                 }
  65.             } else {
  66.                 $this->tpl->setVariable('outer', $value);
  67.             }
  68.             $this->tpl->parse('outer_block');
  69.         }
  70.         $this->assertEquals('a#b|1|2|3|4#c#d|5|6|7#', $this->_stripWhitespace($this->tpl->get()));
  71.     }
  72.  
  73.    /**
  74.     * 
  75.     *
  76.     */
  77.     function testTouchBlockIteration()
  78.     {
  79.         $data = array('a','b','c','d','e');
  80.         $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
  81.         if (PEAR::isError($result)) {
  82.             $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  83.         }
  84.         for ($i = 0; $i < count($data); $i++) {
  85.             $this->tpl->setVariable('outer', $data[$i]);
  86.             // the inner_block is empty and should be removed
  87.             if (0 == $i % 2) {
  88.                 $this->tpl->touchBlock('inner_block');
  89.             }
  90.             $this->tpl->parse('outer_block');
  91.         }
  92.         $this->assertEquals('a|#b#c|#d#e|#', $this->_stripWhitespace($this->tpl->get()));
  93.     }
  94.  
  95.     // Not available in stock version
  96.  
  97.    /**
  98.     *
  99.     */
  100.     /*
  101.     function testHideBlockIteration()
  102.     {
  103.         if (!$this->_methodExists('hideBlock')) {
  104.             return;
  105.         }
  106.         $data = array('a','b','c','d','e');
  107.         $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
  108.         if (PEAR::isError($result)) {
  109.             $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  110.         }
  111.         for ($i = 0; $i < count($data); $i++) {
  112.             $this->tpl->setVariable(array(
  113.                 'inner' => $i + 1,
  114.                 'outer' => $data[$i]
  115.             ));
  116.             // the inner_block is not empty, but should be removed
  117.             if (0 == $i % 2) {
  118.                 $this->tpl->hideBlock('inner_block');
  119.             }
  120.             $this->tpl->parse('outer_block');
  121.         }
  122.         $this->assertEquals('a#b|2#c#d|4#e#', $this->_stripWhitespace($this->tpl->get()));
  123.     }
  124.     */
  125. }
  126. ?>
  127.