diff --git a/core/modules/link/tests/src/Functional/LinkFieldUITest.php b/core/modules/link/tests/src/Functional/LinkFieldUITest.php
index eeed78c4c0..91d906fd4a 100644
--- a/core/modules/link/tests/src/Functional/LinkFieldUITest.php
+++ b/core/modules/link/tests/src/Functional/LinkFieldUITest.php
@@ -52,9 +52,13 @@ function testFieldUI() {
// Add a link field to the newly-created type. It defaults to allowing both
// internal and external links.
- $label = $this->randomMachineName();
+ $label = 'link_field_label';
+ $description = 'link field description';
$field_name = Unicode::strtolower($label);
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link');
+ $field_edit = [
+ 'description' => $description,
+ ];
+ $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', array(), $field_edit);
// Load the formatter page to check that the settings summary does not
// generate warnings.
@@ -62,31 +66,82 @@ function testFieldUI() {
$this->drupalGet("$type_path/display");
$this->assertText(t('Link text trimmed to @limit characters', array('@limit' => 80)));
- // Test the help text displays when the link field allows both internal and
- // external links.
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- $this->assertRaw('You can also enter an internal path such as /node/add or an external URL such as http://example.com.');
-
- // Log in an admin to set up the next content type.
- $this->drupalLogin($this->adminUser);
-
- // Add a different content type.
- $type = $this->drupalCreateContentType();
- $type_path = 'admin/structure/types/manage/' . $type->id();
- $add_path = 'node/add/' . $type->id();
-
- // Add a link field to the newly-created type. Specify it must allow
- // external only links.
- $label = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $field_edit = ['settings[link_type]' => LinkItemInterface::LINK_EXTERNAL];
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', array(), $field_edit);
-
- // Test the help text displays when link allows only external links.
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- $this->assertRaw('This must be an external URL such as http://example.com.');
+ // There are many combinations of UI settings, where the description should
+ // show: variation on internal, external, both; cardinality (where the
+ // fieldset is hidden or used); and link text shown (required or optional)
+ // or disabled. There are two descriptions: field and URL help text.
+ $cardinalities = [1, 2];
+ $title_settings = [
+ DRUPAL_DISABLED,
+ DRUPAL_OPTIONAL,
+ ];
+ $link_types = [
+ LinkItemInterface::LINK_EXTERNAL,
+ LinkItemInterface::LINK_GENERIC,
+ LinkItemInterface::LINK_INTERNAL,
+ ];
+ $help_texts = [
+ LinkItemInterface::LINK_EXTERNAL => 'This must be an external URL such as http://example.com.',
+ LinkItemInterface::LINK_GENERIC => 'You can also enter an internal path such as /node/add or an external URL such as http://example.com. Enter <front> to link to the front page.',
+ LinkItemInterface::LINK_INTERNAL => rtrim(\Drupal::url('', array(), array('absolute' => TRUE)), '/'),
+ ];
+ $field_count = 0;
+ // Test all variations of link types on all cardinalities.
+ foreach ($cardinalities as $cardinality) {
+ foreach ($link_types as $link_type) {
+ // Now, test this with both the title enabled and disabled.
+ foreach ($title_settings as $title_setting) {
+ // Both test empty descriptions and not empty descriptions.
+ foreach ([TRUE, FALSE] as $description_enabled) {
+ $field_count++;
+ // Output variation being tested for debugging purpose.
+ $this->verbose("Now testing - cardinality: $cardinality - link_type:
+ $link_type, title_setting: $title_setting, description_enabled:
+ $description_enabled");
+
+ // Log in an admin to set up a content type for this test.
+ $this->drupalLogin($this->adminUser);
+
+ // Add a new content type.
+ $type = $this->drupalCreateContentType();
+ $type_path = 'admin/structure/types/manage/' . $type->id();
+ $add_path = 'node/add/' . $type->id();
+
+ // Create a field for this content type with the current cardinality
+ // and link field settings.
+ $label = "link_field_label_$field_count";
+ $description = 'link field description with html ' . $field_count;
+ $field_name = Unicode::strtolower($label);
+ $storage_edit = ['cardinality_number' => $cardinality];
+ $field_edit = [
+ 'settings[link_type]' => $link_type,
+ 'description' => $description_enabled ? $description : '',
+ 'settings[title]' => $title_setting,
+ ];
+ $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', $storage_edit, $field_edit);
+
+ // Log in a user that is allowed to create this content type, see if
+ // the user can see the expected help text.
+ $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
+ $this->drupalGet($add_path);
+
+ // Check that the help texts we assume should be there, is there.
+ $this->assertRaw($help_texts[$link_type]);
+ if ($link_type === LinkItemInterface::LINK_INTERNAL) {
+ // Internal links have no "system" description. Test that none
+ // of the other help texts show here.
+ $this->assertNoRaw($help_texts[LinkItemInterface::LINK_EXTERNAL]);
+ $this->assertNoRaw($help_texts[LinkItemInterface::LINK_GENERIC]);
+ }
+ // Also assert that the description we made is here, no matter what
+ // the cardinality or link setting.
+ if ($description_enabled) {
+ $this->assertRaw($description);
+ }
+ }
+ }
+ }
+ }
}
}
diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php
index 1bdc927f7e..bf4ba43389 100644
--- a/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php
+++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php
@@ -37,6 +37,8 @@ public function testMenuLinkContentForm() {
$element = $this->xpath('//select[@id = :id]/option[@selected]', array(':id' => 'edit-menu-parent'));
$this->assertTrue($element, 'A default menu parent was found.');
$this->assertEqual('admin:', $element[0]['value'], ' menu is the parent.');
+ // Test that the field description is present.
+ $this->assertRaw('The location this menu link points to.');
$this->drupalPostForm(
NULL,
diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
index 679f89bbec..85c2cba4cd 100644
--- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
+++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
@@ -62,6 +62,11 @@ public function testShortcutLinkAdd() {
'/admin/config/system/site-information',
];
+ // Test the add shortcut form UI. Test that the base field description is
+ // there.
+ $this->drupalGet('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link');
+ $this->assertRaw('The location this shortcut points to.');
+
// Check that each new shortcut links where it should.
foreach ($test_cases as $test_path) {
$title = $this->randomMachineName();