Skip to content

Commit 0e9a1af

Browse files
committed
Init smarty test
1 parent 0819ff9 commit 0e9a1af

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

tests/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
phpunit.phar
2+
.phpunit.cache/

tests/include/functionsSmartyTest.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
$serendipity['dbType'] = 'pdo-sqlite';
4+
//@define('LANG_CHARSET', 'UTF-8');
5+
@define('S9Y_PEAR_PATH', dirname(__FILE__) . '/../../bundled-libs/');
6+
@define('PATH_SMARTY_COMPILE', dirname(__FILE__) . '/../../templates_c/');
7+
@define('IN_serendipity', true);
8+
@define('IS_installed', false);
9+
10+
require_once dirname(__FILE__) . '/../../lang/UTF-8/serendipity_lang_en.inc.php';
11+
require_once dirname(__FILE__) . '/../../include/functions_smarty.inc.php';
12+
13+
use PHPUnit\Framework\Attributes\Test;
14+
15+
class functionsSmartyTest extends PHPUnit\Framework\TestCase
16+
{
17+
18+
protected function setUp(): void {
19+
global $serendipity;
20+
21+
# We need a test database for 2k11's option table
22+
$serendipity['dbConn'] = new PDO('sqlite::memory:');
23+
$sql = "CREATE TABLE IF NOT EXISTS options (
24+
name varchar(255) not null,
25+
value text not null,
26+
okey varchar(64) not null default '',
27+
Primary Key (name, okey)
28+
);";
29+
$serendipity['dbConn']->prepare($sql)->execute();
30+
$sql = "CREATE TABLE IF NOT EXISTS plugins (
31+
name varchar(128) not null,
32+
placement varchar(6) not null default 'right',
33+
sort_order int(4) not null default '0',
34+
authorid int(11) default '0',
35+
path varchar(255) default null,
36+
PRIMARY KEY(name)
37+
);";
38+
$serendipity['dbConn']->prepare($sql)->execute();
39+
40+
$serendipity['core_events'] = [];
41+
}
42+
43+
#[Test]
44+
public function test_smarty_inits()
45+
{
46+
global $serendipity;
47+
48+
$success = serendipity_smarty_init();
49+
50+
$this->assertEquals(true, $success);
51+
$this->assertNotNull($serendipity['smarty']);
52+
}
53+
54+
#[Test]
55+
public function test_smarty_renders()
56+
{
57+
global $serendipity;
58+
59+
serendipity_smarty_init();
60+
61+
$serendipity['smarty']->assign('foo', 'value');
62+
$template_string = 'display {$foo} here';
63+
$result = $serendipity['smarty']->fetch('eval:' . $template_string);
64+
$this->assertEquals('display value here', $result);
65+
}
66+
67+
}

0 commit comments

Comments
 (0)