first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -0,0 +1,8 @@
div.link-field-column {
float: left;
width: 48%;
}
div.link-field-column .form-text {
width: 95%;
}

View File

@@ -0,0 +1,25 @@
name = Link
description = Defines simple link field types.
core = 7.x
package = Fields
files[] = link.module
files[] = link.install
; 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.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"
core = "7.x"
project = "link"
datestamp = "1319392535"

View File

@@ -0,0 +1,118 @@
<?php
/**
* @file
* Install file for the link module.
*/
/**
* Upgrade notes:
* Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:
*/
/**
* Implements hook_field_schema().
*/
function link_field_schema($field) {
return array(
'columns' => array(
'url' => array(
'type' => 'varchar',
'length' => 2048, // Maximum URLs length.
'not null' => FALSE,
'sortable' => TRUE
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE
),
'attributes' => array(
'type' => 'text',
'size' => 'medium',
'not null' => FALSE
),
),
);
}
/**
* Implements hook_update_last_removed().
*/
function link_update_last_removed() {
return 6001;
}
/**
* 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();
$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));
foreach ($instances as $instance) {
// If this field has been updated already, we want to skip it.
$instance_data = unserialize($instance->data);
$update_instance = FALSE;
if (!isset($instance_data['settings']['title'])) {
foreach ($field_data['settings'] as $key => $value) {
if (!isset($instance_data['settings'][$key])) {
$instance_data['settings'][$key] = $value;
$update_instance = TRUE;
}
}
if ($update_instance) {
// update the database.
$num_updated = db_update('field_config_instance')
->fields(array('data' => serialize($instance_data)))
->condition('id', $instance->id)
->execute();
}
}
}
}
return t("Instance settings have been set with the data from the field settings.");
}
/**
* 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:
$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));
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'];
$update_instance = TRUE;
}
}
if ($update_instance) {
// update the database.
$num_updated = db_update('field_config_instance')
->fields(array('data' => serialize($instance_data)))
->condition('id', $instance->id)
->execute();
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,781 @@
<?php
/**
* @file
* Basic simpletests to test options on link module.
*/
class LinkAttributeCrudTest extends DrupalWebTestCase {
private $zebra;
public $permissions = array(
'access content',
'administer content types',
'administer nodes',
'administer filters',
'access comments',
'post comments',
'skip comment approval',
'access administration pages',
);
public static function getInfo() {
return array(
'name' => 'Link Attribute Tests',
'description' => 'Tests the field attributes, making sure they appear in various displayed situations.',
'group' => 'Link',
);
}
function setup() {
$this->zebra = 0;
parent::setup('field_ui', 'link'); // was 'views'
//$this->loginWithPermissions($this->permissions);
// Create and login user.
$account = $this->drupalCreateUser(array('administer content types'));
$this->drupalLogin($account);
}
function createLink($url, $title, $attributes = array()) {
return array(
'url' => $url,
'title' => $title,
'attributes' => $attributes,
);
}
private function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
$this->zebra++;
$zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd';
$cssFieldLocator = 'field-'. str_replace('_', '-', $field_name);
$this->assertPattern('@<div class="field field-type-link '. $cssFieldLocator .'".*<div class="field-item '. $zebra_string .'">\s*'. $link_value .'\s*</div>@is',
$message,
$group);
}
/**
* A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure
* that the node is being displayed.
*/
function testBasic() {
/*$this->acquireContentTypes(1);
variable_set('node_options_'. $this->content_types[0]->name, array('status', 'promote'));*/
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$title = $this->randomName(20);
$this->drupalGet('admin/structure/types');
// Create the content type.
$this->clickLink(t('Add content type'));
$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)));
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
$single_field_name = 'field_'. $single_field_name_machine;
$edit = array (
'fields[_add_new_field][label]' => $single_field_name_friendly,
'fields[_add_new_field][field_name]' => $single_field_name_machine,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$this->drupalPost(NULL, $edit, t('Save'));
// We'll go with the default settings for this run-through.
$this->drupalPost(NULL, array(), t('Save field settings'));
// Using all the default settings, so press the button.
$this->drupalPost(NULL, array(), t('Save settings'));
$this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
// Somehow clicking "save" isn't enough, and we have to do a
// node_types_rebuild().
node_types_rebuild();
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.');
$permission = 'create ' . $content_type_machine . ' content';
$permission_edit = 'edit ' . $content_type_machine . ' content';
// Reset the permissions cache.
$this->checkPermissions(array($permission), TRUE);
// Now that we have a new content type, create a user that has privileges
// on the content type.
$permissions = array_merge($this->permissions, array($permission));
$account = $this->drupalCreateUser($permissions);
$this->drupalLogin($account);
// Go to page.
$this->drupalGet('node/add/'. $content_type_machine);
// Add a node.
$edit = array(
'title' => $title,
'field_'. $single_field_name_machine. '[und][0][title]' => 'Link',
'field_'. $single_field_name_machine. '[und][0][url]' => 'http://www.drupal.org/',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
/*$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.
);
$field = $this->createField($field_settings, 0);
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
$field_db_info = content_database_info($field);*/
//$this->acquireNodes(2);
/*$node = $this->drupalCreateNode(array('type' => $content_type_machine,
'promote' => 1));
$test_nid = $node->nid;*/
//$node = node_load($this->nodes[0]->nid);
//$node->promote = 1; // We want this to show on front page for the teaser test.
/*$this->assert('debug', print_r($node, TRUE), 'Debug');
$node->{$single_field_name}['und'][0] = $this->createLink('http://www.example.com', 'Test Link');
node_save($node);
$this->assert('debug', print_r($node, TRUE), 'Debug');*/
//$this->drupalGet('node/'. $test_nid .'/edit');
$this->drupalGet('node/add/'. $content_type_machine);
// lets add a node:
$edit = array(
'title' => $title,
'field_' . $single_field_name_machine . '[und][0][url]' => 'http://www.example.com/',
'field_' . $single_field_name_machine . '[und][0][title]' => 'Display',
);
// Now we can fill in the second item in the multivalue field and save.
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
$this->assertText('Display');
//$this->assertText('http://www.example.com/');
$this->assertLinkByHref('http://www.example.com');
}
private function createNodeType($content_type_machine, $content_type_friendly) {
$this->drupalGet('admin/structure/types');
// Create the content type.
$this->clickLink(t('Add content type'));
$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)));
}
private function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) {
$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'));
// We'll go with the default settings for this run-through.
$this->drupalPost(NULL, array(), t('Save field settings'));
// Using all the default settings, so press the button.
$this->drupalPost(NULL, array(), t('Save settings'));
$this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
// Somehow clicking "save" isn't enough, and we have to do a
// node_types_rebuild().
node_types_rebuild();
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.');
}
function createNodeTypeUser($content_type_machine) {
$permission = 'create ' . $content_type_machine . ' content';
$permission_edit = 'edit ' . $content_type_machine . ' content';
// Reset the permissions cache.
$this->checkPermissions(array($permission), TRUE);
// Now that we have a new content type, create a user that has privileges
// on the content type.
$permissions = array_merge($this->permissions, array($permission));
$account = $this->drupalCreateUser($permissions);
$this->drupalLogin($account);
}
function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') {
// Go to page.
$this->drupalGet('node/add/'. $content_type_machine);
if (!$node_title) {
$node_title = $this->randomName(20);
}
$edit = array(
'title' => $node_title,
);
if ($url) {
$edit['field_' . $single_field_name_machine . '[und][0][url]'] = $url;
}
if ($title) {
$edit['field_' . $single_field_name_machine . '[und][0][title]'] = $title;
}
// Now we can fill in the second item in the multivalue field and save.
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $node_title)));
}
function testFormatterPlain() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_url);
$this->assertNoText($link_text);
$this->assertNoLinkByHref($link_url);
}
function testFormatterPlainWithQuerystring() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/?q=test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_url);
$this->assertNoText($link_text);
$this->assertNoLinkByHref($link_url);
}
function testFormatterPlainWithFragment() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/#test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_url);
$this->assertNoText($link_text);
$this->assertNoLinkByHref($link_url);
}
function testFormatterURL() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
function testFormatterURLWithQuerystring() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/?q=test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
function testFormatterURLWithAnchor() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/#test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
function testFormatterShort() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText('Link');
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
function testFormatterShortWithQuerystring() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/?q=test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText('Link');
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
function testFormatterShortWithFragment() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/#test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText('Link');
$this->assertNoText($link_text);
$this->assertLinkByHref($link_url);
}
function testFormatterLabel() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertText($single_field_name_friendly);
$this->assertLinkByHref($link_url);
}
function testFormatterLabelWithQuerystring() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/?q=test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertText($single_field_name_friendly);
$this->assertLinkByHref($link_url);
}
function testFormatterLabelWithFragment() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/#test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertNoText($link_text);
$this->assertText($single_field_name_friendly);
$this->assertLinkByHref($link_url);
}
function testFormatterSeparate() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = $this->randomName(20);
$link_url = 'http://www.example.com/';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_text);
$this->assertLink($link_url);
$this->assertLinkByHref($link_url);
}
function testFormatterSeparateWithQuerystring() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = $this->randomName(20);
$link_url = 'http://www.example.com/?q=test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_text);
$this->assertLink('http://www.example.com/');
$this->assertLinkByHref($link_url);
}
function testFormatterSeparateWithFragment() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = $this->randomName(20);
$link_url = 'http://www.example.com/#test';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_text);
$this->assertLink('http://www.example.com/');
$this->assertLinkByHref($link_url);
}
function testFormatterPlainTitle() {
$content_type_friendly = $this->randomName(20);
$content_type_machine = strtolower($this->randomName(10));
$this->createNodeType($content_type_machine, $content_type_friendly);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
//$single_field_name = 'field_'. $single_field_name_machine;
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_title_plain',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->createNodeTypeUser($content_type_machine);
$link_text = 'Display';
$link_url = 'http://www.example.com/';
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
$this->assertText($link_text);
$this->assertNoText($link_url);
$this->assertNoLinkByHref($link_url);
}
/**
* This test sees that we can create a link field with a defined class, and make sure
* that class displays properly when the link is displayed.
*/
/*function testLinkWithClassOnField() {
$this->acquireContentTypes(1);
$field_settings = array(
'type' => 'link',
'widget_type' => 'link',
'type_name' => $this->content_types[0]->name,
'attributes' => array(
'class' => 'test-class',
'target' => 'default',
'rel' => FALSE,
),
);
$field = $this->createField($field_settings, 0);
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
$field_db_info = content_database_info($field);
$this->acquireNodes(2);
$node = node_load($this->nodes[0]->nid);
$node->promote = 1; // We want this to show on front page for the teaser test.
$node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
node_save($node);
// Does this display on the node page?
$this->drupalGet('node/'. $this->nodes[0]->nid);
//$this->outputScreenContents('Link field with class', 'link_');
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
// Does this display on the front page?
$this->drupalGet('<front>');
// reset the zebra!
$this->zebra = 0;
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
}*/
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* @file
* Basic CRUD simpletests for the link module, based off of content.crud.test in CCK.
*/
class LinkContentCrudTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Link CRUD - Basic API tests',
'description' => 'Tests the field CRUD (create, read, update, delete) API.',
'group' => 'Link',
);
}
function setUp() {
parent::setUp('field_ui', 'link'); // was views?
//$this->loginWithPermissions();
}
/**
* All we're doing here is creating a content type, creating a simple link field
* on that content type.
*/
function testLinkCreateFieldAPI() {
$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->drupalGet('admin/structure/types');
// Create the content type.
$this->clickLink(t('Add content type'));
$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 (
'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'));
// We'll go with the default settings for this run-through.
$this->drupalPost(NULL, array(), t('Save field settings'));
// Using all the default settings, so press the button.
$this->drupalPost(NULL, array(), t('Save settings'));
$this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
// Somehow clicking "save" isn't enough, and we have to do a
// node_types_rebuild().
node_types_rebuild();
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')),
),
));*/
}
}

