function TimezoneTest::assertDateTimezonePropertyProcessed
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php \Drupal\KernelTests\Core\Datetime\Element\TimezoneTest::assertDateTimezonePropertyProcessed()
- 8.9.x core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php \Drupal\KernelTests\Core\Datetime\Element\TimezoneTest::assertDateTimezonePropertyProcessed()
- 10 core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php \Drupal\KernelTests\Core\Datetime\Element\TimezoneTest::assertDateTimezonePropertyProcessed()
Asserts that elements set #date_timezone correctly.
@internal
Parameters
string $elementType: The element type to test.
Throws
\Exception
2 calls to TimezoneTest::assertDateTimezonePropertyProcessed()
- TimezoneTest::testDatelistTimezonePropertyProcessed in core/
tests/ Drupal/ KernelTests/ Core/ Datetime/ Element/ TimezoneTest.php - On datelist elements test #date_timezone after ::processDatetime.
- TimezoneTest::testDatetimeTimezonePropertyProcessed in core/
tests/ Drupal/ KernelTests/ Core/ Datetime/ Element/ TimezoneTest.php - On datetime elements test #date_timezone after ::processDatetime.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Datetime/ Element/ TimezoneTest.php, line 336
Class
- TimezoneTest
- Tests the timezone handling of datetime and datelist element types.
Namespace
Drupal\KernelTests\Core\Datetime\ElementCode
public function assertDateTimezonePropertyProcessed(string $elementType) : void {
$this->elementType = $elementType;
// Simulate form being loaded and default values displayed to user.
$form_state = new FormState();
$form_builder = $this->container
->get('form_builder');
$this->setupForm($form_state, $form_builder);
// Check the #date_timezone property on each processed test element.
$wrongTimezones = [];
foreach ($form_state->getCompleteForm() as $elementName => $element) {
if (isset($element['#type']) && $element['#type'] === $this->elementType) {
// Check the correct timezone is set on the value object.
$actualTimezone = array_search($element['#date_timezone'], $this->timezones, TRUE);
if ($element['#test_expect_timezone'] !== $actualTimezone) {
$wrongTimezones[$element['#title']] = [
$element['#test_expect_timezone'],
$actualTimezone,
];
}
}
$this->assertEquals($this->timezones['user'], date_default_timezone_get(), 'Subsequent tests assume specific value for date_default_timezone_get().');
$message = "The correct timezone should be set on the processed {$this->elementType} elements: (expected, actual) \n" . print_r($wrongTimezones, TRUE);
$this->assertCount(0, $wrongTimezones, $message);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.