AttributesInterpolationTest.php
4.27 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?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: AttributesInterpolationTest.php 579 2009-04-25 23:14:46Z kornel $
* @link http://phptal.org/
*/
require_once dirname(__FILE__)."/config.php";
class AttributesInterpolationTest extends PHPTAL_TestCase
{
public function testInterpol()
{
$src = <<<EOT
<span title="\${foo}"></span>
EOT;
$exp = <<<EOT
<span title="foo value"></span>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = 'foo value';
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
public function testInterpol2()
{
$src = <<<EOT
<span title="\${foo2} x \${structure foo} y \${foo}\${structure foo2}"></span><img/>
EOT;
$exp = <<<EOT
<span title="{foo2 <img />} x foo value y foo value{foo2 <img />}"></span><img/>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = 'foo value';
$tpl->foo2 = '{foo2 <img />}';
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
public function testInterpol3()
{
$src = <<<EOT
<span title="\${foo}\${foo}1"></span>
<span tal:attributes="title string:\${foo}\${foo}2"></span>
<span tal:attributes="title '\${foo}\${foo}3'"></span>
EOT;
$exp = <<<EOT
<span title="foo valuefoo value1"></span>
<span title="foo valuefoo value2"></span>
<span title="foo valuefoo value3"></span>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = 'foo value';
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
public function testInterpol3a()
{
$src = <<<EOT
<span tal:attributes="title php:'\${foo}\${foo}'"></span>
<span title="<?php echo '\${foo}\${foo}' ?>"></span>
EOT;
$exp = <<<EOT
<span title="\${foo}\${foo}"></span>
<span title="\${foo}\${foo}"></span>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = 'foo value';
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
public function testNoInterpol()
{
$src = <<<EOT
<span title="$\${foo}"></span>
EOT;
$exp = <<<EOT
<span title="\${foo}"></span>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = 'foo value';
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
public function testNoInterpolAdv()
{
$src = <<<EOT
<span title="$$\${foo}"></span>
EOT;
$exp = <<<EOT
<span title="$\${foo}"></span>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = 'foo value';
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
public function testPHPBlock()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p test=\'te&st<?php echo "<x>"; ?>test<?php print("&") ?>test\'/>');
$this->assertEquals('<p test="te&st<x>test&test"></p>', $tpl->execute());
}
public function testPHPBlockShort()
{
ini_set('short_open_tag',1);
if (!ini_get('short_open_tag')) $this->markTestSkipped("PHP is buggy");
$tpl = $this->newPHPTAL();
$tpl->setSource('<p test=\'te&st<? print("<x>"); ?>test<?= "&" ?>test\'/>');
$this->assertEquals('<p test="te&st<x>test&test"></p>', $tpl->execute());
ini_restore('short_open_tag');
}
public function testPHPBlockNoShort()
{
ini_set('short_open_tag', 0);
if (ini_get('short_open_tag')) $this->markTestSkipped("PHP is buggy");
$tpl = $this->newPHPTAL();
$tpl->setSource('<p test=\'te&st<? print("<x>"); ?>test<?= "&" ?>test\'/>');
try
{
$this->assertEquals(trim_string('<p test="te&st<? print("<x>"); ?>test<?= "&" ?>test"></p>'), trim_string($tpl->execute()));
}
catch(PHPTAL_ParserException $e) {/* xml ill-formedness error is ok too */}
ini_restore('short_open_tag');
}
}