Skip to content

Commit dad57b0

Browse files
committed
Add tests for some smarty functions
1 parent 0e9a1af commit dad57b0

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

tests/include/functionsSmartyTest.php

+83-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<?php
22

3+
# Requires ext_intl and pdo_sqlite3 to be activate
4+
35
$serendipity['dbType'] = 'pdo-sqlite';
4-
//@define('LANG_CHARSET', 'UTF-8');
56
@define('S9Y_PEAR_PATH', dirname(__FILE__) . '/../../bundled-libs/');
7+
@define('S9Y_INCLUDE_PATH', dirname(__FILE__) . '/../../');
68
@define('PATH_SMARTY_COMPILE', dirname(__FILE__) . '/../../templates_c/');
79
@define('IN_serendipity', true);
810
@define('IS_installed', false);
11+
@define('serendipity_LANG_LOADED', false);
912

13+
require_once(dirname(__FILE__) . '/../../bundled-libs/autoload.php');
1014
require_once dirname(__FILE__) . '/../../lang/UTF-8/serendipity_lang_en.inc.php';
15+
require_once dirname(__FILE__) . '/../../include/compat.inc.php';
16+
require_once dirname(__FILE__) . '/../../include/lang.inc.php';
1117
require_once dirname(__FILE__) . '/../../include/functions_smarty.inc.php';
1218

1319
use PHPUnit\Framework\Attributes\Test;
@@ -63,5 +69,81 @@ public function test_smarty_renders()
6369
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
6470
$this->assertEquals('display value here', $result);
6571
}
72+
73+
#[Test]
74+
public function test_smarty_renders_makeFilename()
75+
{
76+
global $serendipity;
77+
78+
serendipity_smarty_init();
79+
80+
@define('PAT_FILENAME', '/');
81+
82+
$serendipity['smarty']->assign('comment', 'value');
83+
$template_string = '{$comment|@makeFilename} {"blank"|@xhtml_target}';
84+
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
85+
$this->assertNotNull($result);
86+
}
87+
88+
#[Test]
89+
public function test_smarty_renders_xhtml_target()
90+
{
91+
global $serendipity;
92+
93+
serendipity_smarty_init();
94+
95+
$serendipity['smarty']->assign('comment', 'value');
96+
$template_string = '{ {"blank"|@xhtml_target}';
97+
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
98+
$this->assertNotNull($result);
99+
}
100+
101+
#[Test]
102+
public function test_smarty_renders_empty_prefix()
103+
{
104+
global $serendipity;
105+
106+
serendipity_smarty_init();
107+
108+
$template_string = '{"test"|@emptyPrefix}';
109+
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
110+
$this->assertEquals(': test', $result);
111+
}
112+
113+
#[Test]
114+
public function test_smarty_renders_formatTime()
115+
{
116+
global $serendipity;
117+
118+
serendipity_smarty_init();
119+
120+
$template_string = '{946684800|@formatTime:\'%b %e. %Y\'}';
121+
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
122+
$this->assertEquals('Jan 1. 2000', $result);
123+
}
124+
125+
#[Test]
126+
public function test_smarty_renders_utf8_encode()
127+
{
128+
global $serendipity;
129+
130+
serendipity_smarty_init();
131+
132+
$template_string = '{"test"|@serendipity_utf8_encode}';
133+
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
134+
$this->assertEquals('test', $result);
135+
}
136+
137+
#[Test]
138+
public function test_smarty_renders_ifRemember()
139+
{
140+
global $serendipity;
141+
142+
serendipity_smarty_init();
143+
144+
$template_string = '{"test"|@ifRemember:no}';
145+
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
146+
$this->assertEquals(false, $result);
147+
}
66148

67149
}

0 commit comments

Comments
 (0)