-
Notifications
You must be signed in to change notification settings - Fork 1
/
TemplateTest.php
76 lines (59 loc) · 1.78 KB
/
TemplateTest.php
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
<?php
use North\Template\Template;
use PHPUnit\Framework\TestCase;
class TemplateTest extends TestCase
{
public function setUp()
{
$this->template = new Template([
'paths' => __DIR__ . '/testdata',
]);
}
public function tearDown()
{
unset($this->template);
}
public function testFiles()
{
foreach (glob(__DIR__ . '/testdata/input/*.php') as $file) {
$name = basename($file, '.php');
$output = __DIR__ . '/testdata/output/' . $name . '.php';
if (!file_exists($output)) {
continue;
}
$expected = file_get_contents($output);
ob_start();
$this->template->render($file);
$actual = trim(ob_get_clean());
$this->assertSame($expected, $actual);
}
}
public function testDotIncludeRender()
{
ob_start();
$this->template->render('partials.title.php', ['title' => 'Test']);
$output = ob_get_clean();
$this->assertContains('<h1>Test</h1>', $output);
}
public function testCustomFunctions()
{
$this->template->addFunction('up', function ($t) {
return strtoupper($t);
});
$this->assertSame('UP', $this->template->up('up'));
}
public function testFilterFunction()
{
$this->assertSame('UP', $this->template->filter('UP', 'strtolower|strtoupper'));
}
public function testFilterFunctionNotFoundException()
{
$this->expectException(Exception::class);
$this->template->filter('UP', 'strtolower|strtoupper|missing');
}
public function testTemplateNotFoundException()
{
$this->expectException(Exception::class);
$this->template->render('missing');
}
}