Skip to content

Commit 0a38948

Browse files
test(SystemTimezone): add tests for SystemTimezone model #711
1 parent 4960853 commit 0a38948

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace RESTAPI\Tests;
4+
5+
use RESTAPI\Core\TestCase;
6+
use RESTAPI\Models\SystemTimezone;
7+
8+
class APIModelsSystemTimezoneTestCase extends TestCase {
9+
/**
10+
* Checks that the system timezone is configured after updating.
11+
*/
12+
public function test_update(): void {
13+
# Create the SystemHostname model object to test with
14+
$timezone = new SystemTimezone(timezone: 'America/Denver');
15+
$timezone->update();
16+
17+
# Ensure the timezone was updated correctly
18+
$zoneinfo = file_get_contents('/var/db/zoneinfo');
19+
$this->assert_equals($zoneinfo, 'America/Denver');
20+
21+
# Update the timezone again
22+
$timezone = new SystemTimezone(timezone: 'UTC');
23+
$timezone->update();
24+
25+
# Ensure the timezone was updated correctly
26+
$zoneinfo = file_get_contents('/var/db/zoneinfo');
27+
$this->assert_equals($zoneinfo, 'UTC');
28+
}
29+
30+
/**
31+
* Checks that the get_timezone_choices method returns a valid list of timezones.
32+
*/
33+
public function test_get_timezone_choices(): void {
34+
$timezone = new SystemTimezone();
35+
$choices = $timezone->get_timezone_choices();
36+
$expected_choices = ['America/Denver', 'America/New_York', 'UTC'];
37+
38+
# Ensure the expected choices are in the list
39+
foreach ($expected_choices as $choice) {
40+
$this->assert_is_true(
41+
in_array($choice, $choices),
42+
message: "Expected timezone '$choice' not found in choices.",
43+
);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)