function TimeZoneFormHelperTest::testGetGroupedList

Same name and namespace in other branches
  1. 11.x 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 \Drupal\Core\Datetime\TimeZoneFormHelper[[api-linebreak]] @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.