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,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.');
}
}
}