X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fdatetime%2Ftests%2Fsrc%2FFunctional%2FDateTimeFieldTest.php;fp=web%2Fcore%2Fmodules%2Fdatetime%2Ftests%2Fsrc%2FFunctional%2FDateTimeFieldTest.php;h=f4606d49686c10397499012d2599b8b2e90e7185;hp=ab03ff5772fe2af7a4c60906b4985b30a0d71ada;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/web/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php index ab03ff577..f4606d496 100644 --- a/web/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php +++ b/web/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 = ''; - $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 = '' . $date->format('m/d/Y') . '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, + ])); } } @@ -208,6 +229,7 @@ class DateTimeFieldTest extends DateTestBase { */ 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(); @@ -216,7 +238,7 @@ class DateTimeFieldTest extends DateTestBase { $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'); @@ -352,6 +374,7 @@ class DateTimeFieldTest extends DateTestBase { */ 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'); @@ -370,7 +393,7 @@ class DateTimeFieldTest extends DateTestBase { // 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'); @@ -511,7 +534,7 @@ class DateTimeFieldTest extends DateTestBase { \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. @@ -562,33 +585,57 @@ class DateTimeFieldTest extends DateTestBase { /** * 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.', + ], + ], ]; } @@ -620,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 = [