View File

@@ -0,0 +1,373 @@
<?php
/**
* @file
* Testing CRUD API in the browser.
*/
/**
* Testing that users can not input bad URLs or labels
*/
class LinkUITest extends DrupalWebTestcase {
/**
* Link supposed to be good
*/
const LINK_INPUT_TYPE_GOOD = 0;
/**
* Link supposed to have a bad title
*/
const LINK_INPUT_TYPE_BAD_TITLE = 1;
/**
* Link supposed to have a bad URL
*/
const LINK_INPUT_TYPE_BAD_URL = 2;
public static function getInfo() {
return array(
'name' => 'Link CRUD - browser test',
'description' => 'Tests the field CRUD (create, read, update, delete) API 2.',
'group' => 'Link',
);
}
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);
// 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(), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
$permission = 'create page content';
$this->checkPermissions(array($permission), TRUE);
// 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');
$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
),
);
$test_case = array(
'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'];
$input_test_cases[] = $test_case;
foreach ($input_test_cases as $input) {
$this->drupalLogin($account);
$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'));
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
$this->assertRaw(t('Not a valid URL.'), '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']);
}
$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));
if (isset($input['expected_href'])) {
$path = '//a[@href="'. $input['expected_href'] .'" and text()="'. $input['label'] .'"]';
}
else {
$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);
}
/**
* 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);
}*/
/**
* 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);
// 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][title]' => 'value',
'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
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'href' => 'http://example.com/' . $this->randomName()
);
$edit = array(
'title' => $name,
$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(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.
*/
function testCRUDCreateFieldDefaults() {
$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(), t('Save settings'));
// Is field created?
$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.');
$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->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>');
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* @file
* Link base test file - contains common functions for testing links.
*/
class LinkBaseTestClass extends DrupalWebTestCase {
public $permissions = array(
'access content',
'administer content types',
'administer nodes',
'administer filters',
'access comments',
'post comments',
'access administration pages',
'create page content',
);
public $account;
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);
}
function createLinkField($node_type = 'page',
$settings = array()) {
$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',
);
$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'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
return $field_name;
}
}

