summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2017-09-16 12:24:40 (GMT)
committerxjm2017-09-16 12:24:40 (GMT)
commit5ee33d6341fc953ef5fb80d9e463f2b3b9f30171 (patch)
tree1dff9f84e3f426e6eeb3e4f1a8306f128de4a487
parentfdf6bf90f37a7efd7661538dede28342a2257115 (diff)
Issue #2829845 by mpdonadio, Jo Fitzgerald, xjm, jhedstrom: Record timezone in DateTime test assertions and verbose output
-rw-r--r--core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php34
-rw-r--r--core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php37
2 files changed, 56 insertions, 15 deletions
diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
index 5412990..f4606d4 100644
--- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
+++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
@@ -44,6 +44,7 @@ class DateTimeFieldTest extends DateTestBase {
foreach (static::$timezones as $timezone) {
$this->setSiteTimezone($timezone);
+ $this->assertEquals($timezone, $this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);
// Display creation form.
$this->drupalGet('entity_test/add');
@@ -117,7 +118,12 @@ class DateTimeFieldTest extends DateTestBase {
$expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE);
$output = $this->renderTestEntity($id);
$expected_markup = '<time datetime="' . $expected_iso . '" class="datetime">' . $expected . '</time>';
- $this->assertContains($expected_markup, $output, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso]));
+ $this->assertContains($expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
+ '%value' => $new_value,
+ '%expected' => $expected,
+ '%expected_iso' => $expected_iso,
+ '%timezone' => $timezone,
+ ]));
break;
}
}
@@ -131,7 +137,10 @@ class DateTimeFieldTest extends DateTestBase {
->save();
$expected = $date->format(DATETIME_DATE_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
// Verify that the 'datetime_custom' formatter works.
$this->displayOptions['type'] = 'datetime_custom';
@@ -141,7 +150,10 @@ class DateTimeFieldTest extends DateTestBase {
->save();
$expected = $date->format($this->displayOptions['settings']['date_format']);
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
// Test that allowed markup in custom format is preserved and XSS is
// removed.
@@ -151,7 +163,10 @@ class DateTimeFieldTest extends DateTestBase {
->save();
$expected = '<strong>' . $date->format('m/d/Y') . '</strong>alert(String.fromCharCode(88,83,83))';
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
// Verify that the 'datetime_time_ago' formatter works for intervals in the
// past. First update the test entity so that the date difference always
@@ -178,7 +193,10 @@ class DateTimeFieldTest extends DateTestBase {
'@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']])
]);
$output = $this->renderTestEntity($id);
- $this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
// Verify that the 'datetime_time_ago' formatter works for intervals in the
// future. First update the test entity so that the date difference always
@@ -199,7 +217,10 @@ class DateTimeFieldTest extends DateTestBase {
'@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']])
]);
$output = $this->renderTestEntity($id);
- $this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
}
}
@@ -646,6 +667,7 @@ class DateTimeFieldTest extends DateTestBase {
foreach (static::$timezones as $timezone) {
$this->setSiteTimezone($timezone);
+ $this->assertEquals($timezone, $this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);
// Set now as default_value.
$field_edit = [
diff --git a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
index e7f0fbb..50f61ee 100644
--- a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
+++ b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
@@ -53,6 +53,7 @@ class DateRangeFieldTest extends DateTestBase {
foreach (static::$timezones as $timezone) {
$this->setSiteTimezone($timezone);
+ $this->assertEquals($timezone, $this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);
// Ensure field is set to a date-only field.
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATE);
@@ -134,15 +135,17 @@ class DateRangeFieldTest extends DateTestBase {
$end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE);
$end_expected_markup = '<time datetime="' . $end_expected_iso . '" class="datetime">' . $end_expected . '</time>';
$output = $this->renderTestEntity($id);
- $this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [
+ $this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
'%value' => 'long',
'%expected' => $start_expected,
'%expected_iso' => $start_expected_iso,
+ '%timezone' => $timezone,
]));
- $this->assertContains($end_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [
+ $this->assertContains($end_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
'%value' => 'long',
'%expected' => $end_expected,
'%expected_iso' => $end_expected_iso,
+ '%timezone' => $timezone,
]));
$this->assertContains(' THESEPARATOR ', $output, 'Found proper separator');
@@ -159,7 +162,10 @@ class DateRangeFieldTest extends DateTestBase {
->save();
$expected = $start_date->format(DATETIME_DATE_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATE_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
// Verify that the custom formatter works.
$this->displayOptions['type'] = 'daterange_custom';
@@ -169,7 +175,10 @@ class DateRangeFieldTest extends DateTestBase {
->save();
$expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']);
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
// Test that allowed markup in custom format is preserved and XSS is
// removed.
@@ -179,7 +188,10 @@ class DateRangeFieldTest extends DateTestBase {
->save();
$expected = '<strong>' . $start_date->format('m/d/Y') . '</strong>alert(String.fromCharCode(88,83,83)) - <strong>' . $end_date->format('m/d/Y') . '</strong>alert(String.fromCharCode(88,83,83))';
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
// Test formatters when start date and end date are the same
$this->drupalGet('entity_test/add');
@@ -218,12 +230,13 @@ class DateRangeFieldTest extends DateTestBase {
$start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE);
$start_expected_markup = '<time datetime="' . $start_expected_iso . '" class="datetime">' . $start_expected . '</time>';
$output = $this->renderTestEntity($id);
- $this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [
+ $this->assertContains($start_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
'%value' => 'long',
'%expected' => $start_expected,
'%expected_iso' => $start_expected_iso,
+ '%timezone' => $timezone,
]));
- $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page');
+ $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page in ' . $timezone);
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
@@ -237,7 +250,10 @@ class DateRangeFieldTest extends DateTestBase {
->save();
$expected = $start_date->format(DATETIME_DATE_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
$this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page');
$this->displayOptions['type'] = 'daterange_custom';
@@ -247,7 +263,10 @@ class DateRangeFieldTest extends DateTestBase {
->save();
$expected = $start_date->format($this->displayOptions['settings']['date_format']);
$output = $this->renderTestEntity($id);
- $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected]));
+ $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
+ '%expected' => $expected,
+ '%timezone' => $timezone,
+ ]));
$this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page');
}
}