forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-twig-number-format-filter-default.php
84 lines (71 loc) · 1.91 KB
/
test-timber-twig-number-format-filter-default.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
77
78
79
80
81
82
83
84
<?php
/**
* Replicates Twig tests from twig/twig/tests/Fixtures/filters/number_format*.test
*
* @group Timber\Number
*/
class TestTimberTwigNumberFormatFilterDefault extends Timber_UnitTestCase
{
public function set_up()
{
// Simulate fr_FR locale
global $wp_locale;
$wp_locale->number_format['decimal_point'] = ',';
$wp_locale->number_format['thousands_sep'] = ' ';
parent::set_up();
}
public function tear_down()
{
// Reset locale
$GLOBALS['wp_locale'] = new WP_Locale();
parent::tear_down();
}
public function get_context()
{
return [
'number1' => 20,
'number2' => 20.25,
'number3' => 1020.25,
];
}
public function testNumberFormat1()
{
$result = Timber\Timber::compile_string(
"{{ number1|number_format }}",
$this->get_context()
);
$this->assertEquals('20', $result);
}
public function testNumberFormat2()
{
$result = Timber\Timber::compile_string(
"{{ number2|number_format }}",
$this->get_context()
);
$this->assertEquals('20', $result);
}
public function testNumberFormat3()
{
$result = Timber\Timber::compile_string(
"{{ number2|number_format(2) }}",
$this->get_context()
);
$this->assertEquals('20,25', $result);
}
public function testNumberFormat5()
{
$result = Timber\Timber::compile_string(
"{{ number3|number_format }}",
$this->get_context()
);
$this->assertEquals('1 020', $result);
}
public function testNumberFormat6()
{
$result = Timber\Timber::compile_string(
"{{ number3|number_format(2) }}",
$this->get_context()
);
$this->assertEquals('1 020,25', $result);
}
}