security update link,module_filters,search_api_solr,ubercart,views

This commit is contained in:
2019-04-24 16:39:12 +02:00
parent 0aea7a0db1
commit 514f3bd89e
497 changed files with 9038 additions and 3662 deletions

View File

@@ -1,33 +1,92 @@
Module description
------------------
The link module can be count to the top 50 modules in Drupal installations and provides a standard custom content field for links. With this module links can be added easily to any content types and profiles and include advanced validating and different ways of storing internal or external links and URLs. It also supports additional link text title, site wide tokens for titles and title attributes, target attributes, css class attribution, static repeating values, input conversion, and many more.
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Installation
* Configuration
* Example
* Theming and Output
* Maintainers
Requirements / Dependencies
---------------------------
1. Drupal 6: Custom content module (CCK)
2. Drupal 7: Fields API is provided already by core [no dependencies].
3. Drupal 8: Link module is in core now. No module installation needed. Yay! Don't forget to activate it. It's deactivated by default.
INFO Since some misleading user reports we need to clarify here - Link module is NOT about to add links to any menus or the navigation nor primary/secondary menu. This can be done with default menu module (part of Drupal core). The Link module provides an additional custom field for storing and validating links to be added with any content type, which means another input block additional to your text-body, title, image and any other input you can make on new content creation.
Installation
INTRODUCTION
------------
1. Drop the entire link module directory into your 'sites/all/modules' folder
2. Enable the module from the Administration area modules page (admin/build/modules)
3. Create or Edit a content-type and add a new field of type link (admin/content/types in D6, admin/structure/types in D7)
Configuration
The link can be count to the top 50 projects in Drupal installations and
provides a standard custom content field for links. With this module links can
be added easily to any content types and profiles and include advanced
validating and different ways of storing internal or external links and URLs. It
also supports additional link text title, site wide tokens for titles and title
attributes, target attributes, css class attribution, static repeating values,
input conversion, and many more.
REQUIREMENTS
------------
No special requirements
INSTALLATION
------------
Install as you would normally install a contributed Drupal module. See:
https://drupal.org/documentation/install/modules-themes/modules-7 for further
information.
CONFIGURATION
-------------
Configuration is only slightly more complicated than a text field. Link text titles for URLs can be made required, set as instead of URL, optional (default), or left out entirely. If no link text title is provided, the trimmed version of the complete URL will be displayed. The target attribute should be set to "_blank", "top", or left out completely (checkboxes provide info). The rel=nofollow attribute prevents the link from being followed by certain search engines. More info at Wikipedia (http://en.wikipedia.org/wiki/Spam_in_blogs#rel.3D.22nofollow.22).
Example
* Configuration is only slightly more complicated than a text field. Link text
titles for URLs can be made required, set as instead of URL, optional
(default), or left out entirely. If no link text title is provided, the
trimmed version of the complete URL will be displayed. The target attribute
should be set to "_blank", "top", or left out completely (checkboxes provide
info). The rel=nofollow attribute prevents the link from being followed by
certain search engines. More info at Wikipedia
(http://en.wikipedia.org/wiki/Spam_in_blogs#rel.3D.22nofollow.22).
EXAMPLE
-------
If you were to create a field named 'My New Link', the default display of the link would be: <em><div class="field_my_new_link" target="[target_value]"><a href="[URL]">[Title]</a></div></em> where items between [] characters would be customized based on the user input.
If you were to create a field named 'My New Link', the default display of the
link would be:
<em><div class="field_my_new_link" target="[target_value]"><a href="[URL]">
[Title]</a></div></em> where items between [] characters would be customized
based on the user input.
The link module supports both, internal and external URLs. URLs are validated on input. Here are some examples of data input and the default view of a link: http://drupal.org results in http://drupal.org, but drupal.org results in http://drupal.org, while <front> will convert into http://drupal.org and node/74971 into http://drupal.org/project/link
The link project supports both, internal and external URLs. URLs are validated
on input. Here are some examples of data input and the default view of a link:
http://drupal.org results in http://drupal.org, but drupal.org results in
http://drupal.org, while <front> will convert into http://drupal.org and
node/74971 into http://drupal.org/project/link
Anchors and query strings may also be used in any of these cases, including: node/74971/edit?destination=node/74972<front>#pager
Anchors and query strings may also be used in any of these cases, including:
node/74971/edit?destination=node/74972<front>#pager
Theming and Output
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.
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
MAINTAINERS
-----------
Current maintainers:
* John C Fiala (jcfiala) - https://www.drupal.org/user/163643
* Renato Gonçalves (RenatoG) - https://www.drupal.org/user/3326031
* Clemens Tolboom (clemens.tolboom) - https://www.drupal.org/user/125814
* diqidoq - https://www.drupal.org/user/1001934
* dropcube - https://www.drupal.org/user/37031
* Tom Kirkpatrick (mrfelton) - https://www.drupal.org/user/305669
* Sumit Madan (sumitmadan) - https://www.drupal.org/user/1538790
* Daniel Kudwien (sun) - https://www.drupal.org/user/54136

View File

@@ -2,7 +2,6 @@
float: left;
width: 48%;
}
.link-field-column .form-text {
width: 95%;
}

View File

@@ -1,8 +0,0 @@
.link-field-column {
float: right;
}
.link-field-column.link-field-url .form-text {
direction: ltr;
text-align: left;
}

View File

@@ -1,370 +0,0 @@
From f8ea05469f22005733e7d030f45ff85771924f14 Mon Sep 17 00:00:00 2001
From: Jaleel Carter <Jaleel.Carter@acquia.com>
Date: Thu, 14 Jul 2016 13:29:03 -0400
Subject: [PATCH] 2299657-45
2299657-45-1
---
link.install | 14 +++++++++++
link.module | 16 +++++++-----
tests/link.attribute.test | 6 +++--
tests/link.crud.test | 6 +++--
tests/link.crud_browser.test | 46 ++++++++++++++++++++---------------
tests/link.test | 8 +++---
tests/link.validate.test | 58 ++++++++++++++++++--------------------------
7 files changed, 87 insertions(+), 67 deletions(-)
diff --git a/link.install b/link.install
index 14e745d..e1820f7 100644
--- a/link.install
+++ b/link.install
@@ -115,3 +115,17 @@ function link_update_7001() {
}
}
}
+
+/**
+ * Removes unused link_extra_domains variable.
+ */
+function link_update_7002() {
+ variable_del('link_extra_domains');
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function link_uninstall() {
+ variable_del('link_allowed_domains');
+}
diff --git a/link.module b/link.module
index 1e9d088..aece66d 100644
--- a/link.module
+++ b/link.module
@@ -10,7 +10,6 @@ define('LINK_INTERNAL', 'internal');
define('LINK_FRONT', 'front');
define('LINK_EMAIL', 'email');
define('LINK_NEWS', 'news');
-define('LINK_DOMAINS', 'aero|arpa|asia|biz|build|com|cat|ceo|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|post|pro|tel|travel|mobi|local|xxx');
define('LINK_TARGET_DEFAULT', 'default');
define('LINK_TARGET_NEW_WINDOW', '_blank');
@@ -1261,7 +1260,7 @@ function link_validate_url($text, $langcode = NULL) {
*
* @param string $text
* Url to be checked.
- *
+ *
* @return mixed
* Returns boolean FALSE if the URL is not valid. On success, returns one of
* the LINK_(linktype) constants.
@@ -1383,11 +1382,16 @@ function link_url_type($text) {
}
/**
- * Returns the list of allowed domains, including domains added by admins via variable_set/$config.
+ * Returns the list of allowed domains.
+ *
+ * If the variable link_allowed_domains is set, restrict allowed domains to the
+ * strings in that array. If the variable link_allowed_domains is not set, allow
+ * all domains between 2 and 63 characters in length.
+ * See https://tools.ietf.org/html/rfc1034.
*/
function _link_domains() {
- $link_extra_domains = variable_get('link_extra_domains', array());
- return empty($link_extra_domains) ? LINK_DOMAINS : LINK_DOMAINS . '|' . implode('|', $link_extra_domains);
+ $link_allowed_domains = variable_get('link_allowed_domains', array());
+ return empty($link_allowed_domains) ? '[a-z][a-z0-9-]{1,62}' : implode('|', $link_allowed_domains);
}
/**
@@ -1439,7 +1443,7 @@ function link_field_settings_form() {
/**
* Additional callback to adapt the property info of link fields.
- *
+ *
* @see entity_metadata_field_entity_property_info()
*/
function link_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
diff --git a/tests/link.attribute.test b/tests/link.attribute.test
index 36e6be5..4765814 100644
--- a/tests/link.attribute.test
+++ b/tests/link.attribute.test
@@ -31,8 +31,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
parent::setup('field_ui', 'link');
$this->zebra = 0;
// Create and login user.
- $this->web_user = $this->drupalCreateUser(array('administer content types'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
}
protected function createLink($url, $title, $attributes = array()) {
diff --git a/tests/link.crud.test b/tests/link.crud.test
index e9b7db4..5f12840 100644
--- a/tests/link.crud.test
+++ b/tests/link.crud.test
@@ -29,8 +29,10 @@ class LinkContentCrudTest extends DrupalWebTestCase {
$title = $this->randomName(20);
// Create and login user.
- $this->web_user = $this->drupalCreateUser(array('administer content types'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
$this->drupalGet('admin/structure/types');
diff --git a/tests/link.crud_browser.test b/tests/link.crud_browser.test
index be04260..803169b 100644
--- a/tests/link.crud_browser.test
+++ b/tests/link.crud_browser.test
@@ -42,15 +42,11 @@ class LinkUITest extends DrupalWebTestcase {
*/
function testLinkCreate() {
//libxml_use_internal_errors(true);
- $this->web_user = $this->drupalCreateUser(array(
- 'administer content types',
- 'administer nodes',
- 'administer filters',
- 'access content',
- 'create page content',
- 'access administration pages'
- ));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
+
// create field
$name = strtolower($this->randomName());
@@ -133,7 +129,7 @@ class LinkUITest extends DrupalWebTestcase {
$input_test_cases[] = $test_case;
foreach ($input_test_cases as $input) {
- $this->drupalLogin($this->web_user);
+ $this->drupalLogin($admin);
$this->drupalGet('node/add/page');
$edit = array(
@@ -179,8 +175,10 @@ class LinkUITest extends DrupalWebTestcase {
* title actually displays <strong>.
*/
function testStaticLinkCreate() {
- $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
@@ -227,8 +225,10 @@ class LinkUITest extends DrupalWebTestcase {
* Testing that if you have the title but no url, the title is not sanitized twice.
*/
function testCRUDTitleOnlyTitleNoLink() {
- $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
@@ -278,8 +278,10 @@ class LinkUITest extends DrupalWebTestcase {
* sure they are set to the expected results.
*/
function testCRUDCreateFieldDefaults() {
- $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
@@ -318,8 +320,10 @@ class LinkUITest extends DrupalWebTestcase {
* 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);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
@@ -390,8 +394,10 @@ class LinkUITest extends DrupalWebTestcase {
* 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);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
diff --git a/tests/link.test b/tests/link.test
index 962197f..b030153 100644
--- a/tests/link.test
+++ b/tests/link.test
@@ -23,9 +23,11 @@ class LinkBaseTestClass extends DrupalWebTestCase {
$modules[] = 'field_ui';
$modules[] = 'link';
parent::setUp($modules);
-
- $this->web_user = $this->drupalCreateUser($this->permissions);
- $this->drupalLogin($this->web_user);
+
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
}
protected function createLinkField($node_type = 'page', $settings = array()) {
diff --git a/tests/link.validate.test b/tests/link.validate.test
index a9ac116..f03a64c 100644
--- a/tests/link.validate.test
+++ b/tests/link.validate.test
@@ -61,13 +61,10 @@ class LinkValidateTest extends LinkValidateTestCase {
* Test if we're stopped from posting a bad url on default validation.
*/
function test_link_validate_bad_url_validate_default() {
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'administer filters',
- 'access content',
- 'create page content',
- 'access administration pages'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
@@ -106,13 +103,10 @@ class LinkValidateTest extends LinkValidateTestCase {
* Test if we're stopped from posting a bad url with validation on.
*/
function test_link_validate_bad_url_validate_on() {
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'administer filters',
- 'access content',
- 'create page content',
- 'access administration pages'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
@@ -152,13 +146,10 @@ class LinkValidateTest extends LinkValidateTestCase {
* Test if we can post a bad url if the validation is expressly turned off.
*/
function test_link_validate_bad_url_validate_off() {
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'administer filters',
- 'access content',
- 'create page content',
- 'access administration pages'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
// create field
$name = strtolower($this->randomName());
@@ -202,13 +193,10 @@ class LinkValidateTest extends LinkValidateTestCase {
*/
function x_test_link_validate_switching_between_validation_status() {
$this->acquireContentTypes(1);
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'access administration pages',
- 'access content',
- 'create ' . $this->content_types[0]->type . ' content',
- 'edit any ' . $this->content_types[0]->type . ' content'));
- $this->drupalLogin($this->web_user);
+ $perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
+ $perms = array_keys($perms[array_search('administrator', user_roles())]);
+ $admin = $this->drupalCreateUser($perms);
+ $this->drupalLogin($admin);
variable_set('node_options_' . $this->content_types[0]->name, array('status', 'promote'));
$field_settings = array(
'type' => 'link',
@@ -368,7 +356,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'group' => 'Link',
);
}
-
+
function setUp() {
parent::setUp('link');
}
@@ -429,11 +417,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
function testValidateInternalLinks() {
$tempfile = drupal_tempnam('public://files', 'test');
$links = array(
- 'rss.xml',
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.');
@@ -482,8 +469,8 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
//$valid2 = valid_url($link, TRUE);
//$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");
}
- // Test if we can make a tld valid:
- variable_set('link_extra_domains', array('frog'));
+ // Test if we can make a tld allowable:
+ variable_set('link_allowed_domains', array('frog'));
$valid = link_validate_url('http://www.example.frog');
$this->assertEqual(LINK_EXTERNAL, $valid, "Testing that http://www.example.frog is a valid external link if we've added 'frog' to the list of valid domains.");
}
@@ -495,7 +482,6 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'http://4827.0.0.2/',
'//www.example.com/',
'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',
@@ -504,5 +490,9 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
$valid = link_validate_url($link);
$this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
}
+ // Test if we can make a tld disallowed:
+ variable_set('link_allowed_domains', array('toad'));
+ $valid = link_validate_url('http://www.example.frog');
+ $this->assertEqual(FALSE, $valid, "Testing that http://www.example.frog is an invalid external link if we've not added 'frog' to the list of valid domains.");
}
}
--
2.7.4 (Apple Git-66)

View File

@@ -21,8 +21,9 @@ function link_devel_generate($object, $field, $instance, $bundle) {
* Callback for hook_devel_generate().
*/
function _link_devel_generate($object, $field, $instance, $bundle) {
$url = 'http://example.com/' . devel_generate_word(mt_rand(6, 12));
$link = array(
'url' => url('<front>', array('absolute' => TRUE)),
'url' => url($url, array('absolute' => TRUE)),
'attributes' => _link_default_attributes(),
);
if ($instance['settings']['title'] != 'none') {

View File

@@ -11,11 +11,11 @@
function link_field_diff_view($items, $context) {
$diff_items = array();
foreach ($items as $delta => $item) {
if ($item['url'] && $item['title']) {
if ($item['url'] && isset($item['title'])) {
$diff_items[$delta] = $item['title'] . ' (' . $item['url'] . ')';
}
else {
$diff_items[$delta] = $item['title'] . $item['url'];
$diff_items[$delta] = $item['url'];
}
}
return $diff_items;

View File

@@ -3,7 +3,6 @@ description = Defines simple link field types.
core = 7.x
package = Fields
files[] = link.module
files[] = link.migrate.inc
; Tests
@@ -14,14 +13,14 @@ files[] = tests/link.crud_browser.test
files[] = tests/link.token.test
files[] = tests/link.entity_token.test
files[] = tests/link.validate.test
files[] = tests/link.multilingual.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 2016-01-15
version = "7.x-1.4"
; Information added by Drupal.org packaging script on 2019-02-20
version = "7.x-1.5-beta3+25-dev"
core = "7.x"
project = "link"
datestamp = "1452830642"
datestamp = "1550680992"

View File

@@ -6,10 +6,38 @@
*/
/**
* Upgrade notes:
* Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:
* Upgrade notes.
*
* Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:.
*/
/**
* Implements hook_install().
*/
function link_install() {
// Notify the user they may want to install token.
if (!module_exists('token')) {
$t = get_t();
drupal_set_message($t('If you install the <a href="!url" target="blank">Token</a>, static title can use any other entity field as its value.', array(
'!url' => 'http://drupal.org/project/token',
)));
}
}
/**
* Removes unused link_extra_domains variable.
*/
function link_update_7002() {
variable_del('link_extra_domains');
}
/**
* Implements hook_uninstall().
*/
function link_uninstall() {
variable_del('link_allowed_domains');
}
/**
* Implements hook_field_schema().
*/
@@ -46,19 +74,21 @@ function link_update_last_removed() {
}
/**
* Handles moving settings data from field_config.data to field_config_instance.data.
* Implements hook_update_N().
*
* Handles moving settings data from field_config.data to
* field_config_instance.data.
*/
function link_update_7000() {
// For each field that is a link field, we need to copy the settings from the general field level down to the instance.
//$field_data = array();
// For each field that is a link field, we need to copy the settings from the
// general field level down to the instance.
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
foreach ($result as $field) {
$field_id = $field->id;
$name = $field->field_name;
$field_data = unserialize($field->data);
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
foreach ($instances as $instance) {
// If this field has been updated already, we want to skip it.
$instance_data = unserialize($instance->data);
@@ -71,8 +101,8 @@ function link_update_7000() {
}
}
if ($update_instance) {
// update the database.
$num_updated = db_update('field_config_instance')
// Update the database.
db_update('field_config_instance')
->fields(array('data' => serialize($instance_data)))
->condition('id', $instance->id)
->execute();
@@ -80,22 +110,19 @@ function link_update_7000() {
}
}
}
return t("Instance settings have been set with the data from the field settings.");
}
/**
* Renames all displays from foobar to link_foobar
* Renames all displays from foobar to link_foobar.
*/
function link_update_7001() {
// Update the display type for each link field type.
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
foreach ($result as $field) {
$field_id = $field->id;
$name = $field->field_name;
$field_data = unserialize($field->data);
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
foreach ($instances as $instance) {
// If this field has been updated already, we want to skip it.
$instance_data = unserialize($instance->data);
@@ -115,17 +142,3 @@ function link_update_7001() {
}
}
}
/**
* Removes unused link_extra_domains variable.
*/
function link_update_7002() {
variable_del('link_extra_domains');
}
/**
* Implements hook_uninstall().
*/
function link_uninstall() {
variable_del('link_allowed_domains');
}

View File

@@ -11,11 +11,9 @@
* $this->addFieldMapping('field_my_link', 'source_url');
* $this->addFieldMapping('field_my_link:title', 'source_title');
* $this->addFieldMapping('field_my_link:attributes', 'source_attributes');
* @endcode
*
* With earlier versions of Migrate, you must pass an arguments array:
* # With earlier versions of Migrate, you must pass an arguments array:
*
* @code
* $link_args = array(
* 'title' => array('source_field' => 'source_title'),
* 'attributes' => array('source_field' => 'source_attributes'),
@@ -25,6 +23,10 @@
* @endcode
*/
if (!class_exists('MigrateFieldHandler')) {
return;
}
/**
* Implements hook_migrate_api().
*/
@@ -35,12 +37,20 @@ function link_migrate_api() {
);
}
// @codingStandardsIgnoreLine
class MigrateLinkFieldHandler extends MigrateFieldHandler {
/**
* Construct.
*/
public function __construct() {
$this->registerTypes(array('link_field'));
}
static function arguments($title = NULL, $attributes = NULL, $language = NULL) {
/**
* Arguments.
*/
public static function arguments($title = NULL, $attributes = NULL, $language = NULL) {
$arguments = array();
if (!is_null($title)) {
$arguments['title'] = $title;
@@ -57,16 +67,21 @@ class MigrateLinkFieldHandler extends MigrateFieldHandler {
/**
* Implementation of MigrateFieldHandler::fields().
*
* @param $type
* The field type.
* @param $instance
* Instance info for the field.
* @param array $type
* The field type.
* @param array $instance
* Instance info for the field.
* @param Migration $migration
* The migration context for the parent field. We can look at the mappings
* and determine which subfields are relevant.
* The migration context for the parent field. We can look at the mappings
* and determine which subfields are relevant.
*
* @return array
* Array with values.
*
* @codingStandardsIgnoreStart
*/
public function fields($type, $instance, $migration = NULL) {
// @codingStandardsIgnoreEnd
return array(
'title' => t('Subfield: The link title attribute'),
'attributes' => t('Subfield: The attributes for this link'),
@@ -74,6 +89,9 @@ class MigrateLinkFieldHandler extends MigrateFieldHandler {
);
}
/**
* Prepare.
*/
public function prepare($entity, array $field_info, array $instance, array $values) {
if (isset($values['arguments'])) {
$arguments = $values['arguments'];
@@ -105,9 +123,17 @@ class MigrateLinkFieldHandler extends MigrateFieldHandler {
}
}
$item['url'] = $value;
$return[$language][$delta] = $item;
if (is_array($language)) {
$current_language = $language[$delta];
}
else {
$current_language = $language;
}
$return[$current_language][$delta] = $item;
}
return isset($return) ? $return : NULL;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,11 @@
* Basic simpletests to test options on link module.
*/
/**
* Attribute Crud Test.
*/
class LinkAttributeCrudTest extends DrupalWebTestCase {
private $zebra;
protected $permissions = array(
@@ -19,6 +23,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
'access administration pages',
);
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link Attribute Tests',
@@ -27,16 +34,23 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
);
}
function setup() {
/**
* Setup.
*/
public function setup() {
parent::setup('field_ui', 'link');
$this->zebra = 0;
// Create and login user.
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
));
$this->drupalLogin($this->web_user);
}
/**
* Create Link.
*/
protected function createLink($url, $title, $attributes = array()) {
return array(
'url' => $url,
@@ -45,20 +59,26 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
);
}
/**
* Assert Link On Node.
*/
protected function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
$this->zebra++;
$zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd';
$cssFieldLocator = 'field-' . str_replace('_', '-', $field_name);
$this->assertPattern('@<div class="field field-type-link ' . $cssFieldLocator . '".*<div class="field-item ' . $zebra_string . '">\s*' . $link_value . '\s*</div>@is',
$message,
$group);
$message,
$group);
}
/**
* A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure
* that the node is being displayed.
* Test Basic.
*
* A simple test that just creates a new node type, adds a link field to it,
* creates a new node of that type, and makes sure that the node is being
* displayed.
*/
function testBasic() {
public function testBasic() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$title = $this->randomName(20);
@@ -78,7 +98,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// 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;
$edit = array(
'fields[_add_new_field][label]' => $single_field_name_friendly,
'fields[_add_new_field][field_name]' => $single_field_name_machine,
@@ -103,7 +123,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
$permission = 'create ' . $content_type_machine . ' content';
$permission_edit = 'edit ' . $content_type_machine . ' content';
// Reset the permissions cache.
$this->checkPermissions(array($permission), TRUE);
@@ -124,7 +144,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
$this->assertText(t('@content_type_friendly @title has been created', array(
'@content_type_friendly' => $content_type_friendly,
'@title' => $title,
)));
$this->drupalGet('node/add/' . $content_type_machine);
@@ -137,12 +160,18 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// Now we can fill in the second item in the multivalue field and save.
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
$this->assertText(t('@content_type_friendly @title has been created', array(
'@content_type_friendly' => $content_type_friendly,
'@title' => $title,
)));
$this->assertText('Display');
$this->assertLinkByHref('http://www.example.com');
}
/**
* Create Simple Link Field.
*/
protected function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) {
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/fields');
$edit = array(
@@ -168,9 +197,11 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
}
/**
* Create Node Type User.
*/
protected function createNodeTypeUser($content_type_machine) {
$permission = 'create ' . $content_type_machine . ' content';
$permission_edit = 'edit ' . $content_type_machine . ' content';
// Reset the permissions cache.
$this->checkPermissions(array($permission), TRUE);
@@ -181,6 +212,9 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->drupalLogin($this->web_user);
}
/**
* Create Node For Testing.
*/
protected function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') {
$this->drupalGet('node/add/' . $content_type_machine);
@@ -198,14 +232,17 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
}
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $node_title)));
$this->assertText(t('@content_type_friendly @title has been created', array(
'@content_type_friendly' => $content_type_friendly,
'@title' => $node_title,
)));
}
/**
* Test the link_plain formatter and it's output.
*/
function testFormatterPlain() {
public function testFormatterPlain() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
@@ -217,7 +254,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// 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;
// $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:
@@ -229,7 +266,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_tests = array(
'plain' => array(
'text' => 'Display',
@@ -245,18 +282,21 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
),
);
foreach ($link_tests as $key => $link_test) {
foreach ($link_tests as $link_test) {
$link_text = $link_test['text'];
$link_url = $link_test['url'];
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_url);
$this->assertNoText($link_text);
$this->assertNoLinkByHref($link_url);
}
}
function testFormatterHost() {
/**
* Formatter Host.
*/
public function testFormatterHost() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
@@ -265,18 +305,17 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
'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;
// $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');
$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',
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
'fields[field_' . $single_field_name_machine . '][type]' => 'link_host',
);
$this->drupalPost(NULL, $edit, t('Save'));
@@ -291,7 +330,13 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->assertNoLinkByHref($link_url);
}
function testFormatterURL() {
/**
* Formatter URL.
*
* @codingStandardsIgnoreStart
*/
public function testFormatterURL() {
// @codingStandardsIgnoreEnd
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
@@ -303,7 +348,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// 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;
// $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:
@@ -315,7 +360,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_tests = array(
'plain' => array(
'text' => 'Display',
@@ -331,17 +376,20 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
),
);
foreach ($link_tests as $key => $link_test) {
foreach ($link_tests as $link_test) {
$link_text = $link_test['text'];
$link_url = $link_test['url'];
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
}
function testFormatterShort() {
/**
* Formatter Short.
*/
public function testFormatterShort() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
@@ -353,7 +401,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// 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;
// $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:
@@ -381,18 +429,21 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
),
);
foreach ($link_tests as $key => $link_test) {
foreach ($link_tests as $link_test) {
$link_text = $link_test['text'];
$link_url = $link_test['url'];
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText('Link');
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
}
function testFormatterLabel() {
/**
* Formatter Label.
*/
public function testFormatterLabel() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
@@ -404,7 +455,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// 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;
// $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:
@@ -432,18 +483,21 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
),
);
foreach ($link_tests as $key => $link_test) {
foreach ($link_tests as $link_test) {
$link_text = $link_test['text'];
$link_url = $link_test['url'];
$link_url = $link_test['url'];
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertText($single_field_name_friendly);
$this->assertLinkByHref($link_url);
}
}
function testFormatterSeparate() {
/**
* Formatter Separate.
*/
public function testFormatterSeparate() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
@@ -455,7 +509,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// 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;
// $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:
@@ -484,32 +538,35 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
),
);
foreach ($link_tests as $key => $link_test) {
foreach ($link_tests as $link_test) {
$link_text = $link_test['text'];
$link_url = $link_test['url'];
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_text);
$this->assertLink($plain_url);
$this->assertLinkByHref($link_url);
}
}
function testFormatterPlainTitle() {
/**
* Formatter Plain Title.
*/
public function testFormatterPlainTitle() {
$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;
// $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(
@@ -517,15 +574,16 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
'fields[field_' . $single_field_name_machine . '][type]' => 'link_title_plain',
);
$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($link_text);
$this->assertNoText($link_url);
$this->assertNoLinkByHref($link_url);
}
}

View File

@@ -2,11 +2,20 @@
/**
* @file
* Basic CRUD simpletests for the link module, based off of content.crud.test in CCK.
* File for Crud Tests.
*
* Basic CRUD simpletests for the link module, based off of content.crud.test in
* CCK.
*/
/**
* Content Crud.
*/
class LinkContentCrudTest extends DrupalWebTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link CRUD - Basic API tests',
@@ -15,24 +24,32 @@ class LinkContentCrudTest extends DrupalWebTestCase {
);
}
function setUp() {
/**
* Setup.
*/
public function setUp() {
parent::setUp('field_ui', 'link');
}
/**
* All we're doing here is creating a content type, creating a simple link field
* on that content type.
* Create Field API.
*
* All we're doing here is creating a content type, creating a simple link
* field on that content type.
*
* @codingStandardsIgnoreStart
*/
function testLinkCreateFieldAPI() {
public function testLinkCreateFieldAPI() {
// @codingStandardsIgnoreEnd
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$title = $this->randomName(20);
// Create and login user.
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
));
$this->drupalLogin($this->web_user);
$this->drupalGet('admin/structure/types');
@@ -71,4 +88,5 @@ class LinkContentCrudTest extends DrupalWebTestCase {
$type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
}
}

View File

@@ -6,25 +6,28 @@
*/
/**
* Testing that users can not input bad URLs or labels
* Testing that users can not input bad URLs or labels.
*/
class LinkUITest extends DrupalWebTestcase {
/**
* Link supposed to be good
* Link supposed to be good.
*/
const LINK_INPUT_TYPE_GOOD = 0;
/**
* Link supposed to have a bad title
* Link supposed to have a bad title.
*/
const LINK_INPUT_TYPE_BAD_TITLE = 1;
/**
* Link supposed to have a bad URL
* Link supposed to have a bad URL.
*/
const LINK_INPUT_TYPE_BAD_URL = 2;
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link CRUD - browser test',
@@ -33,22 +36,30 @@ class LinkUITest extends DrupalWebTestcase {
);
}
function setUp() {
/**
* Setup.
*/
public function setUp() {
parent::setUp('field_ui', 'link');
}
/**
* Creates a link field for the "page" type and creates a page with a link.
*/
function testLinkCreate() {
//libxml_use_internal_errors(true);
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
public function testLinkCreate() {
// libxml_use_internal_errors(true);
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'administer nodes',
'administer filters',
'access content',
'create page content',
'access administration pages',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -68,8 +79,8 @@ class LinkUITest extends DrupalWebTestcase {
$permission = 'create page content';
$this->checkPermissions(array($permission), TRUE);
// create page form
//$this->drupalGet('node/add');
// Create page form
// $this->drupalGet('node/add');.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
@@ -80,37 +91,37 @@ class LinkUITest extends DrupalWebTestcase {
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
'msg' => 'Link found',
'type' => self::LINK_INPUT_TYPE_GOOD
'type' => self::LINK_INPUT_TYPE_GOOD,
),
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '<script>alert("hi");</script>',
'msg' => 'js label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '<script src="http://devil.site.com"></script>',
'msg' => 'js label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '" onmouseover="alert(\'hi\')',
'msg' => 'js label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')',
'msg' => 'js label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
'type' => self::LINK_INPUT_TYPE_BAD_TITLE,
),
array(
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
'label' => $this->randomName(),
'msg' => 'js url',
'type' => self::LINK_INPUT_TYPE_BAD_URL
'type' => self::LINK_INPUT_TYPE_BAD_URL,
),
array(
'href' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
@@ -129,7 +140,7 @@ class LinkUITest extends DrupalWebTestcase {
$input_test_cases[] = $test_case;
foreach ($input_test_cases as $input) {
$this->drupalLogin($admin);
$this->drupalLogin($this->web_user);
$this->drupalGet('node/add/page');
$edit = array(
@@ -139,23 +150,26 @@ class LinkUITest extends DrupalWebTestcase {
);
$this->drupalPost(NULL, $edit, t('Save'));
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
$this->assertRaw(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($input['href']))), 'Not a valid URL: ' . $input['href']);
$this->assertRaw(t('The value %value provided for %field is not a valid URL.', array(
'%field' => $name,
'%value' => trim($input['href']),
)), 'Not a valid URL: ' . $input['href']);
continue;
}
else {
$this->assertRaw(' ' . t('has been created.',
array('@type' => 'Basic Page', '%title' => $edit['title'])),
'Page created: ' . $input['href']);
array('@type' => 'Basic Page', '%title' => $edit['title'])),
'Page created: ' . $input['href']);
}
$url = $this->getUrl();
// change to Anonymous user.
// Change to Anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
//debug($this);
// If simpletest starts using something to override the error system, this will flag
// us and let us know it's broken.
// debug($this);
// If simpletest starts using something to override the error system, this
// will flag us and let us know it's broken.
$this->assertFalse(libxml_use_internal_errors(TRUE));
if (isset($input['expected_href'])) {
$path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]';
@@ -167,20 +181,27 @@ class LinkUITest extends DrupalWebTestcase {
libxml_use_internal_errors(FALSE);
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
}
//libxml_use_internal_errors(FALSE);
// libxml_use_internal_errors(FALSE);
}
/**
* Static Link Create.
*
* Testing that if you use <strong> in a static title for your link, that the
* title actually displays <strong>.
*/
function testStaticLinkCreate() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
public function testStaticLinkCreate() {
// create field
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// Create field.
$name = strtolower($this->randomName());
$field_name = 'field_' . $name;
$edit = array(
@@ -193,17 +214,18 @@ class LinkUITest extends DrupalWebTestcase {
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => '<strong>' . $name . '</strong>'), t('Save settings'));
'instance[settings][title_value]' => '<strong>' . $name . '</strong>',
), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName()
'href' => 'http://example.com/' . $this->randomName(),
);
$edit = array(
@@ -214,23 +236,32 @@ class LinkUITest extends DrupalWebTestcase {
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l('<strong>' . $name . '</strong>', $input['href'], array('html' => TRUE)));
}
/**
* Testing that if you have the title but no url, the title is not sanitized twice.
*/
function testCRUDTitleOnlyTitleNoLink() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
// create field
/**
* CRUD Title Only Title No Link.
*
* Testing that if you have the title but no url, the title is not sanitized
* twice.
*
* @codingStandardsIgnoreStart
*/
public function testCRUDTitleOnlyTitleNoLink() {
// @codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// Create field.
$name = strtolower($this->randomName());
$field_name = 'field_' . $name;
$edit = array(
@@ -247,8 +278,8 @@ class LinkUITest extends DrupalWebTestcase {
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -265,8 +296,8 @@ class LinkUITest extends DrupalWebTestcase {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
@@ -274,16 +305,26 @@ class LinkUITest extends DrupalWebTestcase {
}
/**
* 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.
* CRUD Create Field Defaults.
*
* 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.
*
* @codingStandardsIgnoreStart
*/
function testCRUDCreateFieldDefaults() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
public function testCRUDCreateFieldDefaults() {
// @codingStandardsIgnoreEnd
// create field
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -314,18 +355,26 @@ 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() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
// create field
/**
* CRUD Create Field With Class.
*
* 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.
*
* @codingStandardsIgnoreStart
*/
public function testCRUDCreateFieldWithClass() {
// @codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -360,9 +409,9 @@ class LinkUITest extends DrupalWebTestcase {
$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
// create page form.
$field_name = 'field_' . $name;
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -380,8 +429,8 @@ class LinkUITest extends DrupalWebTestcase {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
@@ -389,17 +438,25 @@ class LinkUITest extends DrupalWebTestcase {
$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.
/**
* CRUD Create Field With Two Classes.
*
* 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.
*
* @codingStandardsIgnoreStart
*/
function testCRUDCreateFieldWithTwoClasses() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
public function testCRUDCreateFieldWithTwoClasses() {
// @codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -434,9 +491,9 @@ class LinkUITest extends DrupalWebTestcase {
$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
// create page form.
$field_name = 'field_' . $name;
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -454,12 +511,13 @@ class LinkUITest extends DrupalWebTestcase {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This &amp; That');
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page.");
}
}

View File

@@ -6,10 +6,13 @@
*/
/**
* Testing that tokens can be used in link titles
* Testing that tokens can be used in link titles.
*/
class LinkEntityTokenTest extends LinkBaseTestClass {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link entity tokens test',
@@ -19,24 +22,27 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public 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
public function testFieldTokenNodeLoaded() {
// Create field.
$settings = array(
'instance[settings][enable_tokens]' => 0,
);
$field_name = $this->createLinkField('page',
$settings);
$settings);
// create page form
// Create page form.
$this->drupalGet('node/add/page');
//$field_name = 'field_' . $name;
// $field_name = 'field_' . $name;.
$this->assertField($field_name . '[und][0][title]', 'Title found');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -58,11 +64,11 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
'label' => $this->randomName(),
),
);
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');
// @codingStandardsIgnoreLine
// $this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');.
foreach ($token_url_tests as &$input) {
$this->drupalGet('node/add/page');
$edit = array(
'title' => $input['label'],
$field_name . '[und][0][title]' => $input['label'],
@@ -73,34 +79,37 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
$input['url'] = $url;
}
// change to anonymous user
// 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));
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.
* Field Token Node Viewed.
*
* Creates a link field, fills it, then uses a loaded and node_view'd node to
* test tokens.
*/
function testFieldTokenNodeViewed() {
// create field
public function testFieldTokenNodeViewed() {
// Create field.
$settings = array(
'instance[settings][enable_tokens]' => 0,
);
$field_name = $this->createLinkField('page',
$settings);
$settings);
// create page form
// Create page form.
$this->drupalGet('node/add/page');
//$field_name = 'field_' . $name;
// $field_name = 'field_' . $name;.
$this->assertField($field_name . '[und][0][title]', 'Title found');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -122,11 +131,12 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
'label' => $this->randomName(),
),
);
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');
//@codingStandardsIgnoreLine
// $this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');.
foreach ($token_url_tests as &$input) {
$this->drupalGet('node/add/page');
$edit = array(
'title' => $input['label'],
$field_name . '[und][0][title]' => $input['label'],
@@ -137,19 +147,18 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
$input['url'] = $url;
}
// change to anonymous user
// 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));
array('node' => $node));
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
}
}
}
}

View File

@@ -0,0 +1,191 @@
<?php
/**
* @file
* Tests that exercise the relative / absolute output of the link module.
*/
/**
* Testing that absolute / relative outputs match the expected format.
*/
class LinkMultilingualTestCase extends LinkBaseTestClass {
public function setUp() {
$modules = func_get_args();
$modules = (isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules);
$modules = array_merge($modules, array(
'locale',
'locale_test',
'translation',
));
$this->permissions = array_merge($this->permissions, array(
'administer site configuration',
'administer languages',
));
parent::setUp($modules);
}
/**
* Enables and configured language related stuff.
*/
public function setUpLanguage() {
global $language_url;
$this->drupalGet('admin/config/regional/language');
// Enable the path prefix for the default language: this way any un-prefixed
// URL must have a valid fallback value.
$edit = array('prefix' => 'en');
$this->drupalPost('admin/config/regional/language/edit/en', $edit, t('Save language'));
$language_url->prefix = $language_url->language;
// Add custom language - as we need more than 1 language to be multilingual.
// Code for the language.
$langcode = 'xx';
// The English name for the language.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $langcode,
'direction' => '0',
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
// Enable URL language detection and selection.
$edit = array('language[enabled][locale-url]' => 1);
$this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
language_negotiation_set(LANGUAGE_TYPE_INTERFACE, array(LOCALE_LANGUAGE_NEGOTIATION_URL));
// Reset static caching.
drupal_static_reset('language_list');
drupal_static_reset('locale_url_outbound_alter');
drupal_static_reset('locale_language_url_rewrite_url');
}
}
class LinkMultilingualPathTest extends LinkMultilingualTestCase {
public static function getInfo() {
return array(
'name' => 'Link language path prefix',
'description' => 'Tests that path properly work with language path prefixes.',
'group' => 'Link',
);
}
/**
* Creates a link field, fills it, then uses a loaded node to test paths.
*/
public function testLanguagePrefixedPaths() {
$this->setUpLanguage();
// Create fields.
// Field for absolute urls.
$field_name_absolute = $this->createLinkField('page');
// Field for relative urls.
$settings = array(
'instance[settings][absolute_url]' => FALSE,
);
$field_name_relative = $this->createLinkField('page', $settings);
// Check the node edit form.
$this->drupalGet('node/add/page');
$this->assertField($field_name_absolute . '[und][0][title]', 'Title absolute found');
$this->assertField($field_name_absolute . '[und][0][url]', 'URL absolute found');
$this->assertField($field_name_relative . '[und][0][title]', 'Title relative found');
$this->assertField($field_name_relative . '[und][0][url]', 'URL relative found');
// Create test content.
$url_tests = array(
1 => array(
'href' => 'http://dummy.com/' . $this->randomName(),
'label' => $this->randomName(),
),
2 => array(
'href' => 'node/1',
'label' => $this->randomName(),
),
3 => array(
'href' => 'node/1?property=value',
'label' => $this->randomName(),
'query' => array('property' => 'value'),
),
4 => array(
'href' => 'node/1#position',
'label' => $this->randomName(),
'fragment' => 'position',
),
5 => array(
'href' => 'node/1?property=value2#lower',
'label' => $this->randomName(),
'fragment' => 'lower',
'query' => array('property' => 'value2'),
),
);
foreach ($url_tests as $index => &$input) {
$this->drupalGet('node/add/page');
$edit = array(
'title' => $input['label'],
$field_name_absolute . '[und][0][title]' => $input['label'],
$field_name_absolute . '[und][0][url]' => $input['href'],
$field_name_relative . '[und][0][title]' => $input['label'],
$field_name_relative . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
$input['url'] = $url;
}
// Change to anonymous user.
$this->drupalLogout();
foreach (array_slice($url_tests, 1, NULL, TRUE) 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.");
$this->drupalGet('node/' . $index);
$relative_expected = url('node/1', array('absolute' => FALSE) + $input2);
$absolute_expected = url('node/1', array('absolute' => TRUE) + $input2);
$absolute_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_absolute) . '")]/div/div/a/@href');
$absolute_result = (string) reset($absolute_result);
$this->assertEqual($absolute_result, $absolute_expected, "Absolute url output ('" . $absolute_result . "') looks as expected ('" . $absolute_expected . "')");
$relative_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_relative) . '")]/div/div/a/@href');
$relative_result = (string) reset($relative_result);
$this->assertEqual($relative_result, $relative_expected, "Relative url output ('" . $relative_result . "') looks as expected ('" . $relative_expected . "')");
}
// Check if this works with the alias too.
// Add a path alias for node 1.
$path = array(
'source' => 'node/1',
'alias' => $url_tests[1]['label'],
);
path_save($path);
// Another iteration over the same nodes - this time they should use the
// path alias.
foreach (array_slice($url_tests, 1, NULL, TRUE) 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.");
$this->drupalGet('node/' . $index);
$relative_expected = url('node/1', array('absolute' => FALSE) + $input2);
$absolute_expected = url('node/1', array('absolute' => TRUE) + $input2);
$absolute_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_absolute) . '")]/div/div/a/@href');
$absolute_result = (string) reset($absolute_result);
$this->assertEqual($absolute_result, $absolute_expected, "Absolute alias-url output ('" . $absolute_result . "') looks as expected ('" . $absolute_expected . "')");
$relative_result = $this->xpath('//*[contains(@class, "field-name-' . drupal_clean_css_identifier($field_name_relative) . '")]/div/div/a/@href');
$relative_result = (string) reset($relative_result);
$this->assertEqual($relative_result, $relative_expected, "Relative alias-url output ('" . $relative_result . "') looks as expected ('" . $relative_expected . "')");
}
}
}

View File

@@ -5,10 +5,15 @@
* Link base test file - contains common functions for testing links.
*/
/**
* Base Test Class.
*/
class LinkBaseTestClass extends DrupalWebTestCase {
protected $permissions = array(
'access content',
'administer content types',
'administer fields',
'administer nodes',
'administer filters',
'access comments',
@@ -17,19 +22,23 @@ class LinkBaseTestClass extends DrupalWebTestCase {
'create page content',
);
function setUp() {
/**
* Setup.
*/
public function setUp() {
$modules = func_get_args();
$modules = (isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules);
$modules[] = 'field_ui';
$modules[] = 'link';
parent::setUp($modules);
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
$this->web_user = $this->drupalCreateUser($this->permissions);
$this->drupalLogin($this->web_user);
}
/**
* Create Link Field.
*/
protected function createLinkField($node_type = 'page', $settings = array()) {
$name = strtolower($this->randomName());
$edit = array(
@@ -50,4 +59,5 @@ class LinkBaseTestClass extends DrupalWebTestCase {
return $field_name;
}
}

View File

@@ -6,10 +6,13 @@
*/
/**
* Testing that tokens can be used in link titles
* Testing that tokens can be used in link titles.
*/
class LinkTokenTest extends LinkBaseTestClass {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link tokens - browser test',
@@ -19,34 +22,38 @@ class LinkTokenTest extends LinkBaseTestClass {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
parent::setUp(array('token'));
}
/**
* Creates a link field with a required title enabled for user-entered tokens.
*
* Creates a node with a token in the link title and checks the value.
*/
function testUserTokenLinkCreate() {
// create field
public function testUserTokenLinkCreate() {
// Create field.
$settings = array(
'instance[settings][enable_tokens]' => 1,
);
$field_name = $this->createLinkField('page',
$settings);
$settings);
// create page form
// Create page form.
$this->drupalGet('node/add/page');
//$field_name = 'field_' . $name;
// $field_name = 'field_' . $name;.
$this->assertField($field_name . '[und][0][title]', 'Title found');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
);
//$this->drupalLogin($this->web_user);
// $this->drupalLogin($this->web_user);.
$this->drupalGet('node/add/page');
$edit = array(
@@ -57,36 +64,37 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'] . ' page', $input['href']));
}
/**
* Creates a link field with a static title and an admin-entered token.
*
* Creates a node with a link and checks the title value.
*/
function testStaticTokenLinkCreate() {
public function testStaticTokenLinkCreate() {
// create field
// Create field.
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]');
'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]',
);
$field_name = $this->createLinkField('page', $settings);
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName()
'href' => 'http://example.com/' . $this->randomName(),
);
//$this->drupalLogin($this->web_user);
// $this->drupalLogin($this->web_user);.
$this->drupalGet('node/add/page');
$edit = array(
@@ -97,7 +105,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
@@ -106,30 +114,32 @@ class LinkTokenTest extends LinkBaseTestClass {
/**
* Creates a link field with a static title and an admin-entered token.
*
* Creates a node with a link and checks the title value.
*
* Basically, I want to make sure the [title-raw] token works, because it's a
* token that changes from node to node, where [type]'s always going to be the
* same.
*/
function testStaticTokenLinkCreate2() {
public function testStaticTokenLinkCreate2() {
// create field
// Create field.
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name . ' [node:title]');
'instance[settings][title_value]' => $name . ' [node:title]',
);
$field_name = $this->createLinkField('page', $settings);
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName()
'href' => 'http://example.com/' . $this->randomName(),
);
//$this->drupalLogin($this->web_user);
// $this->drupalLogin($this->web_user);.
$this->drupalGet('node/add/page');
$edit = array(
@@ -140,27 +150,32 @@ class LinkTokenTest extends LinkBaseTestClass {
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($name . ' ' . $name, $input['href']));
}
// This test doesn't seem to actually work, due to lack of 'title' in url.
function _test_Link_With_Title_Attribute_token_url_form() {
/* $this->loginWithPermissions($this->permissions);
/**
* This test doesn't seem to actually work, due to lack of 'title' in url.
*
* @codingStandardsIgnoreStart
*/
public function _test_Link_With_Title_Attribute_token_url_form() {
// @codingStandardsIgnoreEnd
/* $this->loginWithPermissions($this->permissions);
$this->acquireContentTypes(1);
$field_settings = array(
'type' => 'link',
'widget_type' => 'link',
'type_name' => $this->content_types[0]->name,
'attributes' => array(
'class' => '',
'target' => 'default',
'rel' => 'nofollow',
'title' => '',
),
'type' => 'link',
'widget_type' => 'link',
'type_name' => $this->content_types[0]->name,
'attributes' => array(
'class' => '',
'target' => 'default',
'rel' => 'nofollow',
'title' => '',
),
);
$field = $this->createField($field_settings, 0);
@@ -170,10 +185,10 @@ class LinkTokenTest extends LinkBaseTestClass {
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '['. $field_name .'-url]',
'enable_tokens' => TRUE);
'enable_tokens' => TRUE);
// @codingStandardsIgnoreLine
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
$edit, t('Save field settings'));
$edit, t('Save field settings'));
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));*/
$name = $this->randomName();
$settings = array(
@@ -183,12 +198,9 @@ class LinkTokenTest extends LinkBaseTestClass {
$field_name = $this->createLinkField('page', $settings);
// So, having saved this field_name, let's see if it works...
//$this->acquireNodes(1);
//$node = node_load($this->nodes[0]->nid);
//$this->drupalGet('node/'. $this->nodes[0]->nid);
// $this->acquireNodes(1);
// $node = node_load($this->nodes[0]->nid);
// $this->drupalGet('node/'. $this->nodes[0]->nid);.
$edit = array();
$test_link_url = 'http://www.example.com/test';
$edit[$field_name . '[und][0][url]'] = $test_link_url;
@@ -200,23 +212,28 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
// Make sure we get a new version!
//$node = node_load($this->nodes[0]->nid, NULL, TRUE);
// $node = node_load($this->nodes[0]->nid, NULL, TRUE);.
$this->assertText(t('Basic page @title has been updated.',
array('@title' => $name)));
array('@title' => $name)));
//$this->drupalGet('node/'. $node->nid);
// $this->drupalGet('node/'. $node->nid);.
$this->assertText($title, 'Make sure the link title/text shows');
$this->assertRaw(' title="' . $test_link_url . '"', "Do we show the link url as the title attribute?");
$this->assertNoRaw(' title="[' . $field_name . '-url]"');
$this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
//$this->fail($this->content);
// $this->fail($this->content);.
}
/**
* Link With Title Attribute token title form.
*
* If the title of the link is set to the title attribute, then the title
* attribute isn't supposed to show.
*
* @codingStandardsIgnoreStart
*/
function _test_Link_With_Title_Attribute_token_title_form() {
public function _test_Link_With_Title_Attribute_token_title_form() {
// @codingStandardsIgnoreEnd
$this->loginWithPermissions($this->permissions);
$this->acquireContentTypes(1);
$field_settings = array(
@@ -233,21 +250,20 @@ class LinkTokenTest extends LinkBaseTestClass {
$field = $this->createField($field_settings, 0);
$field_name = $field['field_name'];
$field_db_info = content_database_info($field);
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '[' . $field_name . '-title]',
'enable_tokens' => TRUE);
$edit = array(
'attributes[title]' => '[' . $field_name . '-title]',
'enable_tokens' => TRUE,
);
$this->drupalPost('admin/content/node-type/' . $url_type . '/fields/' . $field['field_name'],
$edit, t('Save field settings'));
$edit, t('Save field settings'));
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
// So, having saved this field_name, let's see if it works...
$this->acquireNodes(1);
$node = node_load($this->nodes[0]->nid);
$this->drupalGet('node/' . $this->nodes[0]->nid);
$edit = array();
@@ -260,24 +276,35 @@ class LinkTokenTest extends LinkBaseTestClass {
// Make sure we get a new version!
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
$this->assertText(t('@type @title has been updated.',
array('@title' => $node->title,
'@type' => $this->content_types[0]->name)));
array(
'@title' => $node->title,
'@type' => $this->content_types[0]->name,
)));
$this->drupalGet('node/' . $node->nid);
$this->assertText($title, 'Make sure the link title/text shows');
$this->assertNoRaw(' title="' . $title . '"', "We should not show the link title as the title attribute?");
$this->assertNoRaw(' title="[' . $field_name . '-title]"');
//$this->fail($this->content);
// $this->fail($this->content);.
}
/**
* Trying to set the url to contain a token.
* Trying to set the url to contain a token.
*
* @codingStandardsIgnoreStart
*/
function _testUserTokenLinkCreateInURL() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
public function _testUserTokenLinkCreateInURL() {
//@codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'_add_new_field[label]' => $name,
@@ -288,20 +315,21 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
'enable_tokens' => 1), t('Save field settings'));
'enable_tokens' => 1,
), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField($field_name . '[0][title]', 'Title found');
$this->assertField($field_name . '[0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
);
$this->drupalLogin($this->web_user);
@@ -315,22 +343,31 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] . '/page'));
//$this->fail($this->content);
// $this->fail($this->content);.
}
/**
* Trying to set the url to contain a token.
* Trying to set the url to contain a token.
*
* @codingStandardsIgnoreStart
*/
function _testUserTokenLinkCreateInURL2() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
public function _testUserTokenLinkCreateInURL2() {
// @codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'_add_new_field[label]' => $name,
@@ -341,20 +378,21 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
'enable_tokens' => 1), t('Save field settings'));
'enable_tokens' => 1,
), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField($field_name . '[0][title]', 'Title found');
$this->assertField($field_name . '[0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
);
$this->drupalLogin($this->web_user);
@@ -368,22 +406,34 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] . '/' . $this->web_user->uid));
}
/**
* Test that if you have a title and no url on a field which does not have tokens enabled,
* that the title is sanitized once.
* CRUD Title Only Title No Link.
*
* Test that if you have a title and no url on a field which does not have
* tokens enabled, that the title is sanitized once.
*
* @codingStandardsIgnoreStart
*/
function testCRUDTitleOnlyTitleNoLink2() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
public function testCRUDTitleOnlyTitleNoLink2() {
//@codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'access content',
'create page content',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$field_name = 'field_' . $name;
$edit = array(
@@ -401,8 +451,8 @@ class LinkTokenTest extends LinkBaseTestClass {
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -419,13 +469,12 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
// Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This &amp; That');
}
}

View File

@@ -5,8 +5,14 @@
* Tests that exercise the validation functions in the link module.
*/
/**
* Validate Test Case.
*/
class LinkValidateTestCase extends LinkBaseTestClass {
/**
* Create Link.
*/
protected function createLink($url, $title, $attributes = array()) {
return array(
'url' => $url,
@@ -17,8 +23,11 @@ class LinkValidateTestCase extends LinkBaseTestClass {
/**
* Takes a url, and sees if it can validate that the url is valid.
*
* @codingStandardsIgnoreStart
*/
protected function link_test_validate_url($url) {
// @codingStandardsIgnoreEnd
$field_name = $this->createLinkField();
@@ -26,11 +35,11 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$settings = array(
'title' => $label,
$field_name => array(
LANGUAGE_NONE=> array(
LANGUAGE_NONE => array(
array(
'title' => $label,
'url' => $url,
)
),
),
),
);
@@ -41,10 +50,17 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
}
}
/**
* Class for Validate Test.
*/
class LinkValidateTest extends LinkValidateTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link Validation Tests',
@@ -53,20 +69,35 @@ class LinkValidateTest extends LinkValidateTestCase {
);
}
function test_link_validate_basic_url() {
/**
* Validate basic URL.
*
* @codingStandardsIgnoreStart
*/
public function test_link_validate_basic_url() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.example.com');
}
/**
* Test if we're stopped from posting a bad url on default validation.
*
* @codingStandardsIgnoreStart
*/
function test_link_validate_bad_url_validate_default() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
public function test_link_validate_bad_url_validate_default() {
// @codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'administer nodes',
'administer filters',
'access content',
'create page content',
'access administration pages',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -83,32 +114,43 @@ class LinkValidateTest extends LinkValidateTestCase {
node_types_rebuild();
menu_rebuild();
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('The value @value provided for @field is not a valid URL.', array('@value' => 'edik:naw', '@field' => $name)));
$this->assertText(t('The value @value provided for @field is not a valid URL.', array(
'@value' => 'edik:naw',
'@field' => $name,
)));
}
/**
* Test if we're stopped from posting a bad url with validation on.
*
* @codingStandardsIgnoreStart
*/
function test_link_validate_bad_url_validate_on() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
public function test_link_validate_bad_url_validate_on() {
// @codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'administer nodes',
'administer filters',
'access content',
'create page content',
'access administration pages',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -125,33 +167,44 @@ class LinkValidateTest extends LinkValidateTestCase {
node_types_rebuild();
menu_rebuild();
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('The value @value provided for @field is not a valid URL.', array('@field' => $name, '@value' => 'edik:naw')));
$this->assertText(t('The value @value provided for @field is not a valid URL.', array(
'@field' => $name,
'@value' => 'edik:naw',
)));
}
/**
* Test if we can post a bad url if the validation is expressly turned off.
*
* @codingStandardsIgnoreStart
*/
function test_link_validate_bad_url_validate_off() {
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
public function test_link_validate_bad_url_validate_off() {
// @codingStandardsIgnoreEnd
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'administer nodes',
'administer filters',
'access content',
'create page content',
'access administration pages',
));
$this->drupalLogin($this->web_user);
// create field
// Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -163,6 +216,7 @@ class LinkValidateTest extends LinkValidateTestCase {
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array('instance[settings][validate_url]' => FALSE), t('Save settings'));
// @codingStandardsIgnoreLine
/*$instance_details = db_query("SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = 'page'", array(':field_name' => 'field_'. $name))->fetchObject();
$this->fail('<pre>'. print_r($instance_details, TRUE) .'</pre>');
$this->fail('<pre>'. print_r(unserialize($instance_details->data), TRUE) .'</pre>');*/
@@ -172,48 +226,62 @@ class LinkValidateTest extends LinkValidateTestCase {
node_types_rebuild();
menu_rebuild();
// create page form
// Create page form.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => 'edik:naw')));
$this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
'%field' => $name,
'%value' => 'edik:naw',
)));
}
/**
* Test if a bad url can sneak through un-filtered if we play with the validation...
* Validate switching between validation status.
*
* Test if a bad url can sneak through un-filtered if we play with the
* validation...
*
* @codingStandardsIgnoreStart
*/
function x_test_link_validate_switching_between_validation_status() {
public function x_test_link_validate_switching_between_validation_status() {
// @codingStandardsIgnoreEnd
$this->acquireContentTypes(1);
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);
$this->drupalLogin($admin);
variable_set('node_options_' . $this->content_types[0]->name, array('status', 'promote'));
$this->web_user = $this->drupalCreateUser(array(
'administer content types',
'administer fields',
'administer nodes',
'access administration pages',
'access content',
'create ' . $this->content_types[0]->type . ' content',
'edit any ' . $this->content_types[0]->type . ' content',
));
$this->drupalLogin($this->web_user);
variable_set('node_options_' . $this->content_types[0]->name, array(
'status',
'promote',
));
$field_settings = array(
'type' => 'link',
'widget_type' => 'link',
'type_name' => $this->content_types[0]->name,
'attributes' => array(), // <-- This is needed or we have an error
// <-- This is needed or we have an error.
'attributes' => array(),
'validate_url' => 0,
);
$field = $this->createField($field_settings, 0);
//$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
$field_db_info = content_database_info($field);
$this->acquireNodes(2);
$node = node_load($this->nodes[0]->nid);
$this->drupalGet('node/' . $this->nodes[0]->nid);
$edit = array();
@@ -223,8 +291,13 @@ class LinkValidateTest extends LinkValidateTestCase {
$edit[$field['field_name'] . '[0][title]'] = $title;
$this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
//$this->pass($this->content);
$this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($url))));
// $this->pass($this->content);.
// @codingStandardsIgnoreLine
$this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
// @codingStandardsIgnoreLine
'%field' => $name,
'%value' => trim($url),
)));
// Make sure we get a new version!
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
@@ -236,8 +309,9 @@ class LinkValidateTest extends LinkValidateTestCase {
// Turn the array validation back _on_.
$edit = array('validate_url' => TRUE);
$node_type_link = str_replace('_', '-', $node->type);
//$this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
//$this->fail($this->content);
// @codingStandardsIgnoreLine
// $this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
// $this->fail($this->content);.
$this->drupalPost('admin/content/node-type/' . $node_type_link . '/fields/' . $field['field_name'], $edit, t('Save field settings'));
$this->drupalGet('node/' . $node->nid);
@@ -245,17 +319,26 @@ class LinkValidateTest extends LinkValidateTestCase {
// url() function. But we should have a test that makes sure it continues
// to work.
$this->assertNoRaw($url, 'Make sure Javascript does not display.');
//$this->fail($this->content);
// $this->fail($this->content);.
}
// Validate that '<front>' is a valid url.
function test_link_front_url() {
/**
* Validate that '<front>' is a valid url.
*
* @codingStandardsIgnoreStart
*/
public function test_link_front_url() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('<front>');
}
// Validate that an internal url would be accepted.
function test_link_internal_url() {
/**
* Validate that an internal url would be accepted.
*
* @codingStandardsIgnoreStart
*/
public function test_link_internal_url() {
// @codingStandardsIgnoreEnd
// Create the content first.
$node = $this->drupalCreateNode();
@@ -265,22 +348,46 @@ class LinkValidateTest extends LinkValidateTestCase {
$this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
}
// Validate a simple mailto.
function test_link_mailto() {
/**
* Validate a simple mailto.
*
* @codingStandardsIgnoreStart
*/
public function test_link_mailto() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('mailto:jcfiala@gmail.com');
}
function test_link_external_https() {
/**
* Check link external https.
*
* @codingStandardsIgnoreStart
*/
public function test_link_external_https() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('https://www.example.com/');
}
function test_link_ftp() {
/**
* Check link FTP.
*
* @codingStandardsIgnoreStart
*/
public function test_link_ftp() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('ftp://www.example.com/');
}
}
/**
* Validate Test News.
*/
class LinkValidateTestNews extends LinkValidateTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link News Validation Tests',
@@ -289,18 +396,36 @@ class LinkValidateTestNews extends LinkValidateTestCase {
);
}
// Validate a news link to a message group
function test_link_news() {
/**
* Validate a news link to a message group.
*
* @codingStandardsIgnoreStart
*/
public function test_link_news() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('news:comp.infosystems.www.misc');
}
// Validate a news link to a message id. Said ID copied off of google groups.
function test_link_news_message() {
/**
* Validate a news link to a message id. Said ID copied off of google groups.
*
* @codingStandardsIgnoreStart
*/
public function test_link_news_message() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
}
}
/**
* Validate Specific URL.
*/
class LinkValidateSpecificURL extends LinkValidateTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link Specific URL Validation Tests',
@@ -309,24 +434,53 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
);
}
// Lets throw in a lot of umlouts for testing!
function test_umlout_url() {
/**
* Lets throw in a lot of umlouts for testing!
*
* @codingStandardsIgnoreStart
*/
public function test_umlout_url() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://üÜü.exämple.com/nöde');
}
function test_umlout_mailto() {
/**
* Check umlout mailto.
*
* @codingStandardsIgnoreStart
*/
public function test_umlout_mailto() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('mailto:Üser@exÅmple.com');
}
function test_german_b_url() {
/**
* Check german b in url.
*
* @codingStandardsIgnoreStart
*/
public function test_german_b_url() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.test.com/ßstuff');
}
function test_special_n_url() {
/**
* Check Special in url.
*
* @codingStandardsIgnoreStart
*/
public function test_special_n_url() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.testÑñ.com/');
}
function test_curly_brackets_in_query() {
/**
* Curly Brackets in query.
*
* @codingStandardsIgnoreStart
*/
public function test_curly_brackets_in_query() {
// @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}');
}
@@ -334,8 +488,11 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
* Here, we're testing that a very long url is stored properly in the db.
*
* Basically, trying to test http://drupal.org/node/376818
*
* @codingStandardsIgnoreStart
*/
function testLinkURLFieldIsBig() {
public function testLinkURLFieldIsBig() {
// @codingStandardsIgnoreEnd
$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';
$this->link_test_validate_url($long_url);
}
@@ -343,12 +500,18 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
}
/**
* A series of tests of links, only going against the link_validate_url function in link.module.
* Validate Url Light.
*
* A series of tests of links, only going against the link_validate_url function
* in link.module.
*
* Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 !
*/
class LinkValidateUrlLight extends DrupalWebTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'Link Light Validation Tests',
@@ -357,66 +520,136 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
);
}
function setUp() {
/**
* Setup.
*/
public function setUp() {
parent::setUp('link');
}
/**
* Translates the LINK type constants to english for display and debugging of tests
* Name Link Type.
*
* Translates the LINK type constants to english for display and debugging of
* tests.
*
* @codingStandardsIgnoreStart
*/
function name_Link_Type($type) {
public function name_Link_Type($type) {
// @codingStandardsIgnoreEnd
switch ($type) {
case LINK_FRONT:
return "Front";
case LINK_EMAIL:
return "Email";
case LINK_TEL:
return "Telephone";
case LINK_NEWS:
return "Newsgroup";
case LINK_INTERNAL:
return "Internal Link";
case LINK_EXTERNAL:
return "External Link";
case FALSE:
return "Invalid Link";
default:
return "Bad Value:" . $type;
}
}
// Make sure that a link labeled <front> works.
function testValidateFrontLink() {
/**
* Make sure that a link labeled <front> works.
*/
public function testValidateFrontLink() {
$valid = link_validate_url('<front>');
$this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
}
function testValidateEmailLink() {
/**
* Validate Email Link.
*/
public function testValidateEmailLink() {
$valid = link_validate_url('mailto:bob@example.com');
$this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified");
}
function testValidateEmailLinkBad() {
/**
* Validate Email Link Bad.
*/
public function testValidateEmailLinkBad() {
$valid = link_validate_url(':bob@example.com');
$this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
}
function testValidateNewsgroupLink() {
function testValidateTelLinks() {
$links = array(
'tel:01',
'tel:123456789012345',
'tel:+123456789012345',
);
foreach ($links as $link) {
$type = link_url_type($link);
$this->assertEqual(LINK_TEL, $type, 'Test ' . $link . ' is a tel link.');
$valid = link_validate_url($link);
$this->assertTrue($valid, 'Test ' . $link . ' is valid tel link.');
}
}
function testValidateTelLinksBad() {
$links = array(
'tel:0',
'tel:1234567890123456',
'tel:+1',
'tel:+0123456789',
'tel:+1234567890123456',
':12345678',
);
foreach ($links as $link) {
$type = link_url_type($link);
$this->assertFalse($type, 'Test ' . $link . ' is not a tel link.');
$valid = link_validate_url($link);
$this->assertFalse($valid, 'Test ' . $link . ' is not a valid tel link.');
}
}
/**
* Validate Newsgroup Link.
*/
public function testValidateNewsgroupLink() {
$valid = link_validate_url('news:comp.infosystems.www.misc');
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.');
}
function testValidateNewsArticleLink() {
/**
* Validate News Article Link.
*/
public 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 validates as news.');
}
function testValidateBadNewsgroupLink() {
/**
* Validate Bad Newsgroup Link.
*/
public function testValidateBadNewsgroupLink() {
$valid = link_validate_url('news:comp.bad_name.misc');
$this->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.');
}
function testValidateInternalLinks() {
/**
* Validate Internal Links.
*/
public function testValidateInternalLinks() {
$tempfile = drupal_tempnam('public://files', 'test');
$links = array(
'rss.xml',
file_uri_target($tempfile),
drupal_realpath($tempfile),
);
@@ -429,7 +662,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
}
}
function testValidateExternalLinks() {
/**
* Validate External Links.
*/
public function testValidateExternalLinks() {
$links = array(
'http://localhost:8080/',
'www.example.com',
@@ -445,7 +681,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'www.test-site.com',
'http://example.com/index.php?q=node/123',
'http://example.com/?first_name=Joe Bob&last_name=Smith',
// Anchors
// Anchors.
'http://www.example.com/index.php#test',
'http://www.example.com/index.php#this@that.',
'http://www.example.com/index.php#',
@@ -453,8 +689,22 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up',
'http://www.example.com/blah/#this@that?',
);
// Test all of the protocols.
$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
$allowed_protocols = variable_get('filter_allowed_protocols', array(
'http',
'https',
'ftp',
'news',
'nntp',
'telnet',
'mailto',
'irc',
'ssh',
'sftp',
'webcal',
));
foreach ($allowed_protocols as $protocol) {
if ($protocol !== 'news' && $protocol !== 'mailto') {
$links[] = $protocol . '://www.example.com';
@@ -465,24 +715,28 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
$this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
$valid = link_validate_url($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.");
// 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.");.
}
// Test if we can make a tld allowable:
variable_set('link_allowed_domains', array('frog'));
$valid = link_validate_url('http://www.example.frog');
$this->assertEqual(LINK_EXTERNAL, $valid, "Testing that http://www.example.frog is a valid external link if we've added 'frog' to the list of valid domains.");
}
function testInvalidExternalLinks() {
/**
* Check Invalid External Links.
*/
public function testInvalidExternalLinks() {
$links = array(
'http://www.ex ample.com/',
'http://25.0.0/', // bad ip!
// Bad ip!
'http://25.0.0/',
'http://4827.0.0.2/',
'//www.example.com/',
'http://www.testß.com/', // ß not allowed in domain names!
//'http://www.-fudge.com/', // domains can't have sections starting with a dash.
// ß not allowed in domain names!
'http://www.testß.com/',
// Bad TLD.
'http://.www.foo.bar./',
// Domains can't have sections starting with a dash.
// 'http://www.-fudge.com/',
'http://example.com/index.php?page=this\that',
'example@example.com',
);
@@ -490,9 +744,6 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
$valid = link_validate_url($link);
$this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
}
// Test if we can make a tld disallowed:
variable_set('link_allowed_domains', array('toad'));
$valid = link_validate_url('http://www.example.frog');
$this->assertEqual(FALSE, $valid, "Testing that http://www.example.frog is an invalid external link if we've not added 'frog' to the list of valid domains.");
}
}

View File

@@ -1,113 +0,0 @@
<?php
/**
* @file
* Contains functions handling views integration.
*/
/**
* Implementation of hook_views_handlers().
*/
/*function link_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'link') .'/views',
),
'handlers' => array(
'link_views_handler_argument_target' => array(
'parent' => 'views_handler_argument',
),
'link_views_handler_filter_protocol' => array(
'parent' => 'views_handler_filter_string',
),
),
);
}*/
/**
* Return CCK Views data for the link_field_settings($op == 'views data').
*
* @TODO: Is there some way to tell views I have formatters for it?
*/
/*function link_views_content_field_data($field) {
// Build the automatic views data provided for us by CCK.
// This creates all the information necessary for the "url" field.
$data = content_views_field_views_data($field);
$db_info = content_database_info($field);
$table_alias = content_views_tablename($field);
$field_types = _content_field_types();
// Tweak the automatic views data for the link "url" field.
// Set the filter title to "@label URL"
$data[$table_alias][$field['field_name'] .'_url']['filter']['title'] = t('@label URL', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']);
// Remove the argument handling for URLs.
unset($data[$table_alias][$field['field_name'] .'_url']['argument']);
// Build out additional views data for the link "title" field.
$data[$table_alias][$field['field_name'] .'_title'] = array(
'group' => t('Content'),
'title' => t('@label title', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'help' => $data[$table_alias][$field['field_name'] .'_url']['help'],
'argument' => array(
'field' => $db_info['columns']['title']['column'],
'tablename' => $db_info['table'],
'handler' => 'content_handler_argument_string',
'click sortable' => TRUE,
'name field' => '', // TODO, mimic content.views.inc :)
'content_field_name' => $field['field_name'],
'allow_empty' => TRUE,
),
'filter' => array(
'field' => $db_info['columns']['title']['column'],
'title' => t('@label title', array('@label' => t($field_types[$field['type']]['label']))),
'tablename' => $db_info['table'],
'handler' => 'content_handler_filter_string',
'additional fields' => array(),
'content_field_name' => $field['field_name'],
'allow_empty' => TRUE,
),
'sort' => array(
'field' => $db_info['columns']['title']['column'],
'tablename' => $db_info['table'],
'handler' => 'content_handler_sort',
'content_field_name' => $field['field_name'],
'allow_empty' => TRUE,
),
);
// Build out additional Views filter for the link "protocol" pseudo field.
// TODO: Add a protocol argument.
$data[$table_alias][$field['field_name'] .'_protocol'] = array(
'group' => t('Content'),
'title' => t('@label protocol', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'help' => $data[$table_alias][$field['field_name'] .'_url']['help'],
'filter' => array(
'field' => $db_info['columns']['url']['column'],
'title' => t('@label protocol', array('@label' => t($field_types[$field['type']]['label']))),
'tablename' => $db_info['table'],
'handler' => 'link_views_handler_filter_protocol',
'additional fields' => array(),
'content_field_name' => $field['field_name'],
'allow_empty' => TRUE,
),
);
// Build out additional Views argument for the link "target" pseudo field.
// TODO: Add a target filter.
$data[$table_alias][$field['field_name'] .'_target'] = array(
'group' => t('Content'),
'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'help' => $data[$table_alias][$field['field_name'] .'_url']['help'],
'argument' => array(
'field' => $db_info['columns']['attributes']['column'],
'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'tablename' => $db_info['table'],
'handler' => 'link_views_handler_argument_target',
'additional fields' => array(),
'content_field_name' => $field['field_name'],
'allow_empty' => TRUE,
),
);
return $data;
}*/

View File

@@ -7,20 +7,26 @@
/**
* Argument handler to filter results by target.
*
* @codingStandardsIgnoreStart
*/
class link_views_handler_argument_target extends views_handler_argument {
/**
* Provide defaults for the argument when a new one is created.
*/
function options(&$options) {
parent::options($options);
}
function option_definition() {
$options = parent::option_definition();
return $options;
}
/**
* Provide a default options form for the argument.
*
* @codingStandardsIgnoreStart
*/
function options_form(&$form, &$form_state) {
public function options_form(&$form, &$form_state) {
// @codingStandardsIgnoreEnd
$defaults = $this->default_actions();
$form['title'] = array(
@@ -52,7 +58,7 @@ class link_views_handler_argument_target extends views_handler_argument {
$form['wildcard'] = array(
'#prefix' => '<div class="views-right-50">',
// prefix and no suffix means these two items will be grouped together.
// Prefix and no suffix means these two items will be grouped together.
'#type' => 'textfield',
'#title' => t('Wildcard'),
'#size' => 20,
@@ -125,8 +131,8 @@ class link_views_handler_argument_target extends views_handler_argument {
asort($validate_types);
$form['validate_type']['#options'] = $validate_types;
// Show this gadget if *anything* but 'none' is selected
// Show this gadget if *anything* but 'none' is selected.
$form['validate_fail'] = array(
'#type' => 'select',
'#title' => t('Action to take if argument does not validate'),
@@ -140,10 +146,11 @@ class link_views_handler_argument_target extends views_handler_argument {
*
* The argument sent may be found at $this->argument.
*/
function query($group_by = FALSE) {
public function query($group_by = FALSE) {
$this->ensure_my_table();
// Because attributes are stored serialized, our only option is to also
// serialize the data we're searching for and use LIKE to find similar data.
$this->query->add_where(0, $this->table_alias . ' . ' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument)));
}
}

View File

@@ -7,22 +7,29 @@
/**
* Filter handler for limiting a view to URLs of a certain protocol.
*
* @codingStandardsIgnoreStart
*/
class link_views_handler_filter_protocol extends views_handler_filter_string {
/**
* Set defaults for the filter options.
*/
function options(&$options) {
parent::options($options);
public function option_definition() {
// @codingStandardsIgnoreEnd
$options = parent::option_definition();
$options['operator'] = 'OR';
$options['value'] = 'http';
$options['case'] = 0;
return $options;
}
/**
* Define the operators supported for protocols.
*/
function operators() {
public function operators() {
$operators = array(
'OR' => array(
'title' => t('Is one of'),
@@ -35,7 +42,13 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
return $operators;
}
function options_form(&$form, &$form_state) {
/**
* Options form.
*
* @codingStandardsIgnoreStart
*/
public function options_form(&$form, &$form_state) {
//@codingStandardsIgnoreEnd
parent::options_form($form, $form_state);
$form['case'] = array(
'#type' => 'value',
@@ -45,8 +58,11 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
/**
* Provide a select list to choose the desired protocols.
*
* @codingStandardsIgnoreStart
*/
function value_form(&$form, &$form_state) {
public function value_form(&$form, &$form_state) {
// @codingStandardsIgnoreEnd
// We have to make some choices when creating this as an exposed
// filter form. For example, if the operator is locked and thus
// not rendered, we can't render dependencies; instead we only
@@ -61,7 +77,19 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
'#type' => 'select',
'#title' => t('Protocol'),
'#default_value' => $this->value,
'#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'))),
'#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array(
'http',
'https',
'ftp',
'news',
'nntp',
'telnet',
'mailto',
'irc',
'ssh',
'sftp',
'webcal',
))),
'#multiple' => 1,
'#size' => 4,
'#description' => t('The protocols displayed here are those globally available. You may add more protocols by modifying the <em>filter_allowed_protocols</em> variable in your installation.'),
@@ -71,8 +99,11 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
/**
* Filter down the query to include only the selected protocols.
*
* @codingStandardsIgnoreStart
*/
function op_protocol($field, $upper) {
public function op_protocol($field, $upper) {
// @codingStandardsIgnoreEnd
$db_type = db_driver();
$protocols = $this->value;
@@ -82,20 +113,25 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
// Simple case, the URL begins with the specified protocol.
$condition = $field . ' LIKE \'' . $protocol . '%\'';
// More complex case, no protocol specified but is automatically cleaned up
// by link_cleanup_url(). RegEx is required for this search operation.
// More complex case, no protocol specified but is automatically cleaned
// up by link_cleanup_url(). RegEx is required for this search operation.
if ($protocol == 'http') {
$LINK_DOMAINS = _link_domains();
$link_domains = _link_domains();
if ($db_type == 'pgsql') {
// PostGreSQL code has NOT been tested. Please report any problems to the link issue queue.
// pgSQL requires all slashes to be double escaped in regular expressions.
// PostGreSQL code has NOT been tested. Please report any problems to
// the link issue queue.
// pgSQL requires all slashes to be double escaped in regular
// expressions.
// @codingStandardsIgnoreLine
// See http://www.postgresql.org/docs/8.1/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
$condition .= ' OR ' . $field . ' ~* \'' . '^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
$condition .= ' OR ' . $field . ' ~* \'' . '^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\'';
}
else {
// mySQL requires backslashes to be double (triple?) escaped within character classes.
// mySQL requires backslashes to be double (triple?) escaped within
// character classes.
// @codingStandardsIgnoreLine
// See http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_regexp
$condition .= ' OR ' . $field . ' REGEXP \'' . '^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
$condition .= ' OR ' . $field . ' REGEXP \'' . '^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\'';
}
}
@@ -104,4 +140,5 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
$this->query->add_where($this->options['group'], implode(' ' . $this->operator . ' ', $where_conditions));
}
}