diff --git a/core/modules/link/src/Tests/LinkFieldUITest.php b/core/modules/link/src/Tests/LinkFieldUITest.php
index b548aae..99b3357 100644
--- a/core/modules/link/src/Tests/LinkFieldUITest.php
+++ b/core/modules/link/src/Tests/LinkFieldUITest.php
@@ -61,7 +61,7 @@ function testFieldUI() {
$description = $this->randomMachineName();
$field_name = Unicode::strtolower($label);
$field_edit = [
- 'field[description]' => $description,
+ 'description' => $description,
];
$this->fieldUIAddNewField($type_path, $field_name, $label, 'link', array(), $field_edit);
@@ -75,267 +75,76 @@ function testFieldUI() {
// 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.
-
- // Test descriptions show with defaults: internal and external, cardinality
- // 1 (field set removed), link text shown.
-
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- // Test URL help text is shown for the case internal and external allowed.
- $this->assertRaw('You can also enter an internal path such as /node/add or an external URL such as http://example.com.');
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test descriptions show when external only, cardinality 1, link text
- // shown.
-
- // 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();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $field_edit = [
- 'field[settings][link_type]' => LinkItemInterface::LINK_EXTERNAL,
- 'field[description]' => $description,
- ];
- $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);
- // Test URL help text is shown for the case external only allowed.
- $this->assertRaw('This must be an external URL such as http://example.com.');
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test descriptions show when internal only, cardinality 1, link text
- // shown.
-
- // 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();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $field_edit = [
- 'field[settings][link_type]' => LinkItemInterface::LINK_INTERNAL,
- 'field[description]' => $description,
- ];
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', array(), $field_edit);
-
- // Test the help text displays when link allows only internal links.
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- // There is no help text for internal only links, an input field prefix is
- // used instead. Test for the prefix.
- // @todo Assert the prefix.
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test descriptions show when internal and external, cardinality 2 (URL
- // field set is not removed), link text shown.
-
- // 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. It defaults to allowing both
- // internal and external links.
- $label = $this->randomMachineName();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $storage_edit = ['field_storage[cardinality_number]' => 2];
- $field_edit = [
- 'field[description]' => $description,
+ $cardinalities = [1, 2];
+ $title_settings = [
+ DRUPAL_DISABLED,
+ DRUPAL_OPTIONAL,
];
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', $storage_edit, $field_edit);
-
- // Test description shows with defaults: internal and external, cardinality
- // 2, link text shown.
-
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- // Test URL help text is shown for the case internal and external allowed.
- $this->assertRaw('You can also enter an internal path such as /node/add or an external URL such as http://example.com.');
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test description shows when external only, cardinality 2, link text
- // shown.
-
- // 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();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $storage_edit = ['field_storage[cardinality_number]' => 2];
- $field_edit = [
- 'field[settings][link_type]' => LinkItemInterface::LINK_EXTERNAL,
- 'field[description]' => $description,
+ $link_types = [
+ LinkItemInterface::LINK_EXTERNAL,
+ LinkItemInterface::LINK_GENERIC,
+ LinkItemInterface::LINK_INTERNAL,
];
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', $storage_edit, $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);
- // Test URL help text is shown for the case external only allowed.
- $this->assertRaw('This must be an external URL such as http://example.com.');
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test description shows when internal only, cardinality 2, link text
- // shown.
-
- // 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();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $storage_edit = ['field_storage[cardinality_number]' => 2];
- $field_edit = [
- 'field[settings][link_type]' => LinkItemInterface::LINK_INTERNAL,
- 'field[description]' => $description,
- ];
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', $storage_edit, $field_edit);
-
- // Test the help text displays when link allows only internal links.
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- // There is no help text for internal only links, an input field prefix is
- // used instead. Test for the prefix.
- // @todo Assert the prefix.
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test description shows when internal and external, cardinality 1 (URL
- // field set is removed), link text not shown.
-
- // 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. It defaults to allowing both
- // internal and external links.
- $label = $this->randomMachineName();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $field_edit = [
- 'field[description]' => $description,
- 'field[settings][title]' => DRUPAL_DISABLED,
- ];
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', array(), $field_edit);
-
- // Test description shows with defaults: internal and external, cardinality
- // 1, link text not shown.
-
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- // Test URL help text is shown for the case internal and external allowed.
- $this->assertRaw('You can also enter an internal path such as /node/add or an external URL such as http://example.com.');
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test description shows when external only, cardinality 2, link text
- // shown.
-
- // 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();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $field_edit = [
- 'field[settings][link_type]' => LinkItemInterface::LINK_EXTERNAL,
- 'field[description]' => $description,
- 'field[settings][title]' => DRUPAL_DISABLED,
- ];
- $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);
- // Test URL help text is shown for the case external only allowed.
- $this->assertRaw('This must be an external URL such as http://example.com.');
- // Test field help text is shown.
- $this->assertRaw($description);
-
- // Test description shows when internal only, cardinality 1, link text not
- // shown.
-
- // 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();
- $description = $this->randomMachineName();
- $field_name = Unicode::strtolower($label);
- $field_edit = [
- 'field[settings][link_type]' => LinkItemInterface::LINK_INTERNAL,
- 'field[description]' => $description,
- 'field[settings][title]' => DRUPAL_DISABLED,
- ];
- $this->fieldUIAddNewField($type_path, $field_name, $label, 'link', array(), $field_edit);
-
- // Test the help text displays when link allows only internal links.
- $this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
- $this->drupalGet($add_path);
- // There is no help text for internal only links, an input field prefix is
- // used instead. Test for the prefix.
- // @todo Assert the prefix.
- // Test field help text is shown.
- $this->assertRaw($description);
+ // 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) {
+ // 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 = $this->randomMachineName();
+ $description = $this->randomMachineName();
+ $field_name = Unicode::strtolower($label);
+ $storage_edit = ['cardinality_number' => $cardinality];
+ $field_edit = [
+ 'settings[link_type]' => $link_type,
+ 'description' => $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.
+ switch ($link_type) {
+ case LinkItemInterface::LINK_GENERIC:
+ // Check that the text for allowing both internal and external is
+ // present.
+ $this->assertRaw('You can also enter an internal path such as /node/add or an external URL such as http://example.com.');
+ break;
+
+ case LinkItemInterface::LINK_EXTERNAL:
+ // Check the external only link help text.
+ $this->assertRaw('This must be an external URL such as http://example.com.');
+ break;
+
+ case LinkItemInterface::LINK_INTERNAL:
+ // Internal links have no "system" description. Test that none of
+ // the above shows here.
+ $this->assertNoRaw('This must be an external URL such as http://example.com.');
+ $this->assertNoRaw('You can also enter an internal path such as /node/add or an external URL such as http://example.com.');
+ // And assert that the field prefix is the internal URL.
+ $this->assertRaw(rtrim(\Drupal::url('', array(), array('absolute' => TRUE)), '/'));
+ break;
+
+ }
+ // Also assert that the description we made is here, no matter what
+ // the cardinality or link setting.
+ $this->assertRaw($description);
+ }
+ }
+ }
}
}