PhptalTest.php
5.43 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: PhptalTest.php 757 2009-10-24 23:53:56Z kornel $
* @link http://phptal.org/
*/
require_once dirname(__FILE__)."/config.php";
class PhptalTest extends PHPTAL_TestCase
{
function test01()
{
$tpl = $this->newPHPTAL('input/phptal.01.html');
$tpl->setOutputMode(PHPTAL::XML);
$res = $tpl->execute();
$this->assertEquals('<dummy/>', $res);
}
function testXmlHeader()
{
$tpl = $this->newPHPTAL('input/phptal.02.html');
$res = trim_string($tpl->execute());
$exp = trim_file('output/phptal.02.html');
$this->assertEquals($exp, $res);
}
function testExceptionNoEcho()
{
$tpl = $this->newPHPTAL('input/phptal.03.html');
ob_start();
try {
$res = $tpl->execute();
}
catch (Exception $e){
}
$c = ob_get_contents();
ob_end_clean();
$this->assertEquals('', $c);
}
function testRepositorySingle()
{
$tpl = $this->newPHPTAL('phptal.01.html');
$tpl->setTemplateRepository('input');
$tpl->setOutputMode(PHPTAL::XML);
$res = $tpl->execute();
$this->assertEquals('<dummy/>', $res);
}
function testRepositorySingleWithSlash()
{
$tpl = $this->newPHPTAL('phptal.01.html');
$tpl->setTemplateRepository('input/');
$tpl->setOutputMode(PHPTAL::XML);
$res = $tpl->execute();
$this->assertEquals('<dummy/>', $res);
}
function testRepositoryMuliple()
{
$tpl = $this->newPHPTAL('phptal.01.html');
$tpl->setTemplateRepository(array('bar', 'input/'));
$tpl->setOutputMode(PHPTAL::XML);
$res = $tpl->execute();
$this->assertEquals('<dummy/>', $res);
}
function testSetTemplate()
{
$tpl = $this->newPHPTAL();
$tpl->setTemplateRepository(array('bar', 'input/'));
$tpl->setOutputMode(PHPTAL::XML);
$tpl->setTemplate('phptal.01.html');
$res = $tpl->execute();
$this->assertEquals('<dummy/>', $res);
}
function testXmlMode()
{
$tpl = $this->newPHPTAL('input/xml.04.xml');
$tpl->setOutputMode(PHPTAL::XML);
$res = trim_string($tpl->execute());
$exp = trim_file('input/xml.04.xml');
$this->assertEquals($exp, $res);
}
function testSource()
{
$source = '<span tal:content="foo"/>';
$tpl = $this->newPHPTAL();
$tpl->foo = 'foo value';
$tpl->setSource($source);
$res = $tpl->execute();
$this->assertEquals('<span>foo value</span>', $res);
$this->assertRegExp('/^tpl_\d{8}_/', $tpl->getFunctionName());
$this->assertContains('string', $tpl->getFunctionName());
$this->assertNotContains(PHPTAL_VERSION, $tpl->getFunctionName());
}
/**
* @todo: write it :)
*/
function testFunctionNameChangesWhenSettingsChange()
{
$this->markTestIncomplete();
}
function testSourceWithPath()
{
$source = '<span tal:content="foo"/>';
$tpl = $this->newPHPTAL();
$tpl->foo = 'foo value';
$tpl->setSource($source, $fakename = 'abc12345');
$res = $tpl->execute();
$this->assertEquals('<span>foo value</span>', $res);
$this->assertRegExp('/^tpl_\d{8}_/', $tpl->getFunctionName());
$this->assertContains($fakename, $tpl->getFunctionName());
$this->assertNotContains(PHPTAL_VERSION, $tpl->getFunctionName());
}
function testStripComments()
{
$tpl = $this->newPHPTAL('input/phptal.04.html');
$exp = trim_file('output/phptal.04.html');
$tpl->stripComments(true);
$res = $tpl->execute();
$res = trim_string($res);
$this->assertEquals($exp, $res);
}
function testUnknownOutputMode()
{
try {
$tpl = $this->newPHPTAL();
$tpl->setOutputMode('unknown');
$this->assertTrue(false);
}
catch (PHPTAL_Exception $e){
$this->assertTrue(true);
}
}
function testZeroedContent()
{
$tpl = $this->newPHPTAL('input/phptal.05.html');
$res = $tpl->execute();
$exp = trim_file('input/phptal.05.html');
$this->assertEquals($exp, $res);
}
function testOnlineExpression()
{
$tpl = $this->newPHPTAL('input/phptal.06.html');
$tpl->foo = '<p>hello</p>';
$res = $tpl->execute();
$exp = trim_file('output/phptal.06.html');
$this->assertEquals($exp,$res);
}
function testDirAsTemplate()
{
try {
$tpl = $this->newPHPTAL(dirname(__FILE__));
$tpl->execute();
$this->fail("Executed directory as if it was a template file");
}
catch(PHPTAL_IOException $e) {
// ok
}
catch(PHPTAL_Exception $e) {
$this->fail("Thrown exception ".get_class($e)." (".$e->getMessage().") rather than PHPTAL_IOException");
}
}
function testEncodingUppercase()
{
$tpl = $this->newPHPTAL();
$tpl->setEncoding('utf-8');
$this->assertEquals('UTF-8', $tpl->getEncoding());
}
}