3 namespace Drupal\Tests\system\Kernel\Timezone;
5 use Drupal\KernelTests\KernelTestBase;
8 * Test coverage for time zone handling.
12 class TimezoneTest extends KernelTestBase {
14 public static $modules = ['system'];
17 * Tests system_time_zones().
19 public function testSystemTimeZones() {
20 // Test the default parameters for system_time_zones().
21 $result = system_time_zones();
22 $this->assertInternalType('array', $result);
23 $this->assertArrayHasKey('Africa/Dar_es_Salaam', $result);
24 $this->assertEquals('Africa/Dar es Salaam', $result['Africa/Dar_es_Salaam']);
26 // Tests time zone grouping.
27 $result = system_time_zones(NULL, TRUE);
29 // Check a two-level time zone.
30 $this->assertInternalType('array', $result);
31 $this->assertArrayHasKey('Africa', $result);
32 $this->assertArrayHasKey('Africa/Dar_es_Salaam', $result['Africa']);
33 $this->assertEquals('Dar es Salaam', $result['Africa']['Africa/Dar_es_Salaam']);
35 // Check a three level time zone.
36 $this->assertArrayHasKey('America', $result);
37 $this->assertArrayHasKey('America/Indiana/Indianapolis', $result['America']);
38 $this->assertEquals('Indianapolis (Indiana)', $result['America']['America/Indiana/Indianapolis']);
40 // Make sure grouping hasn't erroneously created an entry with just the
41 // first and second levels.
42 $this->assertArrayNotHasKey('America/Indiana', $result['America']);
44 // Make sure grouping hasn't duplicated an entry with just the first and
46 $this->assertArrayNotHasKey('America/Indianapolis', $result['America']);
48 // Make sure that a grouped item isn't duplicated at the top level of the
50 $this->assertArrayNotHasKey('America/Indiana/Indianapolis', $result);
52 // Test that the ungrouped and grouped results have the same number of
54 $ungrouped_count = count(system_time_zones());
55 $grouped_result = system_time_zones(NULL, TRUE);
57 array_walk_recursive($grouped_result, function () use
61 $this->assertEquals($ungrouped_count, $grouped_count);