1212namespace CodeIgniter \Helpers ;
1313
1414use CodeIgniter \Test \CIUnitTestCase ;
15+ use DateTimeZone ;
1516
1617/**
1718 * @internal
@@ -34,4 +35,55 @@ public function testNowSpecific()
3435 // Chicago should be two hours ahead of Vancouver
3536 $ this ->assertCloseEnough (7200 , now ('America/Chicago ' ) - now ('America/Vancouver ' ));
3637 }
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+ }
3789}
0 commit comments