TimezoneTest.php in Drupal 10
File
core/modules/system/tests/src/Kernel/Timezone/TimezoneTest.php
View source
<?php
namespace Drupal\Tests\system\Kernel\Timezone;
use Drupal\KernelTests\KernelTestBase;
class TimezoneTest extends KernelTestBase {
protected static $modules = [
'system',
];
public function testSystemTimeZones() {
$result = system_time_zones();
$this
->assertIsArray($result);
$this
->assertArrayHasKey('Africa/Dar_es_Salaam', $result);
$this
->assertEquals('Africa/Dar es Salaam', $result['Africa/Dar_es_Salaam']);
$result = system_time_zones(NULL, TRUE);
$this
->assertIsArray($result);
$this
->assertArrayHasKey('Africa', $result);
$this
->assertArrayHasKey('Africa/Dar_es_Salaam', $result['Africa']);
$this
->assertEquals('Dar es Salaam', $result['Africa']['Africa/Dar_es_Salaam']);
$this
->assertArrayHasKey('America', $result);
$this
->assertArrayHasKey('America/Indiana/Indianapolis', $result['America']);
$this
->assertEquals('Indianapolis (Indiana)', $result['America']['America/Indiana/Indianapolis']);
$this
->assertArrayNotHasKey('America/Indiana', $result['America']);
$this
->assertArrayNotHasKey('America/Indianapolis', $result['America']);
$this
->assertArrayNotHasKey('America/Indiana/Indianapolis', $result);
$ungrouped_count = count(system_time_zones());
$grouped_result = system_time_zones(NULL, TRUE);
$grouped_count = 0;
array_walk_recursive($grouped_result, function () use (&$grouped_count) {
$grouped_count++;
});
$this
->assertEquals($ungrouped_count, $grouped_count);
}
}