function LinkFieldUITest::testFieldUI in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/link/src/Tests/LinkFieldUITest.php \Drupal\link\Tests\LinkFieldUITest::testFieldUI()
Tests the link field UI.
File
- core/
modules/ link/ src/ Tests/ LinkFieldUITest.php, line 52 - Contains \Drupal\link\Tests\LinkFieldUITest.
Class
- LinkFieldUITest
- Tests link field UI functionality.
Namespace
Drupal\link\TestsCode
function testFieldUI() {
// Add a 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();
$field_name = Unicode::strtolower($label);
$this
->fieldUIAddNewField($type_path, $field_name, $label, 'link');
// Load the formatter page to check that the settings summary does not
// generate warnings.
// @todo Mess with the formatter settings a bit here.
$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 <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>.');
// 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 <em class="placeholder">http://example.com</em>.');
}