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

  1. <?php
  2.  
  3. require_once 'IT_api_testcase.php';
  4.  
  5. function _uppercaseCallback($ary)
  6. {
  7.     return strtoupper($ary[0]);
  8. }
  9.  
  10.  
  11. class ITX_api_TestCase extends IT_api_TestCase
  12. {
  13.     function ITX_api_TestCase($name)
  14.     {
  15.         $this->IT_api_TestCase($name);
  16.     }
  17.  
  18.     function setUp()
  19.     {
  20.         $this->tpl =& new HTML_Template_ITX('./templates');
  21.     }
  22.  
  23.     function testPlaceholderExists()
  24.     {
  25.         $this->tpl->setTemplate('{var}');
  26.         $this->assertTrue($this->tpl->placeholderExists('var'), 'Existing placeholder \'var\' reported as nonexistant');
  27.         $this->assertTrue(!$this->tpl->placeholderExists('foobar'), 'Nonexistant placeholder \'foobar\' reported as existing');
  28.         $this->assertTrue($this->tpl->placeholderExists('var', '__global__'), 'Existing in block \'__global__\' placeholder \'var\' reported as nonexistant');
  29.         $this->assertTrue(!$this->tpl->placeholderExists('foobar', '__global__'), 'Nonexistant in block \'__global__\' placeholder \'foobar\' reported as existing');
  30.     }
  31.  
  32.     function testBlockExists()
  33.     {
  34.         $this->tpl->setTemplate('{var}');
  35.         $this->assertTrue($this->tpl->blockExists('__global__'), 'Existing block \'__global__\' reported as nonexistant');
  36.         $this->assertTrue(!$this->tpl->blockExists('foobar'), 'Nonexistant block \'foobar\' reported as existing');
  37.     }
  38.  
  39.     function testAddBlock()
  40.     {
  41.         $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
  42.         if (PEAR::isError($result)) {
  43.             $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  44.         }
  45.         $this->tpl->addBlock('var', 'added', 'added:{new_var}');
  46.         $this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');
  47.         $this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');
  48.         $this->tpl->setVariable('new_var', 'new_value');
  49.         $this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));
  50.     }
  51.  
  52.     function testAddBlockfile()
  53.     {
  54.         $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
  55.         if (PEAR::isError($result)) {
  56.             $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  57.         }
  58.         $result = $this->tpl->addBlockfile('var', 'added', 'addblock.html');
  59.         if (PEAR::isError($result)) {
  60.             $this->assertTrue(false, 'Error adding block from file: '. $result->getMessage());
  61.         }
  62.         $this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');
  63.         $this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');
  64.         $this->tpl->setVariable('new_var', 'new_value');
  65.         $this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));
  66.     }
  67.  
  68.     function testReplaceBlock()
  69.     {
  70.         $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
  71.         if (PEAR::isError($result)) {
  72.             $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  73.         }
  74.         $this->tpl->setVariable('old_var', 'old_value');
  75.         $this->tpl->parse('old_block');
  76.         // old_block's contents should be discarded
  77.         $this->tpl->replaceBlock('old_block', 'replaced:{replaced_var}#', false);
  78.         $this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),
  79.                           'The replaced block\'s contents seem to be still present');
  80.         $this->tpl->setVariable('replaced_var', 'replaced_value');
  81.         $this->tpl->parse('old_block');
  82.         // this time old_block's contents should be preserved
  83.         $this->tpl->replaceBlock('old_block', 'replaced_again:{brand_new_var}', true);
  84.         $this->tpl->setVariable('brand_new_var', 'brand_new_value');
  85.         $this->assertEquals('replaced:replaced_value#replaced_again:brand_new_value', $this->_stripWhitespace($this->tpl->get()));
  86.     }
  87.  
  88.     function testReplaceBlockfile()
  89.     {
  90.         $result = $this->tpl->loadTemplatefile('blocks.html', true, true);
  91.         if (PEAR::isError($result)) {
  92.             $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  93.         }
  94.         $this->tpl->setVariable('old_var', 'old_value');
  95.         $this->tpl->parse('old_block');
  96.         // old_block's contents should be discarded
  97.         $result = $this->tpl->replaceBlockfile('old_block', 'replaceblock.html', false);
  98.         if (PEAR::isError($result)) {
  99.             $this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());
  100.         }
  101.         $this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),
  102.                           'The replaced block\'s contents seem to be still present');
  103.         $this->tpl->setVariable(array(
  104.             'replaced_var'       => 'replaced_value',
  105.             'replaced_inner_var' => 'inner_value'
  106.         ));
  107.         $this->tpl->parse('old_block');
  108.         // this time old_block's contents should be preserved
  109.         $result = $this->tpl->replaceBlockfile('old_block', 'addblock.html', true);
  110.         if (PEAR::isError($result)) {
  111.             $this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());
  112.         }
  113.         $this->tpl->setVariable('new_var', 'again');
  114.         $this->assertEquals('replaced:replaced_value|inner_value#added:again', $this->_stripWhitespace($this->tpl->get()));
  115.     }
  116.  
  117.     function testCallback()
  118.     {
  119.         $this->tpl->setTemplate('callback:func_uppercase(word)');
  120.         $this->tpl->setCallbackFunction('uppercase', '_uppercaseCallback');
  121.         $res = $this->tpl->performCallback();
  122.         if (PEAR::isError($res)) {
  123.             $this->assertTrue(false, 'Error performing callback: '. $res->getMessage());
  124.         }
  125.         $this->assertEquals('callback:WORD', $this->tpl->get());
  126.     }
  127. }
  128.  
  129. ?>
  130.