TalContentTest.php
5.67 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
192
193
194
195
196
197
198
199
200
201
202
<?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: TalContentTest.php 674 2009-07-20 09:44:10Z kornel $
* @link http://phptal.org/
*/
class DummyToStringObject {
public function __construct($value){ $this->_value = $value; }
public function __toString(){ return $this->_value; }
private $_value;
}
require_once dirname(__FILE__)."/config.php";
class TalContentTest extends PHPTAL_TestCase
{
function testSimple()
{
$tpl = $this->newPHPTAL('input/tal-content.01.html');
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-content.01.html');
$this->assertEquals($exp, $res);
}
function testVar()
{
$tpl = $this->newPHPTAL('input/tal-content.02.html');
$tpl->content = 'my content';
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-content.02.html');
$this->assertEquals($exp, $res);
}
function testStructure()
{
$tpl = $this->newPHPTAL('input/tal-content.03.html');
$tpl->content = '<foo><bar/></foo>';
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-content.03.html');
$this->assertEquals($exp, $res);
}
function testNothing()
{
$tpl = $this->newPHPTAL('input/tal-content.04.html');
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-content.04.html');
$this->assertEquals($exp, $res);
}
function testDefault()
{
$tpl = $this->newPHPTAL('input/tal-content.05.html');
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-content.05.html');
$this->assertEquals($exp, $res);
}
function testChain()
{
$tpl = $this->newPHPTAL('input/tal-content.06.html');
$res = trim_string($tpl->execute());
$exp = trim_file('output/tal-content.06.html');
$this->assertEquals($exp, $res);
}
function testEmpty()
{
$src = '
<root>
<span tal:content="nullv | falsev | emptystrv | zerov | default">default</span>
<span tal:content="nullv | falsev | emptystrv | default">default</span>
</root>
';
$exp = '
<root>
<span>0</span>
<span>default</span>
</root>
';
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->nullv = null;
$tpl->falsev = false;
$tpl->emptystrv = '';
$tpl->zerov = 0;
$res = $tpl->execute();
$this->assertEquals(trim_string($exp), trim_string($res));
}
function testObjectEcho()
{
$foo = new DummyToStringObject('foo value');
$src = <<<EOT
<root tal:content="foo"/>
EOT;
$exp = <<<EOT
<root>foo value</root>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = $foo;
$res = $tpl->execute();
$this->assertEquals($res, $exp);
}
function testObjectEchoStructure()
{
$foo = new DummyToStringObject('foo value');
$src = <<<EOT
<root tal:content="structure foo"/>
EOT;
$exp = <<<EOT
<root>foo value</root>
EOT;
$tpl = $this->newPHPTAL();
$tpl->setSource($src);
$tpl->foo = $foo;
$res = $tpl->execute();
$this->assertEquals($res, $exp);
}
/**
* @expectedException PHPTAL_VariableNotFoundException
*/
function testErrorsThrow()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:content="erroridontexist"/>');
$tpl->execute();
}
/**
* @expectedException PHPTAL_VariableNotFoundException
*/
function testErrorsThrow2()
{
$this->markTestSkipped("tal:define and tal:attributes rely on chains not throwing");//FIXME
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:content="erroridontexist2 | erroridontexist2"/>');
$tpl->execute();
}
/**
* @expectedException PHPTAL_VariableNotFoundException
*/
function testErrorsThrow3()
{
$this->markTestSkipped("tal:define and tal:attributes rely on chains not throwing");//FIXME
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:replace="erroridontexist3 | erroridontexist3"/>');
$tpl->execute();
}
/**
* @expectedException PHPTAL_VariableNotFoundException
*/
function testErrorsThrow4()
{
$this->markTestSkipped("tal:define and tal:attributes rely on chains not throwing");//FIXME
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:condition="erroridontexist4 | erroridontexist4"/>');
$tpl->execute();
}
function testErrorsSilenced()
{
$tpl = $this->newPHPTAL();
$tpl->setSource('<p tal:content="erroridontexist | nothing"/>');
$this->assertEquals('<p></p>',$tpl->execute());
}
function testZeroIsNotEmpty()
{
$tpl = $this->newPHPTAL();
$tpl->zero = '0';
$tpl->setSource('<p tal:content="zero | erroridontexist"/>');
$this->assertEquals('<p>0</p>',$tpl->execute());
}
function testFalseLast()
{
$tpl = $this->newPHPTAL();
$tpl->one_row = array('RESPONSIBLE_OFFICE'=>'responsible_office1');
$tpl->setSource('<span tal:define="resp_office offices/${one_row/RESPONSIBLE_OFFICE} | false">${resp_office}</span>');
$this->assertEquals('<span>0</span>',$tpl->execute());
}
}