diff --git a/core/modules/link/src/Tests/LinkFieldUITest.php b/core/modules/link/src/Tests/LinkFieldUITest.php index 97fd9c8..b548aae 100644 --- a/core/modules/link/src/Tests/LinkFieldUITest.php +++ b/core/modules/link/src/Tests/LinkFieldUITest.php @@ -58,8 +58,12 @@ function testFieldUI() { // 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); - $this->fieldUIAddNewField($type_path, $field_name, $label, 'link'); + $field_edit = [ + 'field[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. @@ -67,11 +71,53 @@ 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. + // 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. + + // 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); @@ -84,14 +130,212 @@ function testFieldUI() { // 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_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, + ]; + $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, + ]; + $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); } } diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php index 7129d38..d60cca7 100644 --- a/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php +++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentFormTest.php @@ -42,6 +42,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 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 bf98504..0d51c54 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -55,6 +55,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();