Blame view

mobile/source/ext/phptal/tests/TalesStringTest.php 3.19 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  <?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: TalesStringTest.php 610 2009-05-24 00:32:13Z kornel $
   * @link     http://phptal.org/
   */
  
  require_once dirname(__FILE__)."/config.php";
  
  PHPTAL::setIncludePath();
  require_once 'PHPTAL/Tales.php';
  PHPTAL::restoreIncludePath();
  
  class TalesStringTest extends PHPTAL_TestCase {
  
      function testSimple()
      {
          $this->assertEquals('\'this is a string\'', PHPTAL_Php_TalesInternal::string('this is a string'));
      }
  
      function testDoubleDollar()
      {
          $this->assertEquals('\'this is a $string\'', PHPTAL_Php_TalesInternal::string('this is a $$string'));
      }
  
      function testSubPathSimple()
      {
          $res = PHPTAL_Php_TalesInternal::string('hello $name how are you ?');
          $rgm = preg_match('/\'hello \'.*?\$ctx->name.*?\' how are you \?\'$/', $res);
          $this->assertEquals(1, $rgm);
      }
  
      function testSubPath()
      {
          $res = PHPTAL_Php_TalesInternal::string('${name}');
          $this->assertRegExp('/^(\'\'\s*?\.*)?\$ctx->name(.*?\'\')?$/', $res);
      }
  
      function testSubPathExtended()
      {
          $res = PHPTAL_Php_TalesInternal::string('hello ${user/name} how are you ?');
          $rgm = preg_match('/\'hello \'.*?\$ctx->user, \'name\'.*?\' how are you \?\'$/', $res);
          $this->assertEquals(1, $rgm);
      }
  
      function testQuote()
      {
          $tpl = $this->newPHPTAL('input/tales-string-01.html');
          $res = $tpl->execute();
          $res = trim_string($res);
          $exp = trim_file('output/tales-string-01.html');
          $this->assertEquals($exp, $res);
      }
  
      function testDoubleVar()
      {
          $res = PHPTAL_Php_TalesInternal::string('hello $foo $bar');
          $this->assertEquals(1, preg_match('/ctx->foo/', $res), '$foo not interpolated');
          $this->assertEquals(1, preg_match('/ctx->bar/', $res), '$bar not interpolated');
      }
  
      function testDoubleDotComa()
      {
          $tpl = $this->newPHPTAL('input/tales-string-02.html');
          $res = $tpl->execute();
          $res = trim_string($res);
          $exp = trim_file('output/tales-string-02.html');
          $this->assertEquals($exp, $res);
      }
  
      function testEscape()
      {
          $tpl = $this->newPHPTAL('input/tales-string-03.html');
          $res = $tpl->execute();
          $res = trim_string($res);
          $exp = trim_file('output/tales-string-03.html');
          $this->assertEquals($exp,$res);
      }
      
      function testStructure()
      {
          $tpl = $this->newPHPTAL();
          $tpl->setSource('<p>
              ${string:&lt;foo/&gt;}
              ${structure string:&lt;foo/&gt;}
              <x y="${string:&lt;foo/&gt;}" tal:content="string:&lt;foo/&gt;" />
              <x y="${structure string:&lt;foo/&gt;}" tal:content="structure string:&lt;foo/&gt;" />
          </p>');
          $this->assertEquals(trim_string('<p>&lt;foo/&gt;<foo/><x y="&lt;foo/&gt;">&lt;foo/&gt;</x><x y="<foo/>"><foo/></x></p>'),
                              trim_string($tpl->execute()));
      }
  }