class TimeZoneFormHelperTest
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/Datetime/TimeZoneFormHelperTest.php \Drupal\Tests\Core\Datetime\TimeZoneFormHelperTest
@coversDefaultClass \Drupal\Core\Datetime\TimeZoneFormHelper @group Datetime
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Datetime\TimeZoneFormHelperTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of TimeZoneFormHelperTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Datetime/ TimeZoneFormHelperTest.php, line 15
Namespace
Drupal\Tests\Core\DatetimeView source
class TimeZoneFormHelperTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$container = new ContainerBuilder();
$container->set('string_translation', $this->getStringTranslationStub());
\Drupal::setContainer($container);
}
/**
* @covers ::getOptionsList
* @covers ::getOptionsListByRegion
*/
public function testGetList() : void {
// Test the default parameters for getOptionsList().
$result = TimeZoneFormHelper::getOptionsList();
$this->assertIsArray($result);
$this->assertArrayHasKey('Africa/Dar_es_Salaam', $result);
$this->assertEquals('Africa/Dar es Salaam', $result['Africa/Dar_es_Salaam']);
// Test that the ungrouped and grouped results have the same number of
// items.
$ungrouped_count = count(TimeZoneFormHelper::getOptionsList());
$grouped_result = TimeZoneFormHelper::getOptionsListByRegion();
$grouped_count = 0;
array_walk_recursive($grouped_result, function () use (&$grouped_count) {
$grouped_count++;
});
$this->assertEquals($ungrouped_count, $grouped_count);
}
/**
* @covers ::getOptionsListByRegion
*/
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);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
TimeZoneFormHelperTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
TimeZoneFormHelperTest::testGetGroupedList | public | function | @covers ::getOptionsListByRegion | |
TimeZoneFormHelperTest::testGetList | public | function | @covers ::getOptionsList @covers ::getOptionsListByRegion |
|
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.