View File

@@ -0,0 +1,383 @@
<?php
/**
* @file
* Contains simpletests making sure token integration works.
*/
/**
* Testing that tokens can be used in link titles
*/
class LinkTokenTest extends LinkBaseTestClass {
public static function getInfo() {
return array(
'name' => 'Link tokens - browser test',
'description' => 'Tests including tokens in link titles, making sure they appear in node views.',
'group' => 'Link',
'dependencies' => array('token'),
);
}
function setUp($modules = array()) {
$modules[] = 'field_ui';
$modules[] = 'link';
$modules[] = 'token';
parent::setUp($modules);
}
/**
* 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
$settings = array(
'instance[settings][enable_tokens]' => 1,
);
$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');
$input = array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName(),
);
//$this->drupalLogin($account);
$this->drupalGet('node/add/page');
$edit = array(
'title' => $input['label'],
$field_name . '[und][0][title]' => $input['label'] . " [node:content-type:machine-name]",
$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(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() {
// create field
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name .' [node:content-type:machine-name]');
$field_name = $this->createLinkField('page', $settings);
// 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()
);
//$this->drupalLogin($account);
$this->drupalGet('node/add/page');
$edit = array(
'title' => $name,
$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(l($name . ' 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.
*
* 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() {
// create field
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name .' [node:title]');
$field_name = $this->createLinkField('page', $settings);
// 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()
);
//$this->drupalLogin($account);
$this->drupalGet('node/add/page');
$edit = array(
'title' => $name,
$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(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->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' => '',
),
);
$field = $this->createField($field_settings, 0);
//$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
$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 .'-url]',
'enable_tokens' => TRUE);
$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'])));*/
$name = $this->randomName();
$settings = array(
'instance[settings][attributes][rel]' => 'nofollow',
);
$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);
$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['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);
$this->assertText(t('Basic page @title has been updated.',
array('@title' => $name)));
//$this->drupalGet('node/'. $node->nid);
$this->assertText($title, 'Make sure the link title/text shows');
$this->assertRaw(' title="'. $test_link_url .'"', "Do we show the link url as the title attribute?");
$this->assertNoRaw(' title="['. $field_name .'-url]"');
$this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
//$this->fail($this->content);
}
/**
* If the title of the link is set to the title attribute, then the title
* attribute isn't supposed to show.
*/
function _test_Link_With_Title_Attribute_token_title_form() {
$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' => '',
),
);
$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);
$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);
$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;
$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)));
$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);
}
/**
* Trying to set the url to contain a token.
*/
function _testUserTokenLinkCreateInURL() {
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($account);
// create field
$name = strtolower($this->randomName());
$edit = array(
'_add_new_field[label]' => $name,
'_add_new_field[field_name]' => $name,
'_add_new_field[type]' => 'link',
'_add_new_field[widget_type]' => 'link',
);
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
'enable_tokens' => 1), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
// 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(),
);
$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'] . "/[type]",
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] .'/page'));
//$this->fail($this->content);
}
/**
* Trying to set the url to contain a token.
*/
function _testUserTokenLinkCreateInURL2() {
$account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($account);
// create field
$name = strtolower($this->randomName());
$edit = array(
'_add_new_field[label]' => $name,
'_add_new_field[field_name]' => $name,
'_add_new_field[type]' => 'link',
'_add_new_field[widget_type]' => 'link',
);
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
'enable_tokens' => 1), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
// 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(),
);
$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'] . "/[author-uid]",
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] .'/'. $account->uid));
}
}

