diff --git a/core/modules/datetime/src/Tests/DateTestBase.php b/core/modules/datetime/src/Tests/DateTestBase.php index 81e7550..a234ae0 100644 --- a/core/modules/datetime/src/Tests/DateTestBase.php +++ b/core/modules/datetime/src/Tests/DateTestBase.php @@ -2,6 +2,8 @@ namespace Drupal\datetime\Tests; +@trigger_error('\Drupal\datetime\Tests\DateTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\BrowserTestBase instead. See https://www.drupal.org/node/2780063.', E_USER_DEPRECATED); + use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay; @@ -13,6 +15,9 @@ /** * Provides a base class for testing Datetime field functionality. + * + * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. + * Use \Drupal\Tests\BrowserTestBase instead. */ abstract class DateTestBase extends WebTestBase { diff --git a/core/modules/datetime/src/Tests/DateTestBase.php b/core/modules/datetime/tests/src/Functional/DateTestBase.php similarity index 94% copy from core/modules/datetime/src/Tests/DateTestBase.php copy to core/modules/datetime/tests/src/Functional/DateTestBase.php index 81e7550..369e793 100644 --- a/core/modules/datetime/src/Tests/DateTestBase.php +++ b/core/modules/datetime/tests/src/Functional/DateTestBase.php @@ -1,6 +1,6 @@ build($entity); - $output = $this->container->get('renderer')->renderRoot($build); - $this->setRawContent($output); - $this->verbose($output); + return (string) $this->container->get('renderer')->renderRoot($build); } /** diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php similarity index 90% rename from core/modules/datetime/src/Tests/DateTimeFieldTest.php rename to core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php index 827c811..ab03ff5 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php @@ -1,6 +1,6 @@ $date->format($date_format), ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertRaw($date->format($date_format)); @@ -115,8 +115,9 @@ public function testDateField() { // field, it is expected to display the time as 00:00:00. $expected = format_date($date->getTimestamp(), $new_value, '', DATETIME_STORAGE_TIMEZONE); $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $expected_iso . '"]', $expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso])); + $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])); break; } } @@ -129,8 +130,8 @@ public function testDateField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $date->format(DATETIME_DATE_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'datetime_custom' formatter works. $this->displayOptions['type'] = 'datetime_custom'; @@ -139,8 +140,8 @@ public function testDateField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected])); // Test that allowed markup in custom format is preserved and XSS is // removed. @@ -149,8 +150,8 @@ public function testDateField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = '' . $date->format('m/d/Y') . 'alert(String.fromCharCode(88,83,83))'; - $this->renderTestEntity($id); - $this->assertRaw($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%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 @@ -176,8 +177,8 @@ public function testDateField() { $expected = SafeMarkup::format($this->displayOptions['settings']['past_format'], [ '@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]) ]); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'datetime_time_ago' formatter works for intervals in the // future. First update the test entity so that the date difference always @@ -197,8 +198,8 @@ public function testDateField() { $expected = SafeMarkup::format($this->displayOptions['settings']['future_format'], [ '@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]) ]); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); } } @@ -215,7 +216,7 @@ public function testDatetimeField() { $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//text()', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, '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'); @@ -235,7 +236,7 @@ public function testDatetimeField() { "{$field_name}[0][value][time]" => $date->format($time_format), ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertRaw($date->format($date_format)); @@ -259,8 +260,9 @@ public function testDatetimeField() { // Verify that a date is displayed. $expected = format_date($date->getTimestamp(), $new_value); $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $expected_iso . '"]', $expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso])); + $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])); break; } } @@ -273,8 +275,8 @@ public function testDatetimeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'datetime_custom' formatter works. $this->displayOptions['type'] = 'datetime_custom'; @@ -283,8 +285,8 @@ public function testDatetimeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'timezone_override' setting works. $this->displayOptions['type'] = 'datetime_custom'; @@ -293,8 +295,8 @@ public function testDatetimeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%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 @@ -320,8 +322,8 @@ public function testDatetimeField() { $expected = SafeMarkup::format($this->displayOptions['settings']['past_format'], [ '@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]) ]); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'datetime_time_ago' formatter works for intervals in the // future. First update the test entity so that the date difference always @@ -341,8 +343,8 @@ public function testDatetimeField() { $expected = SafeMarkup::format($this->displayOptions['settings']['future_format'], [ '@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]) ]); - $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected])); } /** @@ -368,7 +370,7 @@ public function testDatelistWidget() { // Display creation form. $this->drupalGet('entity_test/add'); - $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend//text()', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, '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'); @@ -381,7 +383,7 @@ public function testDatelistWidget() { $this->drupalGet($fieldEditUrl); // Click on the widget settings button to open the widget settings form. - $this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); + $this->drupalPostForm(NULL, [], $field_name . "_settings_edit"); $xpathIncr = "//select[starts-with(@id, \"edit-fields-$field_name-settings-edit-form-settings-increment\")]"; $this->assertNoFieldByXPath($xpathIncr, NULL, 'Increment element not found for Date Only.'); @@ -407,7 +409,7 @@ public function testDatelistWidget() { $this->drupalGet($fieldEditUrl); // Click on the widget settings button to open the widget settings form. - $this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); + $this->drupalPostForm(NULL, [], $field_name . "_settings_edit"); $this->assertFieldByXPath($xpathIncr, NULL, 'Increment element found for Date and time.'); // Display creation form. @@ -444,7 +446,7 @@ public function testDatelistWidget() { } $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); @@ -485,7 +487,7 @@ public function testDatelistWidget() { } $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); @@ -539,7 +541,7 @@ public function testDatelistWidget() { $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertResponse(200); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); diff --git a/core/modules/datetime_range/src/Tests/DateRangeFieldTest.php b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php similarity index 87% rename from core/modules/datetime_range/src/Tests/DateRangeFieldTest.php rename to core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php index f553315..23ba8fa 100644 --- a/core/modules/datetime_range/src/Tests/DateRangeFieldTest.php +++ b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php @@ -1,12 +1,12 @@ assertFieldByXPath('//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]', TRUE, 'Required markup found'); $this->assertNoFieldByName("{$field_name}[0][value][time]", '', 'Start time element not found.'); $this->assertNoFieldByName("{$field_name}[0][end_value][time]", '', 'End time element not found.'); - $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend//text()', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, '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'); @@ -83,7 +83,7 @@ public function testDateRangeField() { "{$field_name}[0][end_value][date]" => $end_date->format($date_format), ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertRaw($start_date->format($date_format)); @@ -128,20 +128,22 @@ public function testDateRangeField() { $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE); $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); + $start_expected_markup = ''; $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE); $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [ + $end_expected_markup = ''; + $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.', [ '%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso, ])); - $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, 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.', [ '%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso, ])); - $this->assertText(' THESEPARATOR ', 'Found proper separator'); + $this->assertContains(' THESEPARATOR ', $output, 'Found proper separator'); // Verify that hook_entity_prepare_view can add attributes. // @see entity_test_entity_prepare_view() @@ -155,8 +157,8 @@ public function testDateRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format(DATETIME_DATE_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATE_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); // Verify that the custom formatter works. $this->displayOptions['type'] = 'daterange_custom'; @@ -165,8 +167,8 @@ public function testDateRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); // Test that allowed markup in custom format is preserved and XSS is // removed. @@ -175,8 +177,8 @@ public function testDateRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = '' . $start_date->format('m/d/Y') . 'alert(String.fromCharCode(88,83,83)) - ' . $end_date->format('m/d/Y') . 'alert(String.fromCharCode(88,83,83))'; - $this->renderTestEntity($id); - $this->assertRaw($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); // Test formatters when start date and end date are the same $this->drupalGet('entity_test/add'); @@ -192,7 +194,7 @@ public function testDateRangeField() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); @@ -213,13 +215,14 @@ public function testDateRangeField() { $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE); $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [ + $start_expected_markup = ''; + $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.', [ '%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso, ])); - $this->assertNoText(' THESEPARATOR ', 'Separator not found on page'); + $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page'); // Verify that hook_entity_prepare_view can add attributes. // @see entity_test_entity_prepare_view() @@ -232,9 +235,9 @@ public function testDateRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format(DATETIME_DATE_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); - $this->assertNoText(' THESEPARATOR ', 'Separator not found on page'); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page'); $this->displayOptions['type'] = 'daterange_custom'; $this->displayOptions['settings'] = ['date_format' => 'm/d/Y'] + $this->defaultSettings; @@ -242,9 +245,9 @@ public function testDateRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); - $this->assertNoText(' THESEPARATOR ', 'Separator not found on page'); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page'); } } @@ -264,7 +267,7 @@ public function testDatetimeRangeField() { $this->assertFieldByName("{$field_name}[0][value][time]", '', 'Start time element found.'); $this->assertFieldByName("{$field_name}[0][end_value][date]", '', 'End date element found.'); $this->assertFieldByName("{$field_name}[0][end_value][time]", '', 'End time element found.'); - $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend//text()', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, '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'); @@ -289,7 +292,7 @@ public function testDatetimeRangeField() { "{$field_name}[0][end_value][time]" => $end_date->format($time_format), ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertRaw($start_date->format($date_format)); @@ -308,12 +311,14 @@ public function testDatetimeRangeField() { $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long'); $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $start_expected_markup = ''; $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long'); $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); - $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); - $this->assertText(' THESEPARATOR ', 'Found proper separator'); + $end_expected_markup = ''; + $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.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); + $this->assertContains($end_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); + $this->assertContains(' THESEPARATOR ', $output, 'Found proper separator'); // Verify that hook_entity_prepare_view can add attributes. // @see entity_test_entity_prepare_view() @@ -327,8 +332,8 @@ public function testDatetimeRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'datetime_custom' formatter works. $this->displayOptions['type'] = 'daterange_custom'; @@ -337,8 +342,8 @@ public function testDatetimeRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'timezone_override' setting works. $this->displayOptions['type'] = 'daterange_custom'; @@ -348,8 +353,8 @@ public function testDatetimeRangeField() { ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); $expected .= ' - ' . $end_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); // Test formatters when start date and end date are the same $this->drupalGet('entity_test/add'); @@ -368,7 +373,7 @@ public function testDatetimeRangeField() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); @@ -387,9 +392,10 @@ public function testDatetimeRangeField() { $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long'); $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); - $this->assertNoText(' THESEPARATOR ', 'Separator not found on page'); + $start_expected_markup = ''; + $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.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); + $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page'); // Verify that hook_entity_prepare_view can add attributes. // @see entity_test_entity_prepare_view() @@ -402,9 +408,9 @@ public function testDatetimeRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); - $this->assertNoText(' THESEPARATOR ', 'Separator not found on page'); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page'); $this->displayOptions['type'] = 'daterange_custom'; $this->displayOptions['settings'] = ['date_format' => 'm/d/Y g:i:s A'] + $this->defaultSettings; @@ -412,9 +418,9 @@ public function testDatetimeRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); - $this->assertNoText(' THESEPARATOR ', 'Separator not found on page'); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $this->assertNotContains(' THESEPARATOR ', $output, 'Separator not found on page'); } /** @@ -434,7 +440,7 @@ public function testAlldayRangeField() { $this->assertFieldByXPath('//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]', TRUE, 'Required markup found'); $this->assertNoFieldByName("{$field_name}[0][value][time]", '', 'Start time element not found.'); $this->assertNoFieldByName("{$field_name}[0][end_value][time]", '', 'End time element not found.'); - $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend//text()', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, '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'); @@ -453,7 +459,7 @@ public function testAlldayRangeField() { "{$field_name}[0][end_value][date]" => $end_date->format($date_format), ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertRaw($start_date->format($date_format)); @@ -472,12 +478,14 @@ public function testAlldayRangeField() { $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long'); $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $start_expected_markup = ''; $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long'); $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); - $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); - $this->assertText(' THESEPARATOR ', 'Found proper separator'); + $end_expected_markup = ''; + $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.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); + $this->assertContains($end_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); + $this->assertContains(' THESEPARATOR ', $output, 'Found proper separator'); // Verify that hook_entity_prepare_view can add attributes. // @see entity_test_entity_prepare_view() @@ -491,8 +499,8 @@ public function testAlldayRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); // Verify that the custom formatter works. $this->displayOptions['type'] = 'daterange_custom'; @@ -501,8 +509,8 @@ public function testAlldayRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); // Verify that the 'timezone_override' setting works. $this->displayOptions['type'] = 'daterange_custom'; @@ -512,8 +520,8 @@ public function testAlldayRangeField() { ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); $expected .= ' - ' . $end_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); // Test formatters when start date and end date are the same $this->drupalGet('entity_test/add'); @@ -531,7 +539,7 @@ public function testAlldayRangeField() { "{$field_name}[0][end_value][date]" => $start_date->format($date_format), ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); @@ -550,12 +558,14 @@ public function testAlldayRangeField() { $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long'); $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $start_expected_markup = ''; $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long'); $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); - $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); - $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); - $this->assertText(' THESEPARATOR ', 'Found proper separator'); + $end_expected_markup = ''; + $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.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); + $this->assertContains($end_expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); + $this->assertContains(' THESEPARATOR ', $output, 'Found proper separator'); // Verify that hook_entity_prepare_view can add attributes. // @see entity_test_entity_prepare_view() @@ -567,9 +577,9 @@ public function testAlldayRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' THESEPARATOR ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); - $this->assertText(' THESEPARATOR ', 'Found proper separator'); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected])); + $this->assertContains(' THESEPARATOR ', $output, 'Found proper separator'); $this->displayOptions['type'] = 'daterange_custom'; $this->displayOptions['settings']['date_format'] = 'm/d/Y'; @@ -577,9 +587,9 @@ public function testAlldayRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' THESEPARATOR ' . $end_date->format($this->displayOptions['settings']['date_format']); - $this->renderTestEntity($id); - $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); - $this->assertText(' THESEPARATOR ', 'Found proper separator'); + $output = $this->renderTestEntity($id); + $this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', ['%expected' => $expected])); + $this->assertContains(' THESEPARATOR ', $output, 'Found proper separator'); } @@ -606,7 +616,7 @@ public function testDatelistWidget() { // Display creation form. $this->drupalGet('entity_test/add'); - $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend//text()', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, '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'); @@ -622,7 +632,7 @@ public function testDatelistWidget() { $this->drupalGet($fieldEditUrl); // Click on the widget settings button to open the widget settings form. - $this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); + $this->drupalPostForm(NULL, [], $field_name . "_settings_edit"); $xpathIncr = "//select[starts-with(@id, \"edit-fields-$field_name-settings-edit-form-settings-increment\")]"; $this->assertNoFieldByXPath($xpathIncr, NULL, 'Increment element not found for Date Only.'); @@ -656,7 +666,7 @@ public function testDatelistWidget() { $this->drupalGet($fieldEditUrl); // Click on the widget settings button to open the widget settings form. - $this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); + $this->drupalPostForm(NULL, [], $field_name . "_settings_edit"); $xpathIncr = "//select[starts-with(@id, \"edit-fields-$field_name-settings-edit-form-settings-increment\")]"; $this->assertNoFieldByXPath($xpathIncr, NULL, 'Increment element not found for Date Only.'); @@ -683,7 +693,7 @@ public function testDatelistWidget() { $this->drupalGet($fieldEditUrl); // Click on the widget settings button to open the widget settings form. - $this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); + $this->drupalPostForm(NULL, [], $field_name . "_settings_edit"); $this->assertFieldByXPath($xpathIncr, NULL, 'Increment element found for Date and time.'); // Display creation form. @@ -712,7 +722,7 @@ public function testDatelistWidget() { } $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); @@ -767,7 +777,7 @@ public function testDatelistWidget() { } $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); @@ -834,7 +844,7 @@ public function testDatelistWidget() { $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertResponse(200); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id]));