[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/HTML_Template_IT/tests/ -> IT_api_testcase.php (source)

   1  <?php
   2  
   3  class IT_api_TestCase extends PHPUnit_TestCase
   4  {
   5     /**
   6      * An HTML_Template_IT object
   7      * @var object
   8      */
   9      var $tpl;
  10  
  11      function IT_api_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      * Tests a setTemplate method 
  42      *
  43      */
  44      function testSetTemplate()
  45      {
  46          $result = $this->tpl->setTemplate('A template', false, false);
  47          if (PEAR::isError($result)) {
  48              $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
  49          }
  50          $this->assertEquals('A template', $this->tpl->get());
  51      }
  52  
  53     /**
  54      * Tests a loadTemplatefile method 
  55      *
  56      */
  57      function testLoadTemplatefile()
  58      {
  59          $result = $this->tpl->loadTemplatefile('loadtemplatefile.html', false, false);
  60          if (PEAR::isError($result)) {
  61              $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  62          }
  63          $this->assertEquals('A template', trim($this->tpl->get()));
  64      }
  65  
  66     /**
  67      * Tests a setVariable method
  68      *
  69      */
  70      function testSetVariable()
  71      {
  72          $result = $this->tpl->setTemplate('{placeholder1} {placeholder2} {placeholder3}', true, true);
  73          if (PEAR::isError($result)) {
  74              $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
  75          }
  76          // "scalar" call
  77          $this->tpl->setVariable('placeholder1', 'var1');
  78          // array call
  79          $this->tpl->setVariable(array(
  80              'placeholder2' => 'var2',
  81              'placeholder3' => 'var3'
  82          ));
  83          $this->assertEquals('var1 var2 var3', $this->tpl->get());
  84      }
  85  
  86     /**
  87      * Tests the <!-- INCLUDE --> functionality 
  88      *
  89      */
  90      function testInclude()
  91      {
  92          $result = $this->tpl->loadTemplateFile('include.html', false, false);
  93          if (PEAR::isError($result)) {
  94              $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
  95          }
  96          $this->assertEquals('Master file; Included file', trim($this->tpl->get()));
  97      }
  98  
  99     /**
 100      *
 101      */
 102      function testCurrentBlock()
 103      {
 104          $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);
 105          if (PEAR::isError($result)) {
 106              $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
 107          }
 108          $this->tpl->setVariable('outer', 'a');
 109          $this->tpl->setCurrentBlock('inner_block');
 110          for ($i = 0; $i < 5; $i++) {
 111              $this->tpl->setVariable('inner', $i + 1);
 112              $this->tpl->parseCurrentBlock();
 113          } // for
 114          $this->assertEquals('a|1|2|3|4|5#', $this->_stripWhitespace($this->tpl->get()));
 115      }
 116  
 117     /**
 118      *
 119      */
 120      function testRemovePlaceholders()
 121      {
 122          $result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
 123          if (PEAR::isError($result)) {
 124              $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
 125          }
 126          // we do not set {placeholder3}
 127          $this->tpl->setVariable(array(
 128              'placeholder1' => 'var1',
 129              'placeholder2' => 'var2'
 130          ));
 131          $this->assertEquals('var1,var2,', $this->tpl->get());
 132  
 133          // Now, we should really add a switch for keeping {stuff} in
 134          // data supplied to setVariable() safe. Until then, removing it should
 135          // be expected behaviour
 136          $result = $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);
 137          if (PEAR::isError($result)) {
 138              $this->assertTrue(false, 'Error setting template: '. $result->getMessage());
 139          }
 140          $this->tpl->setVariable(array(
 141              'placeholder1' => 'var1',
 142              'placeholder2' => 'var2',
 143              'placeholder3' => 'var3{stuff}'
 144          ));
 145          $this->assertEquals('var1,var2,var3', $this->tpl->get());
 146      }
 147  
 148     /**
 149      *
 150      */
 151      function testTouchBlock()
 152      {
 153          $result = $this->tpl->loadTemplateFile('blockiteration.html', false, true);
 154          if (PEAR::isError($result)) {
 155              $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
 156          }
 157          $this->tpl->setVariable('outer', 'data');
 158          // inner_block should be preserved in output, even if empty
 159          $this->tpl->touchBlock('inner_block');
 160          $this->assertEquals('data|{inner}#', $this->_stripWhitespace($this->tpl->get()));
 161      }
 162     
 163      // Not available in stock class
 164  
 165     /**
 166      *
 167      */
 168      /*
 169      function testHideBlock()
 170      {
 171          if (!$this->_methodExists('hideBlock')) {
 172              return;
 173          }
 174          $result = $this->tpl->loadTemplateFile('blockiteration.html', false, true);
 175          if (PEAR::isError($result)) {
 176              $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
 177          }
 178          $this->tpl->setVariable(array(
 179              'outer' => 'data',
 180              'inner' => 'stuff'
 181          ));
 182          // inner_block is not empty, but should be removed nonetheless
 183          $this->tpl->hideBlock('inner_block');
 184          $this->assertEquals('data#', $this->_stripWhitespace($this->tpl->get()));
 185      }
 186      */
 187     /**
 188      *
 189      */
 190      /*
 191      function testSetGlobalVariable()
 192      {
 193          if (!$this->_methodExists('setGlobalVariable')) {
 194              return;
 195          }
 196          $result = $this->tpl->loadTemplateFile('globals.html', false, true);
 197          if (PEAR::isError($result)) {
 198              $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());
 199          }
 200          $this->tpl->setGlobalVariable('glob', 'glob');
 201          // {var2} is not, block_two should be removed
 202          $this->tpl->setVariable(array(
 203              'var1' => 'one',
 204              'var3' => 'three'
 205          ));
 206          for ($i = 0; $i < 3; $i++) {
 207              $this->tpl->setVariable('var4', $i + 1);
 208              $this->tpl->parse('block_four');
 209          } // for
 210          $this->assertEquals('glob:one#glob:three|glob:1|glob:2|glob:3#', $this->_stripWhitespace($this->tpl->get()));
 211      }
 212      */
 213  }
 214  
 215  ?>


Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7