forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-twig-date-filter-immutable.php
151 lines (123 loc) · 4.02 KB
/
test-timber-twig-date-filter-immutable.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Replicates Twig tests from twig/twig/tests/Fixtures/filters/date*.test
*
* @group Timber\Date
*/
class TestTimberTwigDateFilterImmutable extends Timber_UnitTestCase
{
public function set_up()
{
parent::set_up();
update_option('date_format', 'F j, Y H:i');
update_option('timezone_string', 'Europe/Paris');
/**
* We deliberately do not set a different default timezone with date_default_timezone_set()
* like they do in the Twig tests, because in a WordPress context, you shouldn’t do that.
* Instead, we set the timezone_string in the WordPress options to Europe/Paris. On the date
* that is being checked (2010-10-04), the time difference from Europe/Paris to UTC was +2
* hours.
*/
}
public function tear_down()
{
update_option('timezone_string', 'UTC');
parent::tear_down();
}
public function get_context()
{
return [
'date1' => new \DateTimeImmutable('2010-10-04 13:45'),
'date2' => new \DateTimeImmutable('2010-10-04 13:45', new \DateTimeZone('America/New_York')),
'timezone1' => new \DateTimeZone('America/New_York'),
];
}
public function testDateFormat1()
{
$result = Timber\Timber::compile_string(
"{{ date1|date }}",
$this->get_context()
);
$this->assertEquals('October 4, 2010 15:45', $result);
}
public function testDateFormat2()
{
$result = Timber\Timber::compile_string(
"{{ date1|date('d/m/Y') }}",
$this->get_context()
);
$this->assertEquals('04/10/2010', $result);
}
public function testDateFormat3()
{
$result = Timber\Timber::compile_string(
"{{ date1|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }}",
$this->get_context()
);
$this->assertEquals('04/10/2010 21:45:00', $result);
}
public function testDateFormat4()
{
$result = Timber\Timber::compile_string(
"{{ date1|date('d/m/Y H:i:s', timezone1) }}",
$this->get_context()
);
$this->assertEquals('04/10/2010 09:45:00', $result);
}
public function testDateFormat5()
{
$result = Timber\Timber::compile_string(
"{{ date1|date('d/m/Y H:i:s') }}",
$this->get_context()
);
$this->assertEquals('04/10/2010 15:45:00', $result);
}
public function testDateFormat6()
{
$result = Timber\Timber::compile_string(
"{{ date1|date_modify('+1 hour')|date('d/m/Y H:i:s') }}",
$this->get_context()
);
$this->assertEquals('04/10/2010 16:45:00', $result);
}
public function testDateFormat7()
{
$result = Timber\Timber::compile_string(
"{{ date2|date('d/m/Y H:i:s P', 'Europe/Paris') }}",
$this->get_context()
);
$this->assertEquals('04/10/2010 19:45:00 +02:00', $result);
}
public function testDateFormat8()
{
$result = Timber\Timber::compile_string(
"{{ date2|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }}",
$this->get_context()
);
$this->assertEquals('05/10/2010 01:45:00 +08:00', $result);
}
public function testDateFormat9()
{
$result = Timber\Timber::compile_string(
"{{ date2|date('d/m/Y H:i:s P', false) }}",
$this->get_context()
);
$this->assertEquals('04/10/2010 13:45:00 -04:00', $result);
}
public function testDateFormat10()
{
$result = Timber\Timber::compile_string(
"{{ date2|date('e', 'Europe/Paris') }}",
$this->get_context()
);
$this->assertEquals('Europe/Paris', $result);
}
public function testDateFormat11()
{
$result = Timber\Timber::compile_string(
"{{ date2|date('e', false) }}",
$this->get_context()
);
$this->assertEquals('America/New_York', $result);
}
}