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');
$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;
}
}
->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';
->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.
->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
'@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
'@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,
+ ]));
}
}
*/
public function testDatetimeField() {
$field_name = $this->fieldStorage->getName();
+ $field_label = $this->field->label();
// Change the field to a datetime field.
$this->fieldStorage->setSetting('datetime_type', 'datetime');
$this->fieldStorage->save();
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[0][value][date]", '', 'Date element found.');
$this->assertFieldByName("{$field_name}[0][value][time]", '', 'Time element found.');
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found');
+ $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
$this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
*/
public function testDatelistWidget() {
$field_name = $this->fieldStorage->getName();
+ $field_label = $this->field->label();
// Ensure field is set to a date only field.
$this->fieldStorage->setSetting('datetime_type', 'date');
// Display creation form.
$this->drupalGet('entity_test/add');
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found');
+ $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
$this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
$this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Test the widget for validation notifications.
- foreach ($this->datelistDataProvider() as $data) {
+ foreach ($this->datelistDataProvider($field_label) as $data) {
list($date_value, $expected) = $data;
// Display creation form.
/**
* The data provider for testing the validation of the datelist widget.
*
+ * @param string $field_label
+ * The label of the field being tested.
+ *
* @return array
* An array of datelist input permutations to test.
*/
- protected function datelistDataProvider() {
+ protected function datelistDataProvider($field_label) {
return [
+ // Nothing selected.
+ [
+ ['year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''],
+ ["The $field_label date is required."],
+ ],
// Year only selected, validation error on Month, Day, Hour, Minute.
- [['year' => 2012, 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''], [
- 'A value must be selected for month.',
- 'A value must be selected for day.',
- 'A value must be selected for hour.',
- 'A value must be selected for minute.',
- ]],
+ [
+ ['year' => 2012, 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''],
+ [
+ "The $field_label date is incomplete.",
+ 'A value must be selected for month.',
+ 'A value must be selected for day.',
+ 'A value must be selected for hour.',
+ 'A value must be selected for minute.',
+ ],
+ ],
// Year and Month selected, validation error on Day, Hour, Minute.
- [['year' => 2012, 'month' => '12', 'day' => '', 'hour' => '', 'minute' => ''], [
- 'A value must be selected for day.',
- 'A value must be selected for hour.',
- 'A value must be selected for minute.',
- ]],
+ [
+ ['year' => 2012, 'month' => '12', 'day' => '', 'hour' => '', 'minute' => ''],
+ [
+ "The $field_label date is incomplete.",
+ 'A value must be selected for day.',
+ 'A value must be selected for hour.',
+ 'A value must be selected for minute.',
+ ],
+ ],
// Year, Month and Day selected, validation error on Hour, Minute.
- [['year' => 2012, 'month' => '12', 'day' => '31', 'hour' => '', 'minute' => ''], [
- 'A value must be selected for hour.',
- 'A value must be selected for minute.',
- ]],
+ [
+ ['year' => 2012, 'month' => '12', 'day' => '31', 'hour' => '', 'minute' => ''],
+ [
+ "The $field_label date is incomplete.",
+ 'A value must be selected for hour.',
+ 'A value must be selected for minute.',
+ ],
+ ],
// Year, Month, Day and Hour selected, validation error on Minute only.
- [['year' => 2012, 'month' => '12', 'day' => '31', 'hour' => '0', 'minute' => ''], [
- 'A value must be selected for minute.',
- ]],
+ [
+ ['year' => 2012, 'month' => '12', 'day' => '31', 'hour' => '0', 'minute' => ''],
+ [
+ "The $field_label date is incomplete.",
+ 'A value must be selected for minute.',
+ ],
+ ],
];
}
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 = [