TalAttributesTest.php
5.89 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?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: TalAttributesTest.php 611 2009-05-24 00:40:00Z kornel $
* @link http://phptal.org/
*/
require_once dirname(__FILE__)."/config.php";
if (!class_exists('DummyTag',false)) {
class DummyTag {}
}
class TalAttributesTest extends PHPTAL_TestCase
{
function testSimple()
{
$tpl = $this->newPHPTAL('input/tal-attributes.01.html');
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-attributes.01.html');
$this->assertEquals($exp, $res);
}
function testWithContent()
{
$tpl = $this->newPHPTAL('input/tal-attributes.02.html');
$tpl->spanClass = 'dummy';
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-attributes.02.html');
$this->assertEquals($exp, $res);
}
function testMultiples()
{
$tpl = $this->newPHPTAL('input/tal-attributes.03.html');
$tpl->spanClass = 'dummy';
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-attributes.03.html');
$this->assertEquals($exp, $res);
}
function testChain()
{
$tpl = $this->newPHPTAL('input/tal-attributes.04.html');
$tpl->spanClass = 'dummy';
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-attributes.04.html');
$this->assertEquals($exp, $res);
}
function testMultipleChains()
{
$tpl = $this->newPHPTAL('input/tal-attributes.05.html');
$tpl->spanClass = 'dummy';
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-attributes.05.html');
$this->assertEquals($exp, $res);
}
function testEncoding()
{
$tpl = $this->newPHPTAL('input/tal-attributes.06.html');
$tpl->href = "http://www.test.com/?foo=bar&buz=biz&<thisissomething";
$tpl->title = 'bla bla <blabla>';
$res = $tpl->execute();
$res = trim_string($res);
$exp = trim_file('output/tal-attributes.06.html');
$this->assertEquals($exp, $res);
}
function testZeroValues()
{
$tpl = $this->newPHPTAL('input/tal-attributes.07.html');
$tpl->href1 = 0;
$tpl->href2 = 0;
$tpl->href3 = 0;
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-attributes.07.html');
$this->assertEquals($exp, $res);
}
function testEmpty()
{
$src = <<<EOT
<span class=""'default" tal:attributes="class nullv | falsev | emptystrv | zerov | default"></span>
EOT;
$exp = <<<EOT
<span class="0"></span>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src, __FILE__);
$tpl->nullv = null;
$tpl->falsev = false;
$tpl->emptystrv = '';
$tpl->zerov = 0;
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
function testSingleQuote()
{
$exp = trim_file('output/tal-attributes.08.html');
$tpl = $this->newPHPTAL('input/tal-attributes.08.html');
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
function testStructure()
{
$exp = trim_file('output/tal-attributes.09.html');
$tpl = $this->newPHPTAL('input/tal-attributes.09.html');
$tpl->value = "return confirm('hel<lo');";
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
function testChainedStructure()
{
$exp = trim_file('output/tal-attributes.10.html');
$tpl = $this->newPHPTAL('input/tal-attributes.10.html');
$tpl->value1 = false;
$tpl->value2 = "return confirm('hel<lo');";
$res = $tpl->execute();
$this->assertEquals($exp, $res);
}
function testNothingValue()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:attributes="title missing | nothing"></p>');
$res = $tpl->execute();
$this->assertEquals($res,'<p></p>');
}
function testNULLValue()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:attributes="title missing | php:NULL"></p><p tal:attributes="class \'ok\'; title null:blah"></p>');
$res = $tpl->execute();
$this->assertEquals('<p></p><p class="ok"></p>',$res);
}
function testNULLValueNoAlternative()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:attributes="title php:NULL"></p>');
$res = $tpl->execute();
$this->assertEquals('<p></p>',$res);
}
function testNULLValueReversed()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:attributes="title php:true ? NULL : false; class structure php:false ? NULL : \'fo\\\'o\'; style structure php:true ? NULL : false;"></p>');
$res = $tpl->execute();
$this->assertEquals('<p class="fo\'o"></p>',$res);
}
function testEmptyValue()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:attributes="title missing | \'\'"></p><p tal:attributes="title missing | php:\'\'"></p>');
$res = $tpl->execute();
$this->assertEquals('<p title=""></p><p title=""></p>',$res);
}
function testSemicolon()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<div><p tal:content="\'\\\'a;b;;c;;;d\'" tal:attributes="style \'color:red;; font-weight:bold;;;;\'; title php:\'\\\'test;;test;;;;test\'"></p></div>');
$res = $tpl->execute();
$this->assertEquals($res,'<div><p style="color:red; font-weight:bold;;" title="'test;test;;test">'a;b;;c;;;d</p></div>');
}
//TODO: test xhtml boolean attributes (currently tested in 'old' tests)
}
function phptal_tales_null($code,$nothrow)
{
return 'NULL';
}