Blame view

mobile/source/ext/phptal/tests/EchoExecuteTest.php 2.65 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  <?php
  /**
   * PHPTAL templating engine
   *
   * PHP Version 5
   *
   * @category HTML
   * @package  PHPTAL
   * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
   * @author   Kornel LesiƄski <kornel@aardvarkmedia.co.uk>
   * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
   * @version  SVN: $Id: EchoExecuteTest.php 584 2009-04-27 11:45:25Z kornel $
   * @link     http://phptal.org/
   */
  
  require_once dirname(__FILE__)."/config.php";
  
  class EchoExecuteTest extends PHPTAL_TestCase
  {    
      private function echoExecute(PHPTAL $tpl)
      {        
          try {
              ob_start();
                  $this->assertEquals(0,strlen($tpl->echoExecute()));
              $res = ob_get_clean();
          }
          catch(Exception $e) {
              ob_end_clean();
              throw $e;
          }
          
          $res2 = $tpl->execute();
          $res3 = $tpl->execute();
          
          $this->assertEquals($res2,$res3,"Multiple runs should give same result");
          
          $this->assertEquals($res2,$res,"Execution with and without buffering should give same result");
          
          return trim_string($res);
      }
      
      function testEchoExecute()
      {
          $tpl = $this->newPHPTAL();
          $tpl->setSource('<hello/>');
                  
          $this->assertEquals("<hello></hello>",$this->echoExecute($tpl));
      }
      
      function testEchoExecuteDecls()
      {
          $tpl = $this->newPHPTAL();
          $tpl->setSource('<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><hello/>');
          
          $this->assertEquals(trim_string('<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><hello></hello>'),$this->echoExecute($tpl));
      }
      
      function testEchoExecuteDeclsMacro()
      {
          try
          {
              $tpl = $this->newPHPTAL();
              $tpl->setSource('<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><hello><m metal:define-macro="test">test</m><x metal:use-macro="test"/></hello>');
          
              $this->assertEquals(trim_string('<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><hello><m>test</m></hello>'),$this->echoExecute($tpl));
          }
          catch(PHPTAL_ConfigurationException $e)
          {
              // this is fine. Combination of macros and echoExecute is not supported yet (if it were, the test above is valid)
              $this->assertContains("echoExecute",$e->getMessage());
          }
      }
  }