View File

@@ -0,0 +1,501 @@
<?php
/**
* @file
* Tests that exercise the validation functions in the link module.
*/
class LinkValidateTestCase extends LinkBaseTestClass {
function setUp($modules = array()) {
parent::setUp($modules);
}
function createLink($url, $title, $attributes = array()) {
return array(
'url' => $url,
'title' => $title,
'attributes' => $attributes,
);
}
/**
* Takes a url, and sees if it can validate that the url is valid.
*/
public function link_test_validate_url($url) {
$field_name = $this->createLinkField();
$permission = 'create page content';
$this->checkPermissions(array($permission), TRUE);
$this->drupalGet('node/add/page');
$label = $this->randomName();
$edit = array(
'title' => $label,
$field_name . '[und][0][title]' => $label,
$field_name . '[und][0][url]' => $url,
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t(' has been created.'), 'Node created');
$nid = 1; //$matches[1];
$node = node_load($nid);
$this->assertEqual($url, $node->{$field_name}['und'][0]['url']);
}
}
class LinkValidateTest extends LinkValidateTestCase {
public static function getInfo() {
return array(
'name' => 'Link Validation Tests',
'description' => 'Tests the field validation.',
'group' => 'Link',
);
}
function test_link_validate_basic_url() {
$this->link_test_validate_url('http://www.example.com');
}
/**
* Test if we're stopped from posting a bad url on default validation.
*/
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);
// 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(), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name .'[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('Not a valid URL.'));
}
/**
* Test if we're stopped from posting a bad url with validation on.
*/
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);
// 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('instance[settings][validate_url]' => TRUE), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name .'[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('Not a valid URL.'));
}
/**
* Test if we can post a bad url if the validation is expressly turned off.
*/
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);
// 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('instance[settings][validate_url]' => FALSE), t('Save settings'));
/*$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>');*/
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name .'[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertNoText(t('Not a valid URL.'));
}
/**
* Test if a bad url can sneak through un-filtered if we play with the validation...
*/
function x_test_link_validate_switching_between_validation_status() {
$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'));
$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
'validate_url' => 0,
);
$field = $this->createField($field_settings, 0);
//$this->fail('<pre>'. print_r($field, TRUE) .'</pre>');
$field_db_info = content_database_info($field);
$this->acquireNodes(2);
$node = node_load($this->nodes[0]->nid);
$this->drupalGet('node/'. $this->nodes[0]->nid);
$edit = array();
$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;
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
//$this->pass($this->content);
$this->assertNoText(t('Not a valid 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->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'));
$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);
}
// Validate that '<front>' is a valid url.
function test_link_front_url() {
$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 a simple mailto.
function test_link_mailto() {
$this->link_test_validate_url('mailto:jcfiala@gmail.com');
}
function test_link_external_https() {
$this->link_test_validate_url('https://www.example.com/');
}
function test_link_ftp() {
$this->link_test_validate_url('ftp://www.example.com/');
}
}
class LinkValidateTestNews extends LinkValidateTestCase {
public static function getInfo() {
return array(
'name' => 'Link News Validation Tests',
'description' => 'Tests the field validation for usenet urls.',
'group' => 'Link',
);
}
// Validate a news link to a message group
function test_link_news() {
$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() {
$this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
}
}
class LinkValidateSpecificURL extends LinkValidateTestCase {
public static function getInfo() {
return array(
'name' => 'Link Specific URL Validation Tests',
'description' => 'Tests field validation with unusual urls',
'group' => 'Link',
);
}
// Lets throw in a lot of umlouts for testing!
function test_umlout_url() {
$this->link_test_validate_url('http://üÜü.exämple.com/nöde');
}
function test_umlout_mailto() {
$this->link_test_validate_url('mailto:Üser@exÅmple.com');
}
function test_german_b_url() {
$this->link_test_validate_url('http://www.test.com/ßstuff');
}
function test_special_n_url() {
$this->link_test_validate_url('http://www.testÑñ.com/');
}
function test_curly_brackets_in_query() {
$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
*/
function testLinkURLFieldIsBig() {
$long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A';
$this->link_test_validate_url($long_url);
}
}
/**
* 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');
//}
public static function getInfo() {
return array(
'name' => 'Link Light Validation Tests',
'description' => 'Tests the link_validate_url() function by itself, without invoking the full drupal/cck lifecycle.',
'group' => 'Link',
);
}
/**
* Translates the LINK type constants to english for display and debugging of tests
*/
function name_Link_Type($type) {
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;
}
}
// Make sure that a link labelled <front> works.
function testValidateFrontLink() {
$valid = link_validate_url('<front>');
$this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verfied and identified');
}
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() {
$valid = link_validate_url(':bob@example.com');
$this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
}
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() {
$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.');
}
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.');
}
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() {
$links = array(
'http://localhost:8080/',
'www.example.com',
'www.example.com/',
'http://username:p%40ssw0rd!@www.example.com/',
'http://@www.example.com/',
'http://username:@www.example.com/',
'http://username:password@www.example.com:8080/',
'http://127.0.0.1:80/',
'http://127.173.24.255:4723/',
'127.173.24.255:4723/',
'http://255.255.255.255:4823/',
'www.test-site.com',
'http://example.com/index.php?q=node/123',
'http://example.com/index.php?page=this\that',
'http://example.com/?first_name=Joe Bob&last_name=Smith',
// Anchors
'http://www.example.com/index.php#test',
'http://www.example.com/index.php#this@that.',
'http://www.example.com/index.php#',
'http://www.cnn.com/video/#/video/politics/2008/12/09/intv.madeleine.albright.cnn',
'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'));
foreach ($allowed_protocols as $protocol) {
if ($protocol !== 'news' && $protocol !== 'mailto') {
$links[] = $protocol .'://www.example.com';
}
}
foreach ($links as $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.");
}
}
function testInvalidExternalLinks() {
$links = array(
'http://www.ex ample.com/',
'//www.example.com/',
'http://25.0.0/', // bad ip!
'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.
);
foreach ($links as $link) {
$valid = link_validate_url($link);
$this->assertEqual(FALSE, $valid, 'Testing that '. $link .' is not a valid link.');
}
}
}

