diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index 47e9892..ccfa66a 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -28,6 +28,11 @@ class DateTimeFieldTest extends WebTestBase { public static $modules = array('node', 'entity_test', 'datetime', 'field_ui'); /** + * The default display settings to use for the formatters. + */ + protected $defaultSettings; + + /** * An array of display options to pass to entity_get_display() * * @var array @@ -91,10 +96,14 @@ protected function setUp() { )) ->save(); + $this->defaultSettings = array( + 'timezone_override' => '', + ); + $this->displayOptions = array( 'type' => 'datetime_default', 'label' => 'hidden', - 'settings' => array('format_type' => 'medium'), + 'settings' => array('format_type' => 'medium') + $this->defaultSettings, ); entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) @@ -137,7 +146,6 @@ function testDateField() { $this->assertRaw($date->format($date_format)); $this->assertNoRaw($date->format($time_format)); - // Verify that the date is output according to the formatter settings. $options = array( 'format_type' => array('short', 'medium', 'long'), @@ -145,7 +153,7 @@ function testDateField() { foreach ($options as $setting => $values) { foreach ($values as $new_value) { // Update the entity display settings. - $this->displayOptions['settings'] = array($setting => $new_value); + $this->displayOptions['settings'] = array($setting => $new_value) + $this->defaultSettings; entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) ->save(); @@ -164,7 +172,7 @@ function testDateField() { // Verify that the plain formatter works. $this->displayOptions['type'] = 'datetime_plain'; - $this->displayOptions['settings'] = array(); + $this->displayOptions['settings'] = $this->defaultSettings; entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) ->save(); @@ -174,7 +182,7 @@ function testDateField() { // Verify that the 'datetime_custom' formatter works. $this->displayOptions['type'] = 'datetime_custom'; - $this->displayOptions['settings'] = array('date_format' => 'm/d/Y'); + $this->displayOptions['settings'] = array('date_format' => 'm/d/Y') + $this->defaultSettings; entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) ->save(); @@ -268,7 +276,7 @@ function testDatetimeField() { foreach ($options as $setting => $values) { foreach ($values as $new_value) { // Update the entity display settings. - $this->displayOptions['settings'] = array($setting => $new_value); + $this->displayOptions['settings'] = array($setting => $new_value) + $this->defaultSettings; entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) ->save(); @@ -287,7 +295,7 @@ function testDatetimeField() { // Verify that the plain formatter works. $this->displayOptions['type'] = 'datetime_plain'; - $this->displayOptions['settings'] = array(); + $this->displayOptions['settings'] = $this->defaultSettings; entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) ->save(); @@ -297,7 +305,7 @@ function testDatetimeField() { // Verify that the 'datetime_custom' formatter works. $this->displayOptions['type'] = 'datetime_custom'; - $this->displayOptions['settings'] = array('date_format' => 'm/d/Y g:i:s A'); + $this->displayOptions['settings'] = array('date_format' => 'm/d/Y g:i:s A') + $this->defaultSettings; entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) ->save(); @@ -305,6 +313,16 @@ function testDatetimeField() { $this->renderTestEntity($id); $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', array('%expected' => $expected))); + // Verify that the 'timezone_override' setting works. + $this->displayOptions['type'] = 'datetime_custom'; + $this->displayOptions['settings'] = array('date_format' => 'm/d/Y g:i:s A', 'timezone_override' => 'America/New_York') + $this->defaultSettings; + entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') + ->setComponent($field_name, $this->displayOptions) + ->save(); + $expected = $date->format($this->displayOptions['settings']['date_format'], array('timezone' => 'America/New_York')); + $this->renderTestEntity($id); + $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', array('%expected' => $expected))); + // Verify that the 'datetime_time_ago' formatter works for intervals in the // past. First update the test entity so that the date difference always // has the same interval. Since the database always stores UTC, and the