#pager
+
+Theming and Output
+------------------
+Since link module is mainly a data storage field in a modular framework, the theming and output is up to the site builder and other additional modules. There are many modules in the Drupal repository, which control the output of fields perfectly and can handle rules, user actions, markup dependencies, and can vary the output under many different conditions, with much more efficience and flexibility for different scenarios. Please check out modules like views, display suite, panels, etc for such needs.
\ No newline at end of file
diff --git a/sites/all/modules/contrib/fields/link/link.info b/sites/all/modules/contrib/fields/link/link.info
index 016b7990..4ff71e25 100644
--- a/sites/all/modules/contrib/fields/link/link.info
+++ b/sites/all/modules/contrib/fields/link/link.info
@@ -12,15 +12,16 @@ files[] = tests/link.attribute.test
files[] = tests/link.crud.test
files[] = tests/link.crud_browser.test
files[] = tests/link.token.test
+files[] = tests/link.entity_token.test
files[] = tests/link.validate.test
; Views Handlers
files[] = views/link_views_handler_argument_target.inc
files[] = views/link_views_handler_filter_protocol.inc
-; Information added by Drupal.org packaging script on 2014-10-21
-version = "7.x-1.3"
+; Information added by Drupal.org packaging script on 2016-01-15
+version = "7.x-1.4"
core = "7.x"
project = "link"
-datestamp = "1413924830"
+datestamp = "1452830642"
diff --git a/sites/all/modules/contrib/fields/link/link.module b/sites/all/modules/contrib/fields/link/link.module
index b0c53c37..1e9d088b 100644
--- a/sites/all/modules/contrib/fields/link/link.module
+++ b/sites/all/modules/contrib/fields/link/link.module
@@ -207,7 +207,7 @@ function link_field_instance_settings_form($field, $instance) {
$form['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Additional CSS Class'),
- '#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces.'),
+ '#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces. Only alphanumeric characters and hyphens are allowed'),
'#default_value' => empty($instance['settings']['attributes']['class']) ? '' : $instance['settings']['attributes']['class'],
);
$form['attributes']['configurable_title'] = array(
@@ -291,7 +291,7 @@ function link_field_validate($entity_type, $entity, $field, $instance, $langcode
*/
function link_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as $delta => $value) {
- _link_process($items[$delta], $delta, $field, $entity);
+ _link_process($items[$delta], $delta, $field, $entity, $instance);
}
}
@@ -300,7 +300,7 @@ function link_field_insert($entity_type, $entity, $field, $instance, $langcode,
*/
function link_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as $delta => $value) {
- _link_process($items[$delta], $delta, $field, $entity);
+ _link_process($items[$delta], $delta, $field, $entity, $instance);
}
}
@@ -371,8 +371,24 @@ function _link_load($field, $item, $instance) {
/**
* Prepares the item attributes and url for storage.
+ *
+ * @param $item
+ * Link field values.
+ *
+ * @param $delta
+ * The sequence number for current values.
+ *
+ * @param $field
+ * The field structure array.
+ *
+ * @param $entity
+ * Entity object.
+ *
+ * @param $instance
+ * The instance structure for $field on $entity's bundle.
+ *
*/
-function _link_process(&$item, $delta, $field, $entity) {
+function _link_process(&$item, $delta, $field, $entity, $instance) {
// Trim whitespace from URL.
if (!empty($item['url'])) {
$item['url'] = trim($item['url']);
@@ -391,7 +407,8 @@ function _link_process(&$item, $delta, $field, $entity) {
// Don't save an invalid default value (e.g. 'http://').
if ((isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url']) && is_object($entity)) {
- if (!link_validate_url($item['url'])) {
+ $langcode = !empty($entity) ? field_language($instance['entity_type'], $entity, $instance['field_name']) : LANGUAGE_NONE;
+ if (!link_validate_url($item['url'], $langcode)) {
unset($item['url']);
}
}
@@ -403,7 +420,7 @@ function _link_process(&$item, $delta, $field, $entity) {
function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &$optional_field_found, &$errors) {
if ($item['url'] && !(isset($instance['default_value'][$delta]['url']) && $item['url'] === $instance['default_value'][$delta]['url'] && !$instance['required'])) {
// Validate the link.
- if (link_validate_url(trim($item['url'])) == FALSE) {
+ if (!link_validate_url(trim($item['url']), $langcode)) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'link_required',
'message' => t('The value %value provided for %field is not a valid URL.', array(
@@ -474,19 +491,21 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$entity_type == 'taxonomy_term' || $entity_type == 'taxonomy_vocabulary' ? str_replace('taxonomy_', '', $entity_type) : $entity_type
);
if (isset($instance['settings']['enable_tokens']) && $instance['settings']['enable_tokens']) {
- global $user;
- // Load the entity if necessary for entities in views.
- if (isset($entity->{$property_id})) {
- $entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
- $entity_loaded = array_pop($entity_loaded);
+ $text_tokens = token_scan($item['url']);
+ if (!empty($text_tokens)) {
+ // Load the entity if necessary for entities in views.
+ if (isset($entity->{$property_id})) {
+ $entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
+ $entity_loaded = array_pop($entity_loaded);
+ }
+ else {
+ $entity_loaded = $entity;
+ }
+ $item['url'] = token_replace($item['url'], array($entity_token_type => $entity_loaded));
}
- else {
- $entity_loaded = $entity;
- }
- $item['url'] = token_replace($item['url'], array($entity_token_type => $entity_loaded));
}
- $type = link_validate_url($item['url']);
+ $type = link_url_type($item['url']);
// If the type of the URL cannot be determined and URL validation is disabled,
// then assume LINK_EXTERNAL for later processing.
if ($type == FALSE && $instance['settings']['validate_url'] === 0) {
@@ -496,12 +515,12 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$url_parts = _link_parse_url($url);
if (!empty($url_parts['url'])) {
- $item['url'] = $url_parts['url'];
- $item += array(
- 'query' => isset($url_parts['query']) ? $url_parts['query'] : NULL,
+ $item['url'] = url($url_parts['url'],
+ array('query' => isset($url_parts['query']) ? $url_parts['query'] : NULL,
'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL,
'absolute' => !empty($instance['settings']['absolute_url']),
'html' => TRUE,
+ )
);
}
@@ -541,15 +560,18 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
// Replace title tokens.
if ($title && ($instance['settings']['title'] == 'value' || $instance['settings']['enable_tokens'])) {
- // Load the entity if necessary for entities in views.
- if (isset($entity->{$property_id})) {
- $entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
- $entity_loaded = array_pop($entity_loaded);
+ $text_tokens = token_scan($title);
+ if (!empty($text_tokens)) {
+ // Load the entity if necessary for entities in views.
+ if (isset($entity->{$property_id})) {
+ $entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
+ $entity_loaded = array_pop($entity_loaded);
+ }
+ else {
+ $entity_loaded = $entity;
+ }
+ $title = token_replace($title, array($entity_token_type => $entity_loaded));
}
- else {
- $entity_loaded = $entity;
- }
- $title = token_replace($title, array($entity_token_type => $entity_loaded));
$title = filter_xss($title, array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
$item['html'] = TRUE;
}
@@ -599,22 +621,25 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
// Handle "title" link attribute.
if (!empty($item['attributes']['title']) && module_exists('token')) {
- // Load the entity (necessary for entities in views).
- if (isset($entity->{$property_id})) {
- $entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
- $entity_loaded = array_pop($entity_loaded);
+ $text_tokens = token_scan($item['attributes']['title']);
+ if (!empty($text_tokens)) {
+ // Load the entity (necessary for entities in views).
+ if (isset($entity->{$property_id})) {
+ $entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
+ $entity_loaded = array_pop($entity_loaded);
+ }
+ else {
+ $entity_loaded = $entity;
+ }
+ $item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded));
}
- else {
- $entity_loaded = $entity;
- }
- $item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded));
$item['attributes']['title'] = filter_xss($item['attributes']['title'], array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
}
// Handle attribute classes.
if (!empty($item['attributes']['class'])) {
$classes = explode(' ', $item['attributes']['class']);
foreach ($classes as &$class) {
- $class = drupal_html_class($class);
+ $class = drupal_clean_css_identifier($class);
}
$item['attributes']['class'] = implode(' ', $classes);
}
@@ -660,7 +685,7 @@ function _link_parse_url($url) {
* Replaces the PHP parse_str() function.
*
* Because parse_str replaces the following characters in query parameters name
- * in order to maintain compability with deprecated register_globals directive:
+ * in order to maintain compatibility with deprecated register_globals directive:
*
* - chr(32) ( ) (space)
* - chr(46) (.) (dot)
@@ -700,6 +725,9 @@ function link_theme() {
'link_formatter_link_plain' => array(
'variables' => array('element' => NULL, 'field' => NULL),
),
+ 'link_formatter_link_host' => array(
+ 'variables' => array('element' => NULL),
+ ),
'link_formatter_link_absolute' => array(
'variables' => array('element' => NULL, 'field' => NULL),
),
@@ -859,7 +887,7 @@ function link_field_process($element, $form_state, $complete_form) {
);
}
- // If the title field is avaliable or there are field accepts multiple values
+ // If the title field is available or there are field accepts multiple values
// then allow the individual field items display the required asterisk if needed.
if (isset($element['title']) || isset($element['_weight'])) {
// To prevent an extra required indicator, disable the required flag on the
@@ -885,6 +913,11 @@ function link_field_formatter_info() {
'field types' => array('link_field'),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
+ 'link_host' => array(
+ 'label' => t('Host, as plain text'),
+ 'field types' => array('link_field'),
+ 'multiple values' => FIELD_BEHAVIOR_DEFAULT,
+ ),
'link_url' => array(
'label' => t('URL, as link'),
'field types' => array('link_field'),
@@ -1015,6 +1048,14 @@ function theme_link_formatter_link_plain($vars) {
return empty($vars['element']['url']) ? check_plain($vars['element']['title']) : url($vars['element']['url'], $link_options);
}
+/**
+ * Theme function for 'host' text field formatter.
+ */
+function theme_link_formatter_link_host($vars) {
+ $host = @parse_url($vars['element']['url']);
+ return isset($host['host']) ? check_plain($host['host']) : '';
+}
+
/**
* Formats a link as an absolute URL.
*/
@@ -1142,7 +1183,7 @@ function link_views_api() {
/**
* Forms a valid URL if possible from an entered address.
- *
+ *
* Trims whitespace and automatically adds an http:// to addresses without a
* protocol specified
*
@@ -1153,7 +1194,7 @@ function link_views_api() {
*/
function link_cleanup_url($url, $protocol = 'http') {
$url = trim($url);
- $type = link_validate_url($url);
+ $type = link_url_type($url);
if ($type === LINK_EXTERNAL) {
// Check if there is no protocol specified.
@@ -1173,18 +1214,59 @@ function link_cleanup_url($url, $protocol = 'http') {
/**
* Validates a URL.
- *
+ *
+ * @param $text
+ * Url to be validated.
+ *
+ * @param $langcode
+ * An optional language code to look up the path in.
+ *
+ * @return boolean
+ * True if a valid link, FALSE otherwise.
+ */
+function link_validate_url($text, $langcode = NULL) {
+ $text = link_cleanup_url($text);
+ $type = link_url_type($text);
+
+ if ($type && ($type == LINK_INTERNAL || $type == LINK_EXTERNAL)) {
+ $flag = valid_url($text, TRUE);
+ if (!$flag) {
+ $normal_path = drupal_get_normal_path($text, $langcode);
+ $parsed_link = parse_url($normal_path, PHP_URL_PATH);
+ if ($normal_path != $parsed_link) {
+ $normal_path = $parsed_link;
+ }
+ $flag = drupal_valid_path($normal_path);
+ }
+ if (!$flag) {
+ $flag = file_exists($normal_path);
+ }
+ if (!$flag) {
+ $uri = file_build_uri($normal_path);
+ $flag = file_exists($uri);
+ }
+ }
+ else {
+ $flag = (bool) $type;
+ }
+
+ return $flag;
+}
+
+/**
+ * Type check a URL.
+ *
* Accepts all URLs following RFC 1738 standard for URL formation and all e-mail
* addresses following the RFC 2368 standard for mailto address formation.
*
* @param string $text
- * Url to be validated.
+ * Url to be checked.
*
* @return mixed
* Returns boolean FALSE if the URL is not valid. On success, returns one of
* the LINK_(linktype) constants.
*/
-function link_validate_url($text) {
+function link_url_type($text) {
// @TODO Complete letters.
$LINK_ICHARS_DOMAIN = (string) html_entity_decode(implode("", array(
"æ", // æ
diff --git a/sites/all/modules/contrib/fields/link/tests/link.attribute.test b/sites/all/modules/contrib/fields/link/tests/link.attribute.test
index 603847ef..36e6be5e 100644
--- a/sites/all/modules/contrib/fields/link/tests/link.attribute.test
+++ b/sites/all/modules/contrib/fields/link/tests/link.attribute.test
@@ -254,6 +254,41 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
}
}
+ function testFormatterHost() {
+ $content_type_friendly = $this->randomName(20);
+ $content_type_machine = strtolower($this->randomName(10));
+
+ $this->drupalCreateContentType(array(
+ 'type' => $content_type_machine,
+ 'name' => $content_type_friendly,
+ ));
+
+
+ // Now add a singleton field.
+ $single_field_name_friendly = $this->randomName(20);
+ $single_field_name_machine = strtolower($this->randomName(10));
+ //$single_field_name = 'field_'. $single_field_name_machine;
+ $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
+
+ // Okay, now we want to make sure this display is changed:
+ $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
+ $edit = array(
+ 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
+ 'fields[field_'. $single_field_name_machine .'][type]' => 'link_host',
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+
+ $this->createNodeTypeUser($content_type_machine);
+
+ $link_text = 'Display';
+ $link_url = 'http://www.example.com/';
+ $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
+
+ $this->assertText('www.example.com');
+ $this->assertNoText($link_text);
+ $this->assertNoLinkByHref($link_url);
+ }
+
function testFormatterURL() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
diff --git a/sites/all/modules/contrib/fields/link/tests/link.crud_browser.test b/sites/all/modules/contrib/fields/link/tests/link.crud_browser.test
index c90e86d1..be042609 100644
--- a/sites/all/modules/contrib/fields/link/tests/link.crud_browser.test
+++ b/sites/all/modules/contrib/fields/link/tests/link.crud_browser.test
@@ -312,4 +312,148 @@ class LinkUITest extends DrupalWebTestcase {
$this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
}
+
+ /**
+ * If we're creating a new field and just hit 'save' on the default options, we want to make
+ * sure they are set to the expected results.
+ */
+ function testCRUDCreateFieldWithClass() {
+ $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
+ $this->drupalLogin($this->web_user);
+
+ // create field
+ $name = strtolower($this->randomName());
+ $edit = array(
+ 'fields[_add_new_field][label]' => $name,
+ 'fields[_add_new_field][field_name]' => $name,
+ 'fields[_add_new_field][type]' => 'link_field',
+ 'fields[_add_new_field][widget_type]' => 'link_field',
+ );
+ $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
+
+ $this->drupalPost(NULL, array(), t('Save field settings'));
+ $link_class_name = 'basic-link-' . strtolower($this->randomName());
+ $edit = array(
+ 'instance[settings][attributes][class]' => $link_class_name,
+ );
+ $this->drupalPost(NULL, $edit, t('Save settings'));
+
+ // Is field created?
+ $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
+ node_types_rebuild();
+ menu_rebuild();
+
+ _field_info_collate_fields(TRUE);
+ $instances = field_info_instances('node', 'page');
+
+ $instance = $instances['field_' . $name];
+ $this->assertFalse($instance['required'], 'Make sure field is not required.');
+ $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
+ $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
+ $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
+ $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
+ $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
+ $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
+ $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.');
+ $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
+
+ // Now, let's create a node with this field and make sure the link shows up:
+ // create page form
+ $field_name = 'field_' . $name;
+ $this->drupalGet('node/add/page');
+ $this->assertField($field_name . '[und][0][url]', 'URL found');
+
+ $input = array(
+ 'title' => 'This & That',
+ 'href' => 'http://www.example.com/',
+ );
+
+ $edit = array(
+ 'title' => $field_name,
+ $field_name . '[und][0][title]' => $input['title'],
+ $field_name . '[und][0][url]' => $input['href'],
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+
+ $url = $this->getUrl();
+
+ // change to anonymous user
+ $this->drupalLogout();
+ $this->drupalGet($url);
+
+ $this->assertRaw('This & That');
+ $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page.");
+ }
+
+/**
+ * If we're creating a new field and just hit 'save' on the default options, we want to make
+ * sure they are set to the expected results.
+ */
+ function testCRUDCreateFieldWithTwoClasses() {
+ $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
+ $this->drupalLogin($this->web_user);
+
+ // create field
+ $name = strtolower($this->randomName());
+ $edit = array(
+ 'fields[_add_new_field][label]' => $name,
+ 'fields[_add_new_field][field_name]' => $name,
+ 'fields[_add_new_field][type]' => 'link_field',
+ 'fields[_add_new_field][widget_type]' => 'link_field',
+ );
+ $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
+
+ $this->drupalPost(NULL, array(), t('Save field settings'));
+ $link_class_name = 'basic-link ' . strtoupper($this->randomName());
+ $edit = array(
+ 'instance[settings][attributes][class]' => $link_class_name,
+ );
+ $this->drupalPost(NULL, $edit, t('Save settings'));
+
+ // Is field created?
+ $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
+ node_types_rebuild();
+ menu_rebuild();
+
+ _field_info_collate_fields(TRUE);
+ $instances = field_info_instances('node', 'page');
+
+ $instance = $instances['field_' . $name];
+ $this->assertFalse($instance['required'], 'Make sure field is not required.');
+ $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
+ $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
+ $this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
+ $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
+ $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
+ $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
+ $this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.');
+ $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
+
+ // Now, let's create a node with this field and make sure the link shows up:
+ // create page form
+ $field_name = 'field_' . $name;
+ $this->drupalGet('node/add/page');
+ $this->assertField($field_name . '[und][0][url]', 'URL found');
+
+ $input = array(
+ 'title' => 'This & That',
+ 'href' => 'http://www.example.com/',
+ );
+
+ $edit = array(
+ 'title' => $field_name,
+ $field_name . '[und][0][title]' => $input['title'],
+ $field_name . '[und][0][url]' => $input['href'],
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+
+ $url = $this->getUrl();
+
+ // change to anonymous user
+ $this->drupalLogout();
+ $this->drupalGet($url);
+
+ $this->assertRaw('This & That');
+ $this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page.");
+ }
}
diff --git a/sites/all/modules/contrib/fields/link/tests/link.entity_token.test b/sites/all/modules/contrib/fields/link/tests/link.entity_token.test
new file mode 100644
index 00000000..1f51fab4
--- /dev/null
+++ b/sites/all/modules/contrib/fields/link/tests/link.entity_token.test
@@ -0,0 +1,155 @@
+ 'Link entity tokens test',
+ 'description' => 'Tests that a link field appears properly in entity tokens',
+ 'group' => 'Link',
+ 'dependencies' => array('token', 'entity', 'entity_token'),
+ );
+ }
+
+ function setUp($modules = array()) {
+ parent::setUp(array('token', 'entity', 'entity_token'));
+ }
+
+ /**
+ * Creates a link field, fills it, then uses a loaded node to test tokens.
+ */
+ function testFieldTokenNodeLoaded() {
+ // create field
+ $settings = array(
+ 'instance[settings][enable_tokens]' => 0,
+ );
+ $field_name = $this->createLinkField('page',
+ $settings);
+
+ // create page form
+ $this->drupalGet('node/add/page');
+ //$field_name = 'field_' . $name;
+ $this->assertField($field_name . '[und][0][title]', 'Title found');
+ $this->assertField($field_name . '[und][0][url]', 'URL found');
+
+ $token_url_tests = array(
+ 1 => array(
+ 'href' => 'http://example.com/' . $this->randomName(),
+ 'label' => $this->randomName(),
+ ),
+ 2 => array(
+ 'href' => 'http://example.com/' . $this->randomName() . '?property=value',
+ 'label' => $this->randomName(),
+ ),
+ 3 => array(
+ 'href' => 'http://example.com/' . $this->randomName() . '#position',
+ 'label' => $this->randomName(),
+ ),
+ 4 => array(
+ 'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
+ 'label' => $this->randomName(),
+ ),
+ );
+ //$this->assert('pass', '' . print_r($token_url_tests, TRUE) . '');
+
+ foreach ($token_url_tests as &$input) {
+ $this->drupalGet('node/add/page');
+
+ $edit = array(
+ 'title' => $input['label'],
+ $field_name . '[und][0][title]' => $input['label'],
+ $field_name . '[und][0][url]' => $input['href'],
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+ $url = $this->getUrl();
+ $input['url'] = $url;
+ }
+
+ // change to anonymous user
+ $this->drupalLogout();
+
+ foreach ($token_url_tests as $index => $input2) {
+ $node = node_load($index);
+ $this->assertNotEqual(NULL, $node, "Do we have a node?");
+ $this->assertEqual($node->nid, $index, "Test that we have a node.");
+ $token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
+ $assert_data = token_replace($token_name,
+ array('node' => $node));
+ $this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
+ }
+ }
+
+ /**
+ * Creates a link field, fills it, then uses a loaded and node_view'd node to test tokens.
+ */
+ function testFieldTokenNodeViewed() {
+ // create field
+ $settings = array(
+ 'instance[settings][enable_tokens]' => 0,
+ );
+ $field_name = $this->createLinkField('page',
+ $settings);
+
+ // create page form
+ $this->drupalGet('node/add/page');
+ //$field_name = 'field_' . $name;
+ $this->assertField($field_name . '[und][0][title]', 'Title found');
+ $this->assertField($field_name . '[und][0][url]', 'URL found');
+
+ $token_url_tests = array(
+ 1 => array(
+ 'href' => 'http://example.com/' . $this->randomName(),
+ 'label' => $this->randomName(),
+ ),
+ 2 => array(
+ 'href' => 'http://example.com/' . $this->randomName() . '?property=value',
+ 'label' => $this->randomName(),
+ ),
+ 3 => array(
+ 'href' => 'http://example.com/' . $this->randomName() . '#position',
+ 'label' => $this->randomName(),
+ ),
+ 4 => array(
+ 'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
+ 'label' => $this->randomName(),
+ ),
+ );
+ //$this->assert('pass', '' . print_r($token_url_tests, TRUE) . '');
+
+ foreach ($token_url_tests as &$input) {
+ $this->drupalGet('node/add/page');
+
+ $edit = array(
+ 'title' => $input['label'],
+ $field_name . '[und][0][title]' => $input['label'],
+ $field_name . '[und][0][url]' => $input['href'],
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+ $url = $this->getUrl();
+ $input['url'] = $url;
+ }
+
+ // change to anonymous user
+ $this->drupalLogout();
+
+ foreach ($token_url_tests as $index => $input2) {
+ $node = node_load($index);
+ $node_array = node_view($node, 'full');
+ $this->assertNotEqual(NULL, $node, "Do we have a node?");
+ $this->assertEqual($node->nid, $index, "Test that we have a node.");
+ $token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
+ $assert_data = token_replace($token_name,
+ array('node' => $node));
+ $this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/sites/all/modules/contrib/fields/link/tests/link.token.test b/sites/all/modules/contrib/fields/link/tests/link.token.test
index 21bc4a04..617260e6 100644
--- a/sites/all/modules/contrib/fields/link/tests/link.token.test
+++ b/sites/all/modules/contrib/fields/link/tests/link.token.test
@@ -426,4 +426,6 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->assertRaw('This & That');
}
+
+
}
diff --git a/sites/all/modules/contrib/fields/link/tests/link.validate.test b/sites/all/modules/contrib/fields/link/tests/link.validate.test
index 764eeaad..a9ac116c 100644
--- a/sites/all/modules/contrib/fields/link/tests/link.validate.test
+++ b/sites/all/modules/contrib/fields/link/tests/link.validate.test
@@ -22,25 +22,24 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$field_name = $this->createLinkField();
- $permission = 'create page content';
- $this->checkPermissions(array($permission), TRUE);
-
- $this->drupalGet('node/add/page');
-
$label = $this->randomName();
- $edit = array(
+ $settings = array(
'title' => $label,
- $field_name . '[und][0][title]' => $label,
- $field_name . '[und][0][url]' => $url,
+ $field_name => array(
+ LANGUAGE_NONE=> array(
+ array(
+ 'title' => $label,
+ 'url' => $url,
+ )
+ ),
+ ),
);
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->assertRaw(' has been created.', 'Node created');
- $nid = 1; //$matches[1];
+ $node = $this->drupalCreateNode($settings);
- $node = node_load($nid);
+ $this->assertNotNull($node, ' has been created.', 'Node created');
- $this->assertEqual($url, $node->{$field_name}['und'][0]['url']);
+ $this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
}
}
@@ -269,7 +268,13 @@ class LinkValidateTest extends LinkValidateTestCase {
// Validate that an internal url would be accepted.
function test_link_internal_url() {
- $this->link_test_validate_url('node/32');
+ // Create the content first.
+ $node = $this->drupalCreateNode();
+
+ $link = 'node/' . $node->nid;
+ $this->link_test_validate_url($link);
+ $type = link_url_type($link);
+ $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
}
// Validate a simple mailto.
@@ -340,7 +345,7 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
/**
* Here, we're testing that a very long url is stored properly in the db.
*
- * Basicly, trying to test http://drupal.org/node/376818
+ * Basically, trying to test http://drupal.org/node/376818
*/
function testLinkURLFieldIsBig() {
$long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A';
@@ -363,6 +368,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'group' => 'Link',
);
}
+
+ function setUp() {
+ parent::setUp('link');
+ }
/**
* Translates the LINK type constants to english for display and debugging of tests
@@ -386,10 +395,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
}
}
- // Make sure that a link labelled works.
+ // Make sure that a link labeled works.
function testValidateFrontLink() {
$valid = link_validate_url('');
- $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verfied and identified');
+ $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
}
function testValidateEmailLink() {
@@ -409,7 +418,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
function testValidateNewsArticleLink() {
$valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
- $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article valiates as news.');
+ $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.');
}
function testValidateBadNewsgroupLink() {
@@ -418,16 +427,18 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
}
function testValidateInternalLinks() {
+ $tempfile = drupal_tempnam('public://files', 'test');
$links = array(
- 'node/5',
'rss.xml',
- 'files/test.jpg',
- '/var/www/test',
+ file_uri_target($tempfile),
+ drupal_realpath($tempfile),
);
foreach ($links as $link) {
+ $type = link_url_type($link);
+ $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
$valid = link_validate_url($link);
- $this->assertEqual(LINK_INTERNAL, $valid, 'Test ' . $link . ' internal link.');
+ $this->assertTrue($valid, 'Test ' . $link . ' is valid internal link.');
}
}
@@ -446,7 +457,6 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'http://255.255.255.255:4823/',
'www.test-site.com',
'http://example.com/index.php?q=node/123',
- 'http://example.com/index.php?page=this\that',
'http://example.com/?first_name=Joe Bob&last_name=Smith',
// Anchors
'http://www.example.com/index.php#test',
@@ -464,8 +474,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
}
}
foreach ($links as $link) {
+ $type = link_url_type($link);
+ $this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
$valid = link_validate_url($link);
- $this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that ' . $link . ' is a valid external link.');
+ $this->assertTrue($valid, 'Test ' . $link . ' is valid external link.');
// The following two lines are commented out and only used for comparisons.
//$valid2 = valid_url($link, TRUE);
//$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");
@@ -485,6 +497,8 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'http://www.testß.com/', // ß not allowed in domain names!
'http://www.example.frog/', // Bad TLD
//'http://www.-fudge.com/', // domains can't have sections starting with a dash.
+ 'http://example.com/index.php?page=this\that',
+ 'example@example.com',
);
foreach ($links as $link) {
$valid = link_validate_url($link);