updated contrib modules
This commit is contained in:
101
sites/all/modules/link/README.txt
Normal file
101
sites/all/modules/link/README.txt
Normal file
@@ -0,0 +1,101 @@
|
||||
CONTENTS OF THIS FILE
|
||||
---------------------
|
||||
|
||||
* Introduction
|
||||
* Requirements
|
||||
* Installation
|
||||
* Configuration
|
||||
* Example
|
||||
* Theming and Output
|
||||
* Maintainers
|
||||
|
||||
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
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
|
||||
------------
|
||||
|
||||
Project in Drupal 7 requires the following modules:
|
||||
|
||||
* Fields API (Fields API is provided already by core)
|
||||
* Panels (https://drupal.org/project/panels)
|
||||
|
||||
Drupal 8:
|
||||
|
||||
* Link is in core now. No installation needed. Yay! Don't forget to activate
|
||||
it. It's deactivated by default.
|
||||
|
||||
|
||||
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
|
||||
-------
|
||||
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 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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
7
sites/all/modules/link/link-rtl.css
Normal file
7
sites/all/modules/link/link-rtl.css
Normal file
@@ -0,0 +1,7 @@
|
||||
.link-field-column {
|
||||
float: right;
|
||||
}
|
||||
.link-field-column.link-field-url .form-text {
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
div.link-field-column {
|
||||
.link-field-column {
|
||||
float: left;
|
||||
width: 48%;
|
||||
}
|
||||
|
||||
div.link-field-column .form-text {
|
||||
.link-field-column .form-text {
|
||||
width: 95%;
|
||||
}
|
||||
|
32
sites/all/modules/link/link.devel_generate.inc
Normal file
32
sites/all/modules/link/link.devel_generate.inc
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Devel Generate support for Link module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_devel_generate().
|
||||
*/
|
||||
function link_devel_generate($object, $field, $instance, $bundle) {
|
||||
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
|
||||
return devel_generate_multiple('_link_devel_generate', $object, $field, $instance, $bundle);
|
||||
}
|
||||
else {
|
||||
return _link_devel_generate($object, $field, $instance, $bundle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for hook_devel_generate().
|
||||
*/
|
||||
function _link_devel_generate($object, $field, $instance, $bundle) {
|
||||
$link = array(
|
||||
'url' => url('<front>', array('absolute' => TRUE)),
|
||||
'attributes' => _link_default_attributes(),
|
||||
);
|
||||
if ($instance['settings']['title'] != 'none') {
|
||||
$link['title'] = devel_create_greeking(mt_rand(1, 3), TRUE);
|
||||
}
|
||||
return $link;
|
||||
}
|
22
sites/all/modules/link/link.diff.inc
Normal file
22
sites/all/modules/link/link.diff.inc
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide diff field functions for the Link module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Diff field callback for parsing link fields comparative values.
|
||||
*/
|
||||
function link_field_diff_view($items, $context) {
|
||||
$diff_items = array();
|
||||
foreach ($items as $delta => $item) {
|
||||
if ($item['url'] && isset($item['title'])) {
|
||||
$diff_items[$delta] = $item['title'] . ' (' . $item['url'] . ')';
|
||||
}
|
||||
else {
|
||||
$diff_items[$delta] = $item['url'];
|
||||
}
|
||||
}
|
||||
return $diff_items;
|
||||
}
|
@@ -3,23 +3,23 @@ description = Defines simple link field types.
|
||||
core = 7.x
|
||||
package = Fields
|
||||
|
||||
files[] = link.module
|
||||
files[] = link.install
|
||||
files[] = link.migrate.inc
|
||||
|
||||
; Tests
|
||||
files[] = tests/link.test
|
||||
files[] = tests/link.attribute.test
|
||||
files[] = tests/link.crud.test
|
||||
files[] = tests/link.crud_browser.test
|
||||
files[] = tests/link.token.test
|
||||
files[] = tests/link.entity_token.test
|
||||
files[] = tests/link.validate.test
|
||||
|
||||
; Views Handlers
|
||||
files[] = views/link_views_handler_argument_target.inc
|
||||
files[] = views/link_views_handler_filter_protocol.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-10-23
|
||||
version = "7.x-1.0"
|
||||
; Information added by Drupal.org packaging script on 2019-02-20
|
||||
version = "7.x-1.6"
|
||||
core = "7.x"
|
||||
project = "link"
|
||||
datestamp = "1319392535"
|
||||
|
||||
datestamp = "1550680687"
|
||||
|
@@ -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_uninstall().
|
||||
*/
|
||||
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().
|
||||
*/
|
||||
@@ -18,20 +46,21 @@ function link_field_schema($field) {
|
||||
'columns' => array(
|
||||
'url' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 2048, // Maximum URLs length.
|
||||
// Maximum URLs length.
|
||||
'length' => 2048,
|
||||
'not null' => FALSE,
|
||||
'sortable' => TRUE
|
||||
'sortable' => TRUE,
|
||||
),
|
||||
'title' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'sortable' => TRUE
|
||||
'sortable' => TRUE,
|
||||
),
|
||||
'attributes' => array(
|
||||
'type' => 'text',
|
||||
'size' => 'medium',
|
||||
'not null' => FALSE
|
||||
'not null' => FALSE,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -45,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);
|
||||
@@ -70,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();
|
||||
@@ -79,36 +110,31 @@ 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() {
|
||||
// for each field that is a link field, we need to update the display types:
|
||||
|
||||
// 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);
|
||||
$update_instance = FALSE;
|
||||
foreach ($instance_data['display'] as $display_name => $display_data) {
|
||||
if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
|
||||
$instance_data['display'][$display_name]['type'] = 'link_'. $display_data['type'];
|
||||
$instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
|
||||
$update_instance = TRUE;
|
||||
}
|
||||
}
|
||||
if ($update_instance) {
|
||||
// update the database.
|
||||
$num_updated = db_update('field_config_instance')
|
||||
db_update('field_config_instance')
|
||||
->fields(array('data' => serialize($instance_data)))
|
||||
->condition('id', $instance->id)
|
||||
->execute();
|
||||
|
139
sites/all/modules/link/link.migrate.inc
Normal file
139
sites/all/modules/link/link.migrate.inc
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Support for migrate module.
|
||||
*
|
||||
* With Migrate 2.4 or later, you can use the subfield syntax to set the title
|
||||
* and attributes:
|
||||
*
|
||||
* @code
|
||||
* $this->addFieldMapping('field_my_link', 'source_url');
|
||||
* $this->addFieldMapping('field_my_link:title', 'source_title');
|
||||
* $this->addFieldMapping('field_my_link:attributes', 'source_attributes');
|
||||
*
|
||||
* # With earlier versions of Migrate, you must pass an arguments array:
|
||||
*
|
||||
* $link_args = array(
|
||||
* 'title' => array('source_field' => 'source_title'),
|
||||
* 'attributes' => array('source_field' => 'source_attributes'),
|
||||
* );
|
||||
* $this->addFieldMapping('field_my_link', 'source_url')
|
||||
* ->arguments($link_args);
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
if (!class_exists('MigrateFieldHandler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_migrate_api().
|
||||
*/
|
||||
function link_migrate_api() {
|
||||
return array(
|
||||
'api' => 2,
|
||||
'field handlers' => array('MigrateLinkFieldHandler'),
|
||||
);
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreLine
|
||||
class MigrateLinkFieldHandler extends MigrateFieldHandler {
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->registerTypes(array('link_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Arguments.
|
||||
*/
|
||||
public static function arguments($title = NULL, $attributes = NULL, $language = NULL) {
|
||||
$arguments = array();
|
||||
if (!is_null($title)) {
|
||||
$arguments['title'] = $title;
|
||||
}
|
||||
if (!is_null($attributes)) {
|
||||
$arguments['attributes'] = $attributes;
|
||||
}
|
||||
if (!is_null($language)) {
|
||||
$arguments['language'] = $language;
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of MigrateFieldHandler::fields().
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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'),
|
||||
'language' => t('Subfield: The language for the field'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare.
|
||||
*/
|
||||
public function prepare($entity, array $field_info, array $instance, array $values) {
|
||||
if (isset($values['arguments'])) {
|
||||
$arguments = $values['arguments'];
|
||||
unset($values['arguments']);
|
||||
}
|
||||
else {
|
||||
$arguments = array();
|
||||
}
|
||||
|
||||
$language = $this->getFieldLanguage($entity, $field_info, $arguments);
|
||||
$values = array_filter($values);
|
||||
|
||||
foreach ($values as $delta => $value) {
|
||||
$item = array();
|
||||
if (isset($arguments['title'])) {
|
||||
if (!is_array($arguments['title'])) {
|
||||
$item['title'] = $arguments['title'];
|
||||
}
|
||||
elseif (isset($arguments['title'][$delta])) {
|
||||
$item['title'] = $arguments['title'][$delta];
|
||||
}
|
||||
}
|
||||
if (isset($arguments['attributes'])) {
|
||||
if (is_array($arguments['attributes']) && isset($arguments['attributes'][$delta])) {
|
||||
$item['attributes'] = $arguments['attributes'][$delta];
|
||||
}
|
||||
else {
|
||||
$item['attributes'] = $arguments['attributes'];
|
||||
}
|
||||
}
|
||||
$item['url'] = $value;
|
||||
|
||||
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
File diff suppressed because it is too large
Load Diff
@@ -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,47 +24,53 @@ class LinkContentCrudTest extends DrupalWebTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('field_ui', 'link'); // was views?
|
||||
//$this->loginWithPermissions();
|
||||
/**
|
||||
* 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.
|
||||
$account = $this->drupalCreateUser(array('administer content types'));
|
||||
$this->drupalLogin($account);
|
||||
$this->web_user = $this->drupalCreateUser(array(
|
||||
'administer content types',
|
||||
'administer fields',
|
||||
));
|
||||
$this->drupalLogin($this->web_user);
|
||||
|
||||
$this->drupalGet('admin/structure/types');
|
||||
|
||||
// Create the content type.
|
||||
$this->clickLink(t('Add content type'));
|
||||
|
||||
|
||||
$edit = array (
|
||||
$edit = array(
|
||||
'name' => $content_type_friendly,
|
||||
'type' => $content_type_machine,
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save and add fields'));
|
||||
$this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
|
||||
|
||||
//$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
|
||||
// Now add a singleton field.
|
||||
$single_field_name_friendly = $this->randomName(20);
|
||||
$single_field_name_machine = strtolower($this->randomName(10));
|
||||
$edit = array (
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $single_field_name_friendly,
|
||||
'fields[_add_new_field][field_name]' => $single_field_name_machine,
|
||||
'fields[_add_new_field][type]' => 'link_field',
|
||||
'fields[_add_new_field][widget_type]' => 'link_field',
|
||||
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
@@ -72,14 +87,6 @@ class LinkContentCrudTest extends DrupalWebTestCase {
|
||||
menu_rebuild();
|
||||
$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.');
|
||||
|
||||
/*$table_schema = drupal_get_schema();
|
||||
$this->assertEqual(1, 1, print_r(array_keys($table_schema), TRUE));
|
||||
// Check the schema - the values should be in the per-type table.
|
||||
$this->assertSchemaMatchesTables(array(
|
||||
'per_type' => array(
|
||||
$this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),
|
||||
),
|
||||
));*/
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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,24 +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);
|
||||
$account = $this->drupalCreateUser(array('administer content types',
|
||||
'administer nodes',
|
||||
'administer filters',
|
||||
'access content',
|
||||
'create page content',
|
||||
'access administration pages'));
|
||||
$this->drupalLogin($account);
|
||||
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,
|
||||
@@ -70,62 +79,68 @@ 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');
|
||||
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
|
||||
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
|
||||
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
|
||||
|
||||
$input_test_cases = array(
|
||||
array(
|
||||
'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(
|
||||
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(
|
||||
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-',
|
||||
'label' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
|
||||
'msg' => 'Url with . in querystring',
|
||||
'type' => self::LINK_INPUT_TYPE_GOOD,
|
||||
),
|
||||
);
|
||||
$test_case = array(
|
||||
'href' => 'www.example.com/'. $this->randomName(),
|
||||
'href' => 'www.example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
'msg' => 'Link found',
|
||||
'type' => self::LINK_INPUT_TYPE_GOOD,
|
||||
);
|
||||
$test_case['expected_href'] = 'http://'. $test_case['href'];
|
||||
$test_case['expected_href'] = 'http://' . $test_case['href'];
|
||||
$input_test_cases[] = $test_case;
|
||||
|
||||
foreach ($input_test_cases as $input) {
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalLogin($this->web_user);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
@@ -135,158 +150,60 @@ class LinkUITest extends DrupalWebTestcase {
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
|
||||
$this->assertRaw(t('Not a valid URL.'), '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']);
|
||||
$this->assertRaw(' ' . t('has been created.',
|
||||
array('@type' => 'Basic Page', '%title' => $edit['title'])),
|
||||
'Page created: ' . $input['href']);
|
||||
}
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonym 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'] .'"]';
|
||||
$path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]';
|
||||
}
|
||||
else {
|
||||
$path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]';
|
||||
$path = '//a[@href="' . $input['href'] . '" and text()="' . $input['label'] . '"]';
|
||||
}
|
||||
//$this->pass(htmlentities($path));
|
||||
$elements = $this->xpath($path);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link field for the "page" type and creates a page with a link.
|
||||
* Just like the above test, only here we're turning off the validation on the field.
|
||||
*/
|
||||
/*function testLinkCreate_NoValidation() {
|
||||
//libxml_use_internal_errors(true);
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// create field
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $name,
|
||||
'fields[_add_new_field][field_name]' => $name,
|
||||
'fields[_add_new_field][type]' => 'link_field',
|
||||
'fields[_add_new_field][widget_type]' => 'link_field',
|
||||
);
|
||||
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
$this->drupalPost(NULL, array('validate_url' => FALSE), t('Save settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
|
||||
_content_type_info(TRUE);
|
||||
$fields = content_fields();
|
||||
$this->assertTRUE(0 === $fields['field_'. $name]['validate_url'], 'Make sure validation is off.');
|
||||
|
||||
// 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_test_cases = array(
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
'msg' => 'Link found',
|
||||
'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
|
||||
),
|
||||
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
|
||||
),
|
||||
array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName() . '" onmouseover="alert(\'hi\')',
|
||||
'msg' => 'js label',
|
||||
'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
|
||||
),
|
||||
array(
|
||||
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
|
||||
'label' => $this->randomName(),
|
||||
'msg' => 'js url',
|
||||
'type' => self::LINK_INPUT_TYPE_BAD_URL
|
||||
),
|
||||
);
|
||||
foreach ($input_test_cases as $input) {
|
||||
$this->drupalLogin($account);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
'title' => $input['label'],
|
||||
$field_name . '[0][title]' => $input['label'],
|
||||
$field_name . '[0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
|
||||
//$this->assertRaw(t('Not a valid URL.'), 'Not a valid URL: ' . $input['href']);
|
||||
$this->assertNoRaw($input['href']);
|
||||
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Basic Page', '%title' => $edit['title'])), 'Page created: ' . $input['href']);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Basic Page', '%title' => $edit['title'])), 'Page created: ' . $input['href']);
|
||||
}
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonym 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.
|
||||
$this->assertFalse(libxml_use_internal_errors(TRUE));
|
||||
$path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]';
|
||||
//$this->pass(htmlentities($path));
|
||||
$elements = $this->xpath($path);
|
||||
libxml_use_internal_errors(FALSE);
|
||||
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
|
||||
}
|
||||
//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() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
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;
|
||||
$field_name = 'field_' . $name;
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $name,
|
||||
'fields[_add_new_field][field_name]' => $name,
|
||||
@@ -297,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(
|
||||
@@ -318,22 +236,95 @@ 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)));
|
||||
$this->assertRaw(l('<strong>' . $name . '</strong>', $input['href'], array('html' => TRUE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Title Only Title No Link.
|
||||
*
|
||||
* Testing that if you have the title but no url, the title is not sanitized
|
||||
* twice.
|
||||
*
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
function testCRUDCreateFieldDefaults() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
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
|
||||
// Create field.
|
||||
$name = strtolower($this->randomName());
|
||||
$field_name = 'field_' . $name;
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $name,
|
||||
'fields[_add_new_field][field_name]' => $name,
|
||||
'fields[_add_new_field][type]' => 'link_field',
|
||||
'fields[_add_new_field][widget_type]' => 'link_field',
|
||||
);
|
||||
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'instance[settings][url]' => 1,
|
||||
), t('Save settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
|
||||
|
||||
// Create page form.
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'title' => 'This & That',
|
||||
'href' => '',
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[und][0][title]' => $input['title'],
|
||||
$field_name . '[und][0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// Change to anonymous user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw('This & That');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function testCRUDCreateFieldDefaults() {
|
||||
// @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,
|
||||
@@ -349,25 +340,184 @@ class LinkUITest extends DrupalWebTestcase {
|
||||
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
|
||||
node_types_rebuild();
|
||||
menu_rebuild();
|
||||
//_content_type_info(TRUE);
|
||||
//$fields = content_fields();
|
||||
//$field = $fields['field_'. $name];
|
||||
//$field = field_info_field('field_'. $name);
|
||||
|
||||
_field_info_collate_fields(TRUE);
|
||||
$instances = field_info_instances('node', 'page');
|
||||
//$this->debug($instances);
|
||||
//$this->assert('debug', '<pre>'. print_r($instances, TRUE) .'</pre>', 'Debug');
|
||||
$instance = $instances['field_'. $name];
|
||||
//$this->assertTrue(1 === $instance['validate_url'], 'Make sure validation is on.');
|
||||
|
||||
$instance = $instances['field_' . $name];
|
||||
$this->assertFalse($instance['required'], 'Make sure field is not required.');
|
||||
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
|
||||
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be off by default.');
|
||||
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
|
||||
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
|
||||
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
|
||||
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
|
||||
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
|
||||
$this->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.');
|
||||
|
||||
//$this->fail('<pre>'. print_r($fields['field_'. $name], TRUE) .'</pre>');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
'fields[_add_new_field][field_name]' => $name,
|
||||
'fields[_add_new_field][type]' => 'link_field',
|
||||
'fields[_add_new_field][widget_type]' => 'link_field',
|
||||
);
|
||||
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
|
||||
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
$link_class_name = 'basic-link-' . strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'instance[settings][attributes][class]' => $link_class_name,
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
|
||||
node_types_rebuild();
|
||||
menu_rebuild();
|
||||
|
||||
_field_info_collate_fields(TRUE);
|
||||
$instances = field_info_instances('node', 'page');
|
||||
|
||||
$instance = $instances['field_' . $name];
|
||||
$this->assertFalse($instance['required'], 'Make sure field is not required.');
|
||||
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
|
||||
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
|
||||
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
|
||||
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
|
||||
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
|
||||
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
|
||||
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.');
|
||||
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
|
||||
|
||||
// Now, let's create a node with this field and make sure the link shows up:
|
||||
// create page form.
|
||||
$field_name = 'field_' . $name;
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'title' => 'This & That',
|
||||
'href' => 'http://www.example.com/',
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $field_name,
|
||||
$field_name . '[und][0][title]' => $input['title'],
|
||||
$field_name . '[und][0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// Change to anonymous user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw('This & That');
|
||||
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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.
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $name,
|
||||
'fields[_add_new_field][field_name]' => $name,
|
||||
'fields[_add_new_field][type]' => 'link_field',
|
||||
'fields[_add_new_field][widget_type]' => 'link_field',
|
||||
);
|
||||
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
|
||||
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
$link_class_name = 'basic-link ' . strtoupper($this->randomName());
|
||||
$edit = array(
|
||||
'instance[settings][attributes][class]' => $link_class_name,
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
|
||||
node_types_rebuild();
|
||||
menu_rebuild();
|
||||
|
||||
_field_info_collate_fields(TRUE);
|
||||
$instances = field_info_instances('node', 'page');
|
||||
|
||||
$instance = $instances['field_' . $name];
|
||||
$this->assertFalse($instance['required'], 'Make sure field is not required.');
|
||||
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
|
||||
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
|
||||
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
|
||||
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
|
||||
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
|
||||
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
|
||||
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.');
|
||||
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
|
||||
|
||||
// Now, let's create a node with this field and make sure the link shows up:
|
||||
// create page form.
|
||||
$field_name = 'field_' . $name;
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'title' => 'This & That',
|
||||
'href' => 'http://www.example.com/',
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $field_name,
|
||||
$field_name . '[und][0][title]' => $input['title'],
|
||||
$field_name . '[und][0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// Change to anonymous user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw('This & That');
|
||||
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page.");
|
||||
}
|
||||
|
||||
}
|
||||
|
164
sites/all/modules/link/tests/link.entity_token.test
Normal file
164
sites/all/modules/link/tests/link.entity_token.test
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains simpletests making sure entity_token integration works.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'description' => 'Tests that a link field appears properly in entity tokens',
|
||||
'group' => 'Link',
|
||||
'dependencies' => array('token', 'entity', 'entity_token'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function testFieldTokenNodeLoaded() {
|
||||
// Create field.
|
||||
$settings = array(
|
||||
'instance[settings][enable_tokens]' => 0,
|
||||
);
|
||||
$field_name = $this->createLinkField('page',
|
||||
$settings);
|
||||
|
||||
// Create page form.
|
||||
$this->drupalGet('node/add/page');
|
||||
// $field_name = 'field_' . $name;.
|
||||
$this->assertField($field_name . '[und][0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
||||
|
||||
$token_url_tests = array(
|
||||
1 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
2 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName() . '?property=value',
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
3 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName() . '#position',
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
4 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
);
|
||||
// @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'],
|
||||
$field_name . '[und][0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$url = $this->getUrl();
|
||||
$input['url'] = $url;
|
||||
}
|
||||
|
||||
// Change to anonymous user.
|
||||
$this->drupalLogout();
|
||||
|
||||
foreach ($token_url_tests as $index => $input2) {
|
||||
$node = node_load($index);
|
||||
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
||||
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
||||
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
|
||||
$assert_data = token_replace($token_name,
|
||||
array('node' => $node));
|
||||
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Field Token Node Viewed.
|
||||
*
|
||||
* Creates a link field, fills it, then uses a loaded and node_view'd node to
|
||||
* test tokens.
|
||||
*/
|
||||
public function testFieldTokenNodeViewed() {
|
||||
// Create field.
|
||||
$settings = array(
|
||||
'instance[settings][enable_tokens]' => 0,
|
||||
);
|
||||
$field_name = $this->createLinkField('page',
|
||||
$settings);
|
||||
|
||||
// Create page form.
|
||||
$this->drupalGet('node/add/page');
|
||||
// $field_name = 'field_' . $name;.
|
||||
$this->assertField($field_name . '[und][0][title]', 'Title found');
|
||||
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
||||
|
||||
$token_url_tests = array(
|
||||
1 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName(),
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
2 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName() . '?property=value',
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
3 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName() . '#position',
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
4 => array(
|
||||
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
|
||||
'label' => $this->randomName(),
|
||||
),
|
||||
);
|
||||
|
||||
//@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'],
|
||||
$field_name . '[und][0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$url = $this->getUrl();
|
||||
$input['url'] = $url;
|
||||
}
|
||||
|
||||
// Change to anonymous user.
|
||||
$this->drupalLogout();
|
||||
|
||||
foreach ($token_url_tests as $index => $input2) {
|
||||
$node = node_load($index);
|
||||
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
||||
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
||||
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
|
||||
$assert_data = token_replace($token_name,
|
||||
array('node' => $node));
|
||||
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -5,10 +5,15 @@
|
||||
* Link base test file - contains common functions for testing links.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base Test Class.
|
||||
*/
|
||||
class LinkBaseTestClass extends DrupalWebTestCase {
|
||||
public $permissions = array(
|
||||
|
||||
protected $permissions = array(
|
||||
'access content',
|
||||
'administer content types',
|
||||
'administer fields',
|
||||
'administer nodes',
|
||||
'administer filters',
|
||||
'access comments',
|
||||
@@ -17,21 +22,24 @@ class LinkBaseTestClass extends DrupalWebTestCase {
|
||||
'create page content',
|
||||
);
|
||||
|
||||
public $account;
|
||||
/**
|
||||
* 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);
|
||||
|
||||
function setUp($modules = array()) {
|
||||
if ($modules) {
|
||||
parent::setUp($modules);
|
||||
}
|
||||
else {
|
||||
parent::setUp('field_ui', 'link');
|
||||
}
|
||||
$this->account = $this->drupalCreateUser($this->permissions);
|
||||
$this->drupalLogin($this->account);
|
||||
$this->web_user = $this->drupalCreateUser($this->permissions);
|
||||
$this->drupalLogin($this->web_user);
|
||||
}
|
||||
|
||||
function createLinkField($node_type = 'page',
|
||||
$settings = array()) {
|
||||
/**
|
||||
* Create Link Field.
|
||||
*/
|
||||
protected function createLinkField($node_type = 'page', $settings = array()) {
|
||||
$name = strtolower($this->randomName());
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $name,
|
||||
@@ -39,8 +47,8 @@ class LinkBaseTestClass extends DrupalWebTestCase {
|
||||
'fields[_add_new_field][type]' => 'link_field',
|
||||
'fields[_add_new_field][widget_type]' => 'link_field',
|
||||
);
|
||||
$field_name = 'field_'. $name;
|
||||
$this->drupalPost('admin/structure/types/manage/'. $node_type .'/fields', $edit, t('Save'));
|
||||
$field_name = 'field_' . $name;
|
||||
$this->drupalPost('admin/structure/types/manage/' . $node_type . '/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
$this->drupalPost(NULL, $settings, t('Save settings'));
|
||||
|
||||
@@ -51,4 +59,5 @@ class LinkBaseTestClass extends DrupalWebTestCase {
|
||||
|
||||
return $field_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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,40 +22,38 @@ class LinkTokenTest extends LinkBaseTestClass {
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($modules = array()) {
|
||||
$modules[] = 'field_ui';
|
||||
$modules[] = 'link';
|
||||
$modules[] = 'token';
|
||||
parent::setUp($modules);
|
||||
/**
|
||||
* 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() {
|
||||
/*$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);*/
|
||||
|
||||
// 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($account);
|
||||
// $this->drupalLogin($this->web_user);.
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
@@ -63,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($account);
|
||||
// $this->drupalLogin($this->web_user);.
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
@@ -103,7 +105,7 @@ class LinkTokenTest extends LinkBaseTestClass {
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// change to anonymous user
|
||||
// Change to anonymous user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
@@ -112,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($account);
|
||||
// $this->drupalLogin($this->web_user);.
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
@@ -146,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->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);
|
||||
@@ -176,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(
|
||||
@@ -189,40 +198,42 @@ 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;
|
||||
$title = 'title_'. $this->randomName(20);
|
||||
$edit[$field_name .'[und][0][title]'] = $title;
|
||||
$edit[$field_name . '[und][0][url]'] = $test_link_url;
|
||||
$title = 'title_' . $this->randomName(20);
|
||||
$edit[$field_name . '[und][0][title]'] = $title;
|
||||
$edit['title'] = $name;
|
||||
|
||||
$this->drupalGet('node/add/page');
|
||||
$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->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(
|
||||
@@ -239,51 +250,61 @@ 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'));
|
||||
$this->drupalPost('admin/content/node-type/' . $url_type . '/fields/' . $field['field_name'],
|
||||
$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);
|
||||
$this->drupalGet('node/' . $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
|
||||
$title = 'title_'. $this->randomName(20);
|
||||
$edit[$field['field_name'] .'[0][title]'] = $title;
|
||||
$edit[$field['field_name'] . '[0][url]'] = 'http://www.example.com/test';
|
||||
$title = 'title_' . $this->randomName(20);
|
||||
$edit[$field['field_name'] . '[0][title]'] = $title;
|
||||
|
||||
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
|
||||
$this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
|
||||
|
||||
// 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->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->assertNoRaw(' title="' . $title . '"', "We should not show the link title as the title attribute?");
|
||||
$this->assertNoRaw(' title="[' . $field_name . '-title]"');
|
||||
// $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() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
public function _testUserTokenLinkCreateInURL() {
|
||||
//@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(
|
||||
'_add_new_field[label]' => $name,
|
||||
@@ -294,23 +315,24 @@ 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($account);
|
||||
$this->drupalLogin($this->web_user);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
@@ -321,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->assertRaw(l($input['label'], $input['href'] . '/page'));
|
||||
// $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() {
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
|
||||
$this->drupalLogin($account);
|
||||
public function _testUserTokenLinkCreateInURL2() {
|
||||
// @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(
|
||||
'_add_new_field[label]' => $name,
|
||||
@@ -347,23 +378,24 @@ 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($account);
|
||||
$this->drupalLogin($this->web_user);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$edit = array(
|
||||
@@ -374,10 +406,75 @@ 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'] .'/'. $account->uid));
|
||||
$this->assertRaw(l($input['label'], $input['href'] . '/' . $this->web_user->uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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.
|
||||
$name = strtolower($this->randomName());
|
||||
$field_name = 'field_' . $name;
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $name,
|
||||
'fields[_add_new_field][field_name]' => $name,
|
||||
'fields[_add_new_field][type]' => 'link_field',
|
||||
'fields[_add_new_field][widget_type]' => 'link_field',
|
||||
);
|
||||
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
$this->drupalPost(NULL, array(
|
||||
'instance[settings][url]' => 1,
|
||||
'instance[settings][enable_tokens]' => 0,
|
||||
), t('Save settings'));
|
||||
|
||||
// Is field created?
|
||||
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
|
||||
|
||||
// Create page form.
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
||||
|
||||
$input = array(
|
||||
'title' => 'This & That',
|
||||
'href' => '',
|
||||
);
|
||||
|
||||
$edit = array(
|
||||
'title' => $name,
|
||||
$field_name . '[und][0][title]' => $input['title'],
|
||||
$field_name . '[und][0][url]' => $input['href'],
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
$url = $this->getUrl();
|
||||
|
||||
// Change to anonymous user.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet($url);
|
||||
|
||||
$this->assertRaw('This & That');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,13 +5,15 @@
|
||||
* Tests that exercise the validation functions in the link module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validate Test Case.
|
||||
*/
|
||||
class LinkValidateTestCase extends LinkBaseTestClass {
|
||||
|
||||
function setUp($modules = array()) {
|
||||
parent::setUp($modules);
|
||||
}
|
||||
|
||||
function createLink($url, $title, $attributes = array()) {
|
||||
/**
|
||||
* Create Link.
|
||||
*/
|
||||
protected function createLink($url, $title, $attributes = array()) {
|
||||
return array(
|
||||
'url' => $url,
|
||||
'title' => $title,
|
||||
@@ -21,35 +23,44 @@ class LinkValidateTestCase extends LinkBaseTestClass {
|
||||
|
||||
/**
|
||||
* Takes a url, and sees if it can validate that the url is valid.
|
||||
*
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
public function link_test_validate_url($url) {
|
||||
protected function link_test_validate_url($url) {
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
$field_name = $this->createLinkField();
|
||||
|
||||
$permission = 'create page content';
|
||||
$this->checkPermissions(array($permission), TRUE);
|
||||
|
||||
$this->drupalGet('node/add/page');
|
||||
|
||||
$label = $this->randomName();
|
||||
$edit = array(
|
||||
$settings = array(
|
||||
'title' => $label,
|
||||
$field_name . '[und][0][title]' => $label,
|
||||
$field_name . '[und][0][url]' => $url,
|
||||
$field_name => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'title' => $label,
|
||||
'url' => $url,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t(' has been created.'), 'Node created');
|
||||
|
||||
$nid = 1; //$matches[1];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
$node = node_load($nid);
|
||||
$this->assertNotNull($node, ' has been created.', 'Node created');
|
||||
|
||||
$this->assertEqual($url, $node->{$field_name}['und'][0]['url']);
|
||||
$this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for Validate Test.
|
||||
*/
|
||||
class LinkValidateTest extends LinkValidateTestCase {
|
||||
|
||||
/**
|
||||
* Get Info.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Link Validation Tests',
|
||||
@@ -58,23 +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() {
|
||||
$account = $this->drupalCreateUser(array('administer content types',
|
||||
'administer nodes',
|
||||
'administer filters',
|
||||
'access content',
|
||||
'create page content',
|
||||
'access administration pages'));
|
||||
$this->drupalLogin($account);
|
||||
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,
|
||||
@@ -91,35 +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');
|
||||
|
||||
$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',
|
||||
$field_name . '[und][0][url]' => 'edik:naw',
|
||||
);
|
||||
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$this->assertText(t('Not a valid URL.'));
|
||||
$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() {
|
||||
$account = $this->drupalCreateUser(array('administer content types',
|
||||
'administer nodes',
|
||||
'administer filters',
|
||||
'access content',
|
||||
'create page content',
|
||||
'access administration pages'));
|
||||
$this->drupalLogin($account);
|
||||
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,
|
||||
@@ -136,36 +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');
|
||||
|
||||
$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',
|
||||
$field_name . '[und][0][url]' => 'edik:naw',
|
||||
);
|
||||
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$this->assertText(t('Not a valid URL.'));
|
||||
$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() {
|
||||
$account = $this->drupalCreateUser(array('administer content types',
|
||||
'administer nodes',
|
||||
'administer filters',
|
||||
'access content',
|
||||
'create page content',
|
||||
'access administration pages'));
|
||||
$this->drupalLogin($account);
|
||||
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,
|
||||
@@ -177,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>');*/
|
||||
@@ -186,113 +226,167 @@ 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');
|
||||
|
||||
$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',
|
||||
$field_name . '[und][0][url]' => 'edik:naw',
|
||||
);
|
||||
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$this->assertNoText(t('Not a valid URL.'));
|
||||
|
||||
$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);
|
||||
$account = $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($account);
|
||||
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);
|
||||
$this->drupalGet('node/' . $this->nodes[0]->nid);
|
||||
|
||||
$edit = array();
|
||||
$title = $this->randomName();
|
||||
$url = 'javascript:alert("http://example.com/' . $this->randomName() . '")';
|
||||
$edit[$field['field_name'] .'[0][url]'] = $url;
|
||||
$edit[$field['field_name'] .'[0][title]'] = $title;
|
||||
$edit[$field['field_name'] . '[0][url]'] = $url;
|
||||
$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('Not a valid URL.'));
|
||||
$this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
|
||||
// $this->pass($this->content);.
|
||||
// @codingStandardsIgnoreLine
|
||||
$this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
|
||||
'%field' => $name,
|
||||
'%value' => trim($url),
|
||||
)));
|
||||
|
||||
// Make sure we get a new version!
|
||||
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
|
||||
$this->assertEqual($url, $node->{$field['field_name']}[0]['url']);
|
||||
|
||||
$this->drupalGet('node/'. $node->nid);
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
$this->assertNoRaw($url, 'Make sure Javascript does not display.');
|
||||
|
||||
// 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);
|
||||
$this->drupalPost('admin/content/node-type/'. $node_type_link .'/fields/'. $field['field_name'], $edit, t('Save field settings'));
|
||||
// @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);
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
// This actually works because the display_url goes through the core
|
||||
// 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() {
|
||||
$this->link_test_validate_url('node/32');
|
||||
/**
|
||||
* Validate that an internal url would be accepted.
|
||||
*
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
public function test_link_internal_url() {
|
||||
// @codingStandardsIgnoreEnd
|
||||
// Create the content first.
|
||||
$node = $this->drupalCreateNode();
|
||||
|
||||
$link = 'node/' . $node->nid;
|
||||
$this->link_test_validate_url($link);
|
||||
$type = link_url_type($link);
|
||||
$this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
|
||||
}
|
||||
|
||||
// Validate a simple mailto.
|
||||
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',
|
||||
@@ -301,18 +395,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',
|
||||
@@ -321,33 +433,65 @@ 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}');
|
||||
}
|
||||
|
||||
/**
|
||||
* Here, we're testing that a very long url is stored properly in the db.
|
||||
*
|
||||
* Basicly, trying to test http://drupal.org/node/376818
|
||||
* Basically, trying to test http://drupal.org/node/376818
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
@@ -355,17 +499,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 {
|
||||
|
||||
//function setUp() {
|
||||
// do we need to include something here?
|
||||
//module_load_include('inc', 'link');
|
||||
//}
|
||||
|
||||
/**
|
||||
* Get Info.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Link Light Validation Tests',
|
||||
@@ -375,74 +520,117 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the LINK type constants to english for display and debugging of tests
|
||||
* Setup.
|
||||
*/
|
||||
function name_Link_Type($type) {
|
||||
public function setUp() {
|
||||
parent::setUp('link');
|
||||
}
|
||||
|
||||
/**
|
||||
* Name Link Type.
|
||||
*
|
||||
* Translates the LINK type constants to english for display and debugging of
|
||||
* tests.
|
||||
*
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
public function name_Link_Type($type) {
|
||||
// @codingStandardsIgnoreEnd
|
||||
switch ($type) {
|
||||
case LINK_FRONT:
|
||||
return "Front";
|
||||
|
||||
case LINK_EMAIL:
|
||||
return "Email";
|
||||
|
||||
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;
|
||||
return "Bad Value:" . $type;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that a link labelled <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 verfied and identified');
|
||||
$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() {
|
||||
/**
|
||||
* 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 valiates as news.');
|
||||
$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 testValidateInternalLink() {
|
||||
$valid = link_validate_url('node/5');
|
||||
$this->assertEqual(LINK_INTERNAL, $valid, 'Test normal internal link.');
|
||||
/**
|
||||
* Validate Internal Links.
|
||||
*/
|
||||
public 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.');
|
||||
$valid = link_validate_url($link);
|
||||
$this->assertTrue($valid, 'Test ' . $link . ' is valid internal link.');
|
||||
}
|
||||
}
|
||||
|
||||
function testValidateInternalLinkWithDot() {
|
||||
$valid = link_validate_url('rss.xml');
|
||||
$this->assertEqual(LINK_INTERNAL, $valid, 'Test rss.xml internal link.');
|
||||
}
|
||||
|
||||
function testValidateInternalLinkToFile() {
|
||||
$valid = link_validate_url('files/test.jpg');
|
||||
$this->assertEqual(LINK_INTERNAL, $valid, 'Test files/test.jpg internal link.');
|
||||
}
|
||||
|
||||
function testValidateExternalLinks() {
|
||||
/**
|
||||
* Validate External Links.
|
||||
*/
|
||||
public function testValidateExternalLinks() {
|
||||
$links = array(
|
||||
'http://localhost:8080/',
|
||||
'www.example.com',
|
||||
@@ -457,9 +645,8 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
|
||||
'http://255.255.255.255:4823/',
|
||||
'www.test-site.com',
|
||||
'http://example.com/index.php?q=node/123',
|
||||
'http://example.com/index.php?page=this\that',
|
||||
'http://example.com/?first_name=Joe Bob&last_name=Smith',
|
||||
// Anchors
|
||||
// Anchors.
|
||||
'http://www.example.com/index.php#test',
|
||||
'http://www.example.com/index.php#this@that.',
|
||||
'http://www.example.com/index.php#',
|
||||
@@ -467,34 +654,60 @@ 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';
|
||||
$links[] = $protocol . '://www.example.com';
|
||||
}
|
||||
}
|
||||
foreach ($links as $link) {
|
||||
$type = link_url_type($link);
|
||||
$this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
|
||||
$valid = link_validate_url($link);
|
||||
$this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that '. $link .' is a valid external link.');
|
||||
// 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.");
|
||||
$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.");.
|
||||
}
|
||||
}
|
||||
|
||||
function testInvalidExternalLinks() {
|
||||
/**
|
||||
* Check Invalid External Links.
|
||||
*/
|
||||
public function testInvalidExternalLinks() {
|
||||
$links = array(
|
||||
'http://www.ex ample.com/',
|
||||
'//www.example.com/',
|
||||
'http://25.0.0/', // bad ip!
|
||||
// Bad ip!
|
||||
'http://25.0.0/',
|
||||
'http://4827.0.0.2/',
|
||||
'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',
|
||||
);
|
||||
foreach ($links as $link) {
|
||||
$valid = link_validate_url($link);
|
||||
$this->assertEqual(FALSE, $valid, 'Testing that '. $link .' is not a valid link.');
|
||||
$this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains functions handling views integration.
|
||||
|
@@ -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,
|
||||
@@ -93,7 +99,7 @@ class link_views_handler_argument_target extends views_handler_argument {
|
||||
'#default_value' => $this->options['validate_type'],
|
||||
);
|
||||
|
||||
$validate_types = array('none' => t('<Basic validation>'));
|
||||
$validate_types = array('none' => t('- Basic validation -'));
|
||||
$plugins = views_fetch_plugin_data('argument validator');
|
||||
foreach ($plugins as $id => $info) {
|
||||
$valid = TRUE;
|
||||
@@ -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() {
|
||||
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)));
|
||||
$this->query->add_where(0, $this->table_alias . ' . ' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,22 +7,30 @@
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @codingStandardsIgnoreEnd
|
||||
*/
|
||||
function options(&$options) {
|
||||
parent::options($options);
|
||||
function option_definition() {
|
||||
$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 +43,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 +59,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 +78,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 +100,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;
|
||||
@@ -80,27 +112,34 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
|
||||
$where_conditions = array();
|
||||
foreach ($protocols as $protocol) {
|
||||
// Simple case, the URL begins with the specified protocol.
|
||||
$condition = $field .' LIKE \''. $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();
|
||||
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]))' . '\'';
|
||||
}
|
||||
}
|
||||
|
||||
$where_conditions[] = $condition;
|
||||
}
|
||||
|
||||
$this->query->add_where($this->options['group'], implode(' '. $this->operator .' ', $where_conditions));
|
||||
$this->query->add_where($this->options['group'], implode(' ' . $this->operator . ' ', $where_conditions));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user