function TimeZoneFormHelperTest::testGetGroupedList

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Datetime/TimeZoneFormHelperTest.php \Drupal\Tests\Core\Datetime\TimeZoneFormHelperTest::testGetGroupedList()

@covers ::getOptionsListByRegion

File

core/tests/Drupal/Tests/Core/Datetime/TimeZoneFormHelperTest.php, line 53

Class

TimeZoneFormHelperTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Datetime%21TimeZoneFormHelper.php/class/TimeZoneFormHelper/11.x" title="Helper class for dealing with timezones." class="local">\Drupal\Core\Datetime\TimeZoneFormHelper</a> @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testGetGroupedList() : void {
    // Tests time zone grouping.
    $result = TimeZoneFormHelper::getOptionsListByRegion();
    // Check a two-level time zone.
    $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']);
    // Check a three level time zone.
    $this->assertArrayHasKey('America', $result);
    $this->assertArrayHasKey('America/Indiana/Indianapolis', $result['America']);
    $this->assertEquals('Indianapolis (Indiana)', $result['America']['America/Indiana/Indianapolis']);
    // Make sure grouping hasn't erroneously created an entry with just the
    // first and second levels.
    $this->assertArrayNotHasKey('America/Indiana', $result['America']);
    // Make sure grouping hasn't duplicated an entry with just the first and
    // third levels.
    $this->assertArrayNotHasKey('America/Indianapolis', $result['America']);
    // Make sure that a grouped item isn't duplicated at the top level of the
    // results array.
    $this->assertArrayNotHasKey('America/Indiana/Indianapolis', $result);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.