[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/tests/cases/compiler/ -> WactCodeWriterTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  require_once 'limb/wact/src/compiler/templatecompiler.inc.php';
  11  
  12  class WactCodeWriterTest extends UnitTestCase
  13  {
  14    protected $writer;
  15  
  16    function setUp()
  17    {
  18      $this->writer = new WactCodeWriter();
  19    }
  20  
  21    function testGetCode()
  22    {
  23      $this->assertEqual($this->writer->renderCode(),'');
  24    }
  25  
  26    function testGetSetCode()
  27    {
  28      $this->writer->setCode($code = 'code');
  29      $this->assertEqual($code, $this->writer->getCode());
  30    }
  31  
  32    function testWritePHP()
  33    {
  34      $this->writer->writePHP('echo ("Hello World!");');
  35      $this->assertEqual($this->writer->renderCode(),'<?php echo ("Hello World!"); ?>');
  36    }
  37  
  38    function testWriteHTML()
  39    {
  40      $this->writer->writeHTML('<p>Hello World!</p>');
  41      $this->assertEqual($this->writer->renderCode(),'<p>Hello World!</p>');
  42    }
  43  
  44    function testSwithBetweenPHPAndHTML()
  45    {
  46      $this->writer->writePHP('echo ("Hello World!");');
  47      $this->writer->writeHTML('<p>Hello World!</p>');
  48      $this->writer->writePHP('echo ("Hello World!");');
  49      $this->assertEqual($this->writer->renderCode(),
  50                         '<?php echo ("Hello World!"); ?><p>Hello World!</p><?php echo ("Hello World!"); ?>');
  51    }
  52  
  53    function testRegisterInclude()
  54    {
  55      $this->writer->registerInclude('test.php');
  56      $this->assertEqual($this->writer->renderCode(),'<?php '."require_once 'test.php';\n".'?>');
  57    }
  58  
  59    function testReset()
  60    {
  61      $this->writer->writePHP('echo ("Hello World!");');
  62      $this->writer->registerInclude('test.php');
  63      $this->writer->reset();
  64      $this->assertEqual($this->writer->renderCode(), '');
  65    }
  66  
  67    function testBeginFunction()
  68    {
  69      $params = '($a,$b,$c)';
  70      $this->writer->beginFunction($params);
  71      $this->assertEqual($this->writer->renderCode(),'<?php function tpl1'.$params ." {\n ?>");
  72    }
  73  
  74    function testEndFunction()
  75    {
  76      $this->writer->endFunction();
  77      $this->assertEqual($this->writer->renderCode(),'<?php '." }\n".' ?>');
  78    }
  79  
  80    function testSetFunctionPrefix()
  81    {
  82      $this->writer->setFunctionPrefix('Test');
  83      $params = '($a,$b,$c)';
  84      $this->writer->beginFunction($params);
  85      $this->assertEqual($this->writer->renderCode(),'<?php function tplTest1'.$params ." {\n ?>");
  86    }
  87  
  88    function testGetTempVariable()
  89    {
  90      $var = $this->writer->getTempVariable();
  91      $this->assertWantedPattern('/[a-z][a-z0-9]*/i', $var);
  92    }
  93  
  94    function testGetSecondTempVariable()
  95    {
  96      $A = $this->writer->getTempVariable();
  97      $B = $this->writer->getTempVariable();
  98      $this->assertNotEqual($A, $B);
  99    }
 100  
 101    function testGetTempVariablesMany()
 102    {
 103      for ($i = 1; $i <= 30; $i++)
 104      {
 105        $var = $this->writer->getTempVariable();
 106        $this->assertWantedPattern('/[a-z][a-z0-9]*/i', $var);
 107      }
 108    }
 109  }
 110  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7