12
12
namespace CodeIgniter \Helpers ;
13
13
14
14
use CodeIgniter \Test \CIUnitTestCase ;
15
+ use DateTimeZone ;
15
16
16
17
/**
17
18
* @internal
@@ -34,4 +35,55 @@ public function testNowSpecific()
34
35
// Chicago should be two hours ahead of Vancouver
35
36
$ this ->assertCloseEnough (7200 , now ('America/Chicago ' ) - now ('America/Vancouver ' ));
36
37
}
38
+
39
+ public function testTimezoneSelectDefault ()
40
+ {
41
+ $ timezones = DateTimeZone::listIdentifiers (DateTimeZone::ALL , null );
42
+
43
+ $ expected = "<select name='timezone' class='custom-select'> " . PHP_EOL ;
44
+
45
+ foreach ($ timezones as $ timezone ) {
46
+ $ selected = ($ timezone === 'Asia/Jakarta ' ) ? 'selected ' : '' ;
47
+ $ expected .= "<option value=' {$ timezone }' {$ selected }> {$ timezone }</option> " . PHP_EOL ;
48
+ }
49
+
50
+ $ expected .= ('</select> ' . PHP_EOL );
51
+
52
+ $ this ->assertSame ($ expected , timezone_select ('custom-select ' , 'Asia/Jakarta ' ));
53
+ }
54
+
55
+ public function testTimezoneSelectSpecific ()
56
+ {
57
+ $ spesificRegion = DateTimeZone::ASIA ;
58
+ $ timezones = DateTimeZone::listIdentifiers ($ spesificRegion , null );
59
+
60
+ $ expected = "<select name='timezone' class='custom-select'> " . PHP_EOL ;
61
+
62
+ foreach ($ timezones as $ timezone ) {
63
+ $ selected = ($ timezone === 'Asia/Jakarta ' ) ? 'selected ' : '' ;
64
+ $ expected .= "<option value=' {$ timezone }' {$ selected }> {$ timezone }</option> " . PHP_EOL ;
65
+ }
66
+
67
+ $ expected .= ('</select> ' . PHP_EOL );
68
+
69
+ $ this ->assertSame ($ expected , timezone_select ('custom-select ' , 'Asia/Jakarta ' , $ spesificRegion ));
70
+ }
71
+
72
+ public function testTimezoneSelectSingle ()
73
+ {
74
+ $ spesificRegion = DateTimeZone::PER_COUNTRY ;
75
+ $ country = 'ID ' ;
76
+ $ timezones = DateTimeZone::listIdentifiers ($ spesificRegion , $ country );
77
+
78
+ $ expected = "<select name='timezone' class='custom-select'> " . PHP_EOL ;
79
+
80
+ foreach ($ timezones as $ timezone ) {
81
+ $ selected = ($ timezone === 'Asia/Jakarta ' ) ? 'selected ' : '' ;
82
+ $ expected .= "<option value=' {$ timezone }' {$ selected }> {$ timezone }</option> " . PHP_EOL ;
83
+ }
84
+
85
+ $ expected .= ('</select> ' . PHP_EOL );
86
+
87
+ $ this ->assertSame ($ expected , timezone_select ('custom-select ' , 'Asia/Jakarta ' , $ spesificRegion , $ country ));
88
+ }
37
89
}
0 commit comments