class TimeZoneAbbreviationRouteTest
Same name in this branch
- main core/modules/system/tests/src/Functional/Datetime/TimeZoneAbbreviationRouteTest.php \Drupal\Tests\system\Functional\Datetime\TimeZoneAbbreviationRouteTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Datetime/TimeZoneAbbreviationRouteTest.php \Drupal\Tests\system\Functional\Datetime\TimeZoneAbbreviationRouteTest
- 10 core/modules/system/tests/src/Functional/Datetime/TimeZoneAbbreviationRouteTest.php \Drupal\Tests\system\Functional\Datetime\TimeZoneAbbreviationRouteTest
- 9 core/modules/system/tests/src/Functional/Datetime/TimeZoneAbbreviationRouteTest.php \Drupal\Tests\system\Functional\Datetime\TimeZoneAbbreviationRouteTest
- 11.x core/modules/system/tests/src/Kernel/Datetime/TimeZoneAbbreviationRouteTest.php \Drupal\Tests\system\Kernel\Datetime\TimeZoneAbbreviationRouteTest
Tests converting JavaScript time zone abbreviations to time zone identifiers.
Attributes
#[Group('Datetime')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Kernel\Datetime\TimeZoneAbbreviationRouteTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of TimeZoneAbbreviationRouteTest
File
-
core/
modules/ system/ tests/ src/ Kernel/ Datetime/ TimeZoneAbbreviationRouteTest.php, line 16
Namespace
Drupal\Tests\system\Kernel\DatetimeView source
class TimeZoneAbbreviationRouteTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
];
/**
* Test that the AJAX Timezone Callback can deal with various formats.
*/
public function testSystemTimezone() : void {
$options = [
'query' => [
'date' => 'Tue+Sep+17+2013+21%3A35%3A31+GMT%2B0100+(BST)#',
],
];
// Query the AJAX Timezone Callback with a long-format date.
$response = $this->drupalGet('system/timezone/BST/3600/1', $options);
$this->assertEquals($response, '"Europe\\/London"');
}
/**
* Test the AJAX Timezone Callback with invalid inputs.
*
* @param string $path
* Path to call.
* @param string|null $expectedResponse
* Expected response, or NULL if expecting error.
* @param bool $expectInvalidRequest
* Whether to expect the request is invalid.
*/
public function testAbbreviationConversion(string $path, ?string $expectedResponse = NULL, bool $expectInvalidRequest = FALSE) : void {
$response = $this->drupalGet('system/timezone/' . $path);
if (isset($expectedResponse)) {
$this->assertEquals($response, $expectedResponse);
}
$this->assertSession()
->statusCodeEquals($expectInvalidRequest ? 404 : 200);
}
/**
* Provides test data for testGet().
*
* @return array
* Test scenarios.
*/
public static function providerAbbreviationConversion() : array {
return [
'valid, default offset' => [
'CST/0/0',
'"America\\/Chicago"',
],
// This should be the same TZID as default value.
'valid, default, explicit' => [
'CST/-1/0',
'"America\\/Chicago"',
],
// Same abbreviation but different offset.
'valid, default, alternative offset' => [
'CST/28800/0',
'"Asia\\/Chongqing"',
],
// Using '0' as offset will get the best matching time zone for an offset.
'valid, no abbreviation, offset, no DST' => [
'0/3600/0',
'"Europe\\/Paris"',
],
'valid, no abbreviation, offset, with DST' => [
'0/3600/1',
'"Europe\\/London"',
],
'invalid, unknown abbreviation' => [
'foo/0/0',
NULL,
FALSE,
],
'invalid abbreviation, out of range (short)' => [
'A',
NULL,
TRUE,
],
'invalid abbreviation, out of range (long)' => [
'ABCDEFGHIJK',
NULL,
TRUE,
],
'invalid offset, non integer' => [
'CST/foo',
NULL,
TRUE,
],
'invalid offset, out of range (lower)' => [
'CST/-100000',
'false',
],
'invalid offset, out of range (higher)' => [
'CST/100000',
'false',
],
'invalid DST value' => [
'CST/3600/blah',
NULL,
TRUE,
],
'invalid DST value, out of range (lower)' => [
'CST/3600/-2',
NULL,
TRUE,
],
'invalid DST value, out of range (higher)' => [
'CST/3600/2',
NULL,
TRUE,
],
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.