diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php index eada494..a02e1c6 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -593,4 +593,44 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) { $this->verbose($output); } + function testRequiredLinkText() { + $field_name = Unicode::strtolower($this->randomMachineName()); + // Create a field with settings to validate. + $this->fieldStorage = entity_create('field_storage_config', array( + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'type' => 'link', + )); + $this->fieldStorage->save(); + $this->field = entity_create('field_config', array( + 'field_storage' => $this->fieldStorage, + 'bundle' => 'entity_test', + 'label' => 'Read more about this entity', + 'required' => TRUE, + 'settings' => array( + 'title' => DRUPAL_REQUIRED, + 'link_type' => LinkItemInterface::LINK_GENERIC, + ), + )); + $this->field->save(); + entity_get_form_display('entity_test', 'entity_test', 'default') + ->setComponent($field_name, array( + 'type' => 'link_default', + 'settings' => array( + 'placeholder_url' => 'http://example.com', + 'placeholder_title' => 'Enter the text for this link', + ), + )) + ->save(); + + // Display creation form. + $this->drupalGet('entity_test/add'); + $edit = []; + $this->drupalPostForm(NULL, $edit, t('Save')); + + $result = $this->xpath('//label[contains(@class, :class) and contains(text(), :text)]', array(':class' => 'form-required', ':text' => 'Link text')); + $this->assertEqual(count($result), 1, "Link text is marked as required when the link field is set to required."); + $this->assertText(t('@url field is required.', array('@url' => t('URL')))); + $this->assertText(t('@name field is required.', array('@name' => t('Link text')))); + } }