forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-twig-filters.php
59 lines (53 loc) · 2 KB
/
test-timber-twig-filters.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
<?php
class TestTimberTermTwigFilters extends Timber_UnitTestCase
{
public function testTimberFitlerSanitize()
{
$data['title'] = "Jared's Big Adventure";
$str = Timber::compile_string('{{title|sanitize}}', $data);
$this->assertEquals('jareds-big-adventure', $str);
}
public function testTimberPreTags()
{
$data = '<pre><h1>thing</h1></pre>';
$template = '{{foo|pretags}}';
$str = Timber::compile_string($template, [
'foo' => $data,
]);
$this->assertEquals('<pre><h1>thing</h1></pre>', $str);
}
public function testTimberFilterString()
{
$data['arr'] = ['foo', 'foo'];
$str = Timber::compile_string('{{arr|join(" ")}}', $data);
$this->assertEquals('foo foo', trim($str));
$data['arr'] = ['bar'];
$str = Timber::compile_string('{{arr|join}}', $data);
$this->assertEquals('bar', trim($str));
$data['arr'] = ['foo', 'bar'];
$str = Timber::compile_string('{{arr|join(", ")}}', $data);
$this->assertEquals('foo, bar', trim($str));
$data['arr'] = 6;
$str = Timber::compile_string('{{arr}}', $data);
$this->assertEquals('6', trim($str));
}
public function testTimberFormatBytes()
{
$str1 = Timber::compile_string('{{ 1200|size_format }}');
$str2 = Timber::compile_string('{{ 1500|size_format(2) }}');
$this->assertSame('1 KB', $str1);
$this->assertSame('1.46 KB', $str2);
}
public function testTwigFilterList()
{
$data['authors'] = ['Tom', 'Rick', 'Harry', 'Mike'];
$str = Timber::compile_string("{{authors|list}}", $data);
$this->assertEquals('Tom, Rick, Harry and Mike', $str);
}
public function testTwigFilterListOxford()
{
$data['authors'] = ['Tom', 'Rick', 'Harry', 'Mike'];
$str = Timber::compile_string("{{authors|list(',', ', and')}}", $data);
$this->assertEquals('Tom, Rick, Harry, and Mike', $str);
}
}