View File

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

View File

@@ -0,0 +1,149 @@
<?php
/**
* @file
* Argument handler to filter results by target.
*/
/**
* Argument handler to filter results by target.
*/
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);
}
/**
* Provide a default options form for the argument.
*/
function options_form(&$form, &$form_state) {
$defaults = $this->default_actions();
$form['title'] = array(
'#prefix' => '<div class="clear-block">',
'#suffix' => '</div>',
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $this->options['title'],
'#description' => t('The title to use when this argument is present; it will override the title of the view and titles from previous arguments. You can use percent substitution here to replace with argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
);
$form['clear_start'] = array(
'#value' => '<div class="clear-block">',
);
$form['defaults_start'] = array(
'#value' => '<div class="views-left-50">',
);
$form['default_action'] = array(
'#type' => 'radios',
'#title' => t('Action to take if argument is not present'),
'#default_value' => $this->options['default_action'],
);
$form['defaults_stop'] = array(
'#value' => '</div>',
);
$form['wildcard'] = array(
'#prefix' => '<div class="views-right-50">',
// prefix and no suffix means these two items will be grouped together.
'#type' => 'textfield',
'#title' => t('Wildcard'),
'#size' => 20,
'#default_value' => $this->options['wildcard'],
'#description' => t('If this value is received as an argument, the argument will be ignored; i.e, "all values"'),
);
$form['wildcard_substitution'] = array(
'#suffix' => '</div>',
'#type' => 'textfield',
'#title' => t('Wildcard title'),
'#size' => 20,
'#default_value' => $this->options['wildcard_substitution'],
'#description' => t('The title to use for the wildcard in substitutions elsewhere.'),
);
$form['clear_stop'] = array(
'#value' => '</div>',
);
$options = array();
$validate_options = array();
foreach ($defaults as $id => $info) {
$options[$id] = $info['title'];
if (empty($info['default only'])) {
$validate_options[$id] = $info['title'];
}
if (!empty($info['form method'])) {
$this->{$info['form method']}($form, $form_state);
}
}
$form['default_action']['#options'] = $options;
$form['validate_type'] = array(
'#type' => 'select',
'#title' => t('Validator'),
'#default_value' => $this->options['validate_type'],
);
$validate_types = array('none' => t('<Basic validation>'));
$plugins = views_fetch_plugin_data('argument validator');
foreach ($plugins as $id => $info) {
$valid = TRUE;
if (!empty($info['type'])) {
$valid = FALSE;
if (empty($this->definition['validate type'])) {
continue;
}
foreach ((array) $info['type'] as $type) {
if ($type == $this->definition['validate type']) {
$valid = TRUE;
break;
}
}
}
// If we decide this validator is ok, add it to the list.
if ($valid) {
$plugin = views_get_plugin('argument validator', $id);
if ($plugin) {
$plugin->init($this->view, $this, $id);
if ($plugin->access()) {
$plugin->validate_form($form, $form_state, $id);
$validate_types[$id] = $info['title'];
}
}
}
}
asort($validate_types);
$form['validate_type']['#options'] = $validate_types;
// 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'),
'#default_value' => $this->options['validate_fail'],
'#options' => $validate_options,
);
}
/**
* Set up the query for this argument.
*
* The argument sent may be found at $this->argument.
*/
function query() {
$this->ensure_my_table();
// Because attributes are stored serialized, our only option is to also
// serialize the data we're searching for and use LIKE to find similar data.
$this->query->add_where(0, $this->table_alias .'.'. $this->real_field ." LIKE '%%%s%'", serialize(array('target' => $this->argument)));
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* @file
* Contains filter handlers for protocol filters with views.
*/
/**
* Filter handler for limiting a view to URLs of a certain protocol.
*/
class link_views_handler_filter_protocol extends views_handler_filter_string {
/**
* Set defaults for the filter options.
*/
function options(&$options) {
parent::options($options);
$options['operator'] = 'OR';
$options['value'] = 'http';
$options['case'] = 0;
}
/**
* Define the operators supported for protocols.
*/
function operators() {
$operators = array(
'OR' => array(
'title' => t('Is one of'),
'short' => t('='),
'method' => 'op_protocol',
'values' => 1,
),
);
return $operators;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['case'] = array(
'#type' => 'value',
'#value' => 0,
);
}
/**
* Provide a select list to choose the desired protocols.
*/
function value_form(&$form, &$form_state) {
// 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
// render the form items we need.
$which = 'all';
if (!empty($form_state['exposed']) && empty($this->options['expose']['operator'])) {
$which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none';
}
if ($which == 'all' || $which == 'value') {
$form['value'] = array(
'#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'))),
'#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.'),
);
}
}
/**
* Filter down the query to include only the selected protocols.
*/
function op_protocol($field, $upper) {
$db_type = db_driver();
$protocols = $this->value;
$where_conditions = array();
foreach ($protocols as $protocol) {
// Simple case, the URL begins with the specified protocol.
$condition = $field .' LIKE \''. $protocol .'%\'';
// More complex case, no protocol specified but is automatically cleaned up
// by link_cleanup_url(). RegEx is required for this search operation.
if ($protocol == 'http') {
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.
// 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]))'.'\'';
}
else {
// mySQL requires backslashes to be double (triple?) escaped within character classes.
// 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]))'.'\'';
}
}
$where_conditions[] = $condition;
}
$this->query->add_where($this->options['group'], implode(' '. $this->operator .' ', $where_conditions));